File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
src/core/diff/strategies/__tests__ Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments