From 8159c51b03235928b76a2a96550eae3f974a49a6 Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Sun, 15 Dec 2024 15:41:10 -0500 Subject: [PATCH] Update omission format and keywords --- .../editor/__tests__/detect-omission.test.ts | 66 +++++++++++++++++++ src/integrations/editor/detect-omission.ts | 3 +- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 src/integrations/editor/__tests__/detect-omission.test.ts diff --git a/src/integrations/editor/__tests__/detect-omission.test.ts b/src/integrations/editor/__tests__/detect-omission.test.ts new file mode 100644 index 0000000..4740b1f --- /dev/null +++ b/src/integrations/editor/__tests__/detect-omission.test.ts @@ -0,0 +1,66 @@ +import { detectCodeOmission } from '../detect-omission' + +describe('detectCodeOmission', () => { + const originalContent = `function example() { + // Some code + const x = 1; + const y = 2; + return x + y; +}` + + it('should detect square bracket line range omission', () => { + const newContent = `[Previous content from line 1-305 remains exactly the same] +const z = 3;` + expect(detectCodeOmission(originalContent, newContent)).toBe(true) + }) + + it('should detect single-line comment omission', () => { + const newContent = `// Lines 1-50 remain unchanged +const z = 3;` + expect(detectCodeOmission(originalContent, newContent)).toBe(true) + }) + + it('should detect multi-line comment omission', () => { + const newContent = `/* Previous content remains the same */ +const z = 3;` + expect(detectCodeOmission(originalContent, newContent)).toBe(true) + }) + + it('should detect HTML-style comment omission', () => { + const newContent = ` +const z = 3;` + expect(detectCodeOmission(originalContent, newContent)).toBe(true) + }) + + it('should detect JSX-style comment omission', () => { + const newContent = `{/* Rest of the code remains the same */} +const z = 3;` + expect(detectCodeOmission(originalContent, newContent)).toBe(true) + }) + + it('should detect Python-style comment omission', () => { + const newContent = `# Previous content remains unchanged +const z = 3;` + expect(detectCodeOmission(originalContent, newContent)).toBe(true) + }) + + it('should not detect regular comments without omission keywords', () => { + const newContent = `// Adding new functionality +const z = 3;` + expect(detectCodeOmission(originalContent, newContent)).toBe(false) + }) + + it('should not detect when comment is part of original content', () => { + const originalWithComment = `// Content remains unchanged +${originalContent}` + const newContent = `// Content remains unchanged +const z = 3;` + expect(detectCodeOmission(originalWithComment, newContent)).toBe(false) + }) + + it('should not detect code that happens to contain omission keywords', () => { + const newContent = `const remains = 'some value'; +const unchanged = true;` + expect(detectCodeOmission(originalContent, newContent)).toBe(false) + }) +}) \ No newline at end of file diff --git a/src/integrations/editor/detect-omission.ts b/src/integrations/editor/detect-omission.ts index 565ebd3..5cb0f8e 100644 --- a/src/integrations/editor/detect-omission.ts +++ b/src/integrations/editor/detect-omission.ts @@ -7,7 +7,7 @@ export function detectCodeOmission(originalFileContent: string, newFileContent: string): boolean { const originalLines = originalFileContent.split("\n") const newLines = newFileContent.split("\n") - const omissionKeywords = ["remain", "remains", "unchanged", "rest", "previous", "existing", "..."] + const omissionKeywords = ["remain", "remains", "unchanged", "rest", "previous", "existing", "content", "same", "..."] const commentPatterns = [ /^\s*\/\//, // Single-line comment for most languages @@ -15,6 +15,7 @@ export function detectCodeOmission(originalFileContent: string, newFileContent: /^\s*\/\*/, // Multi-line comment opening /^\s*{\s*\/\*/, // JSX comment opening /^\s*