Skip to content

Commit 8159c51

Browse files
committed
Update omission format and keywords
1 parent 468d317 commit 8159c51

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { detectCodeOmission } from '../detect-omission'
2+
3+
describe('detectCodeOmission', () => {
4+
const originalContent = `function example() {
5+
// Some code
6+
const x = 1;
7+
const y = 2;
8+
return x + y;
9+
}`
10+
11+
it('should detect square bracket line range omission', () => {
12+
const newContent = `[Previous content from line 1-305 remains exactly the same]
13+
const z = 3;`
14+
expect(detectCodeOmission(originalContent, newContent)).toBe(true)
15+
})
16+
17+
it('should detect single-line comment omission', () => {
18+
const newContent = `// Lines 1-50 remain unchanged
19+
const z = 3;`
20+
expect(detectCodeOmission(originalContent, newContent)).toBe(true)
21+
})
22+
23+
it('should detect multi-line comment omission', () => {
24+
const newContent = `/* Previous content remains the same */
25+
const z = 3;`
26+
expect(detectCodeOmission(originalContent, newContent)).toBe(true)
27+
})
28+
29+
it('should detect HTML-style comment omission', () => {
30+
const newContent = `<!-- Existing content unchanged -->
31+
const z = 3;`
32+
expect(detectCodeOmission(originalContent, newContent)).toBe(true)
33+
})
34+
35+
it('should detect JSX-style comment omission', () => {
36+
const newContent = `{/* Rest of the code remains the same */}
37+
const z = 3;`
38+
expect(detectCodeOmission(originalContent, newContent)).toBe(true)
39+
})
40+
41+
it('should detect Python-style comment omission', () => {
42+
const newContent = `# Previous content remains unchanged
43+
const z = 3;`
44+
expect(detectCodeOmission(originalContent, newContent)).toBe(true)
45+
})
46+
47+
it('should not detect regular comments without omission keywords', () => {
48+
const newContent = `// Adding new functionality
49+
const z = 3;`
50+
expect(detectCodeOmission(originalContent, newContent)).toBe(false)
51+
})
52+
53+
it('should not detect when comment is part of original content', () => {
54+
const originalWithComment = `// Content remains unchanged
55+
${originalContent}`
56+
const newContent = `// Content remains unchanged
57+
const z = 3;`
58+
expect(detectCodeOmission(originalWithComment, newContent)).toBe(false)
59+
})
60+
61+
it('should not detect code that happens to contain omission keywords', () => {
62+
const newContent = `const remains = 'some value';
63+
const unchanged = true;`
64+
expect(detectCodeOmission(originalContent, newContent)).toBe(false)
65+
})
66+
})

src/integrations/editor/detect-omission.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
export function detectCodeOmission(originalFileContent: string, newFileContent: string): boolean {
88
const originalLines = originalFileContent.split("\n")
99
const newLines = newFileContent.split("\n")
10-
const omissionKeywords = ["remain", "remains", "unchanged", "rest", "previous", "existing", "..."]
10+
const omissionKeywords = ["remain", "remains", "unchanged", "rest", "previous", "existing", "content", "same", "..."]
1111

1212
const commentPatterns = [
1313
/^\s*\/\//, // Single-line comment for most languages
1414
/^\s*#/, // Single-line comment for Python, Ruby, etc.
1515
/^\s*\/\*/, // Multi-line comment opening
1616
/^\s*{\s*\/\*/, // JSX comment opening
1717
/^\s*<!--/, // HTML comment opening
18+
/^\s*\[/, // Square bracket notation
1819
]
1920

2021
for (const line of newLines) {

0 commit comments

Comments
 (0)