Skip to content

Commit 8cd6c20

Browse files
committed
test: Refactor assertions in read_file tests to use expected XML variable
This commit updates the `read_file` tool tests to utilize a predefined variable for the expected XML output, improving readability and maintainability of the test code. The changes ensure consistency in the expected results across multiple test cases.
1 parent 30aca0f commit 8cd6c20

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/core/__tests__/read-file-maxReadFileLine.test.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ describe("read_file tool with maxReadFileLine setting", () => {
4848
const fileContent = "Line 1\nLine 2\nLine 3\nLine 4\nLine 5"
4949
const numberedFileContent = "1 | Line 1\n2 | Line 2\n3 | Line 3\n4 | Line 4\n5 | Line 5"
5050
const sourceCodeDef = "\n\n# file.txt\n1--5 | Content"
51+
const expectedFullFileXml = `<file>\n <path>${testFilePath}</path>\n <content>\n${numberedFileContent}\n </content>\n</file>`
5152

5253
// Mocked functions with correct types
5354
const mockedCountFileLines = countFileLines as jest.MockedFunction<typeof countFileLines>
@@ -147,9 +148,7 @@ describe("read_file tool with maxReadFileLine setting", () => {
147148
expect(mockedExtractTextFromFile).toHaveBeenCalledWith(absoluteFilePath)
148149
expect(mockedReadLines).not.toHaveBeenCalled()
149150
expect(mockedParseSourceCodeDefinitionsForFile).not.toHaveBeenCalled()
150-
expect(result).toBe(
151-
`<file>\n <path>${testFilePath}</path>\n <content>\n${numberedFileContent}\n </content>\n</file>`,
152-
)
151+
expect(result).toBe(expectedFullFileXml)
153152
})
154153
})
155154

@@ -209,9 +208,7 @@ describe("read_file tool with maxReadFileLine setting", () => {
209208

210209
// Verify
211210
expect(mockedExtractTextFromFile).toHaveBeenCalledWith(absoluteFilePath)
212-
expect(result).toBe(
213-
`<file>\n <path>${testFilePath}</path>\n <content>\n${numberedFileContent}\n </content>\n</file>`,
214-
)
211+
expect(result).toBe(expectedFullFileXml)
215212
})
216213

217214
it("should read with extractTextFromFile when file has few lines", async () => {
@@ -225,9 +222,7 @@ describe("read_file tool with maxReadFileLine setting", () => {
225222
// Verify
226223
expect(mockedExtractTextFromFile).toHaveBeenCalledWith(absoluteFilePath)
227224
expect(mockedReadLines).not.toHaveBeenCalled()
228-
expect(result).toBe(
229-
`<file>\n <path>${testFilePath}</path>\n <content>\n${numberedFileContent}\n </content>\n</file>`,
230-
)
225+
expect(result).toBe(expectedFullFileXml)
231226
})
232227
})
233228

@@ -243,9 +238,7 @@ describe("read_file tool with maxReadFileLine setting", () => {
243238
// Verify
244239
expect(mockedExtractTextFromFile).toHaveBeenCalledWith(absoluteFilePath)
245240
expect(mockedReadLines).not.toHaveBeenCalled()
246-
expect(result).toBe(
247-
`<file>\n <path>${testFilePath}</path>\n <content>\n${numberedFileContent}\n </content>\n</file>`,
248-
)
241+
expect(result).toBe(expectedFullFileXml)
249242
})
250243
})
251244

0 commit comments

Comments
 (0)