chore: Add more multi-block tests for apply_diff tool (#2261)

This commit is contained in:
Povilas Kanapickas 2025-04-03 17:55:05 +03:00 committed by GitHub
parent a3e6c912b0
commit 552ed0e986
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -76,6 +76,54 @@ function hello() {
}
})
it("should replace matching content in multiple blocks", async () => {
const originalContent = 'function hello() {\n console.log("hello")\n}\n'
const diffContent = `test.ts
<<<<<<< SEARCH
function hello() {
=======
function helloWorld() {
>>>>>>> REPLACE
<<<<<<< SEARCH
console.log("hello")
=======
console.log("hello world")
>>>>>>> REPLACE`
const result = await strategy.applyDiff(originalContent, diffContent)
expect(result.success).toBe(true)
if (result.success) {
expect(result.content).toBe('function helloWorld() {\n console.log("hello world")\n}\n')
}
})
it("should replace matching content in multiple blocks with line numbers", async () => {
const originalContent = 'function hello() {\n console.log("hello")\n}\n'
const diffContent = `test.ts
<<<<<<< SEARCH
:start_line:1
:end_line:1
-------
function hello() {
=======
function helloWorld() {
>>>>>>> REPLACE
<<<<<<< SEARCH
:start_line:2
:end_line:2
-------
console.log("hello")
=======
console.log("hello world")
>>>>>>> REPLACE`
const result = await strategy.applyDiff(originalContent, diffContent)
expect(result.success).toBe(true)
if (result.success) {
expect(result.content).toBe('function helloWorld() {\n console.log("hello world")\n}\n')
}
})
it("should match content with different surrounding whitespace", async () => {
const originalContent = "\nfunction example() {\n return 42;\n}\n\n"
const diffContent = `test.ts