Skip to content

Commit 4e14825

Browse files
committed
Enhance search and replace content processor with robust matching strategies and fallback handling
- create a minimal test that targets the change [Changes] - add missing test cases [Pasted text] - to `apps/editor/src/utils/changes-integration/search-replace-processor/apply-search-replace-to-content/apply-search-replace-to-content.spec.ts` add missing test cases - what tests are missing? - find dead code and remove it, together with comments └── apps └── editor └── src └── utils └── changes-integration └── search-replace-processor ├── apply-search-replace-to-content │ ├── apply-search-replace-to-content.spec.ts │ ├── apply-search-replace-to-content.ts │ ├── index.ts │ └── test-cases │ ├── add-blank-line │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── adjacent-blocks-and-duplicate-snippets │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── basic-conflict │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── delete-first-line │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── deletion │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── expand-line-before-blank-line │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── extra-blank-lines-in-search │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── insert-after-context │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── insert-before-context │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── multiple-conflicts │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── multiple-seven-char-equals-underlines │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── noop-blocks │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── out-of-order-blocks │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── out-of-order-shrinking-block │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── out-of-order-with-duplicate-snippet │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── prepend-empty-search │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── preserve-boundary-blank-lines │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── remove-blank-line │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── reorder-without-context │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── rst-syntax │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── seven-char-equals-underline │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── similar-code-multiple-blocks │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── strict-match-precedence │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── trailing-blank-lines-diff │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ ├── trailing-whitespace │ │ ├── expected.txt │ │ ├── markers.txt │ │ └── original.txt │ └── whitespace-issues │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── index.ts ├── parse-search-replace-segments.ts └── types.ts
1 parent b8d235c commit 4e14825

44 files changed

Lines changed: 824 additions & 197 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/editor/src/utils/changes-integration/search-replace-processor/apply-search-replace-to-content/apply-search-replace-to-content.spec.ts‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,61 @@ describe('search-replace-parser', () => {
8686
it('does not prepend a newline when the first kept line moves without context', () => {
8787
run_test_case('reorder-without-context')
8888
})
89+
90+
it('applies search replace blocks that appear out of file order', () => {
91+
run_test_case('out-of-order-blocks')
92+
})
93+
94+
it('skips no-op blocks without failing on unmatched ones', () => {
95+
run_test_case('noop-blocks')
96+
})
97+
98+
it('prepends content at the start of the file when the search block is empty', () => {
99+
run_test_case('prepend-empty-search')
100+
})
101+
102+
it('adds a blank line between existing lines', () => {
103+
run_test_case('add-blank-line')
104+
})
105+
106+
it('removes a blank line between existing lines', () => {
107+
run_test_case('remove-blank-line')
108+
})
109+
110+
it('preserves blank lines at the boundaries of a search replace block', () => {
111+
run_test_case('preserve-boundary-blank-lines')
112+
})
113+
114+
it('expands a line into multiple lines before a blank line', () => {
115+
run_test_case('expand-line-before-blank-line')
116+
})
117+
118+
it('handles seven-character equals underlines inside search and replace blocks', () => {
119+
run_test_case('seven-char-equals-underline')
120+
})
121+
122+
it('matches the intended occurrence when out-of-order blocks follow a duplicate snippet', () => {
123+
run_test_case('out-of-order-with-duplicate-snippet')
124+
})
125+
126+
it('adds and removes trailing blank lines at the end of a search replace block', () => {
127+
run_test_case('trailing-blank-lines-diff')
128+
})
129+
130+
it('handles multiple seven-character equals underlines inside a single search block', () => {
131+
run_test_case('multiple-seven-char-equals-underlines')
132+
})
133+
134+
it('prefers an exact match over an earlier loose-whitespace match', () => {
135+
run_test_case('strict-match-precedence')
136+
})
137+
138+
it('adjusts the cursor properly when an out-of-order block shrinks earlier content', () => {
139+
run_test_case('out-of-order-shrinking-block')
140+
})
141+
142+
it('applies back-to-back blocks targeting identical duplicate snippets in order', () => {
143+
run_test_case('adjacent-blocks-and-duplicate-snippets')
144+
})
89145
})
90146
})

0 commit comments

Comments
 (0)