Skip to content

Commit bfac546

Browse files
committed
chore: Add more multi-block tests for apply_diff tool
1 parent a3e6c91 commit bfac546

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/core/diff/strategies/__tests__/multi-search-replace.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,54 @@ function hello() {
7676
}
7777
})
7878

79+
it("should replace matching content in multiple blocks", async () => {
80+
const originalContent = 'function hello() {\n console.log("hello")\n}\n'
81+
const diffContent = `test.ts
82+
<<<<<<< SEARCH
83+
function hello() {
84+
=======
85+
function helloWorld() {
86+
>>>>>>> REPLACE
87+
<<<<<<< SEARCH
88+
console.log("hello")
89+
=======
90+
console.log("hello world")
91+
>>>>>>> REPLACE`
92+
93+
const result = await strategy.applyDiff(originalContent, diffContent)
94+
expect(result.success).toBe(true)
95+
if (result.success) {
96+
expect(result.content).toBe('function helloWorld() {\n console.log("hello world")\n}\n')
97+
}
98+
})
99+
100+
it("should replace matching content in multiple blocks with line numbers", async () => {
101+
const originalContent = 'function hello() {\n console.log("hello")\n}\n'
102+
const diffContent = `test.ts
103+
<<<<<<< SEARCH
104+
:start_line:1
105+
:end_line:1
106+
-------
107+
function hello() {
108+
=======
109+
function helloWorld() {
110+
>>>>>>> REPLACE
111+
<<<<<<< SEARCH
112+
:start_line:2
113+
:end_line:2
114+
-------
115+
console.log("hello")
116+
=======
117+
console.log("hello world")
118+
>>>>>>> REPLACE`
119+
120+
const result = await strategy.applyDiff(originalContent, diffContent)
121+
expect(result.success).toBe(true)
122+
if (result.success) {
123+
expect(result.content).toBe('function helloWorld() {\n console.log("hello world")\n}\n')
124+
}
125+
})
126+
79127
it("should match content with different surrounding whitespace", async () => {
80128
const originalContent = "\nfunction example() {\n return 42;\n}\n\n"
81129
const diffContent = `test.ts

0 commit comments

Comments
 (0)