From 9c232296272df769138407e11d414b08df561e00 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 16 Nov 2025 15:36:50 +0000 Subject: [PATCH] Add undiff tests --- reconcile-js/package-lock.json | 14 ++++++------ reconcile-js/src/index.test.ts | 39 +++++++++++++++++++++++++++++++++- reconcile-js/tsconfig.json | 3 +-- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/reconcile-js/package-lock.json b/reconcile-js/package-lock.json index 573aba2..38dcb9c 100644 --- a/reconcile-js/package-lock.json +++ b/reconcile-js/package-lock.json @@ -1231,13 +1231,13 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "24.0.10", - "resolved": "https://registry.npmjs.org/@types/node/-/node-24.0.10.tgz", - "integrity": "sha512-ENHwaH+JIRTDIEEbDK6QSQntAYGtbvdDXnMXnZaZ6k13Du1dPMmprkEHIL7ok2Wl2aZevetwTAb5S+7yIF+enA==", + "version": "24.10.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.1.tgz", + "integrity": "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ==", "dev": true, "license": "MIT", "dependencies": { - "undici-types": "~7.8.0" + "undici-types": "~7.16.0" } }, "node_modules/@types/stack-utils": { @@ -5274,9 +5274,9 @@ } }, "node_modules/undici-types": { - "version": "7.8.0", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.8.0.tgz", - "integrity": "sha512-9UJ2xGDvQ43tYyVMpuHlsgApydB8ZKfVYTsLDhXkFL/6gfkp+U8xTGdh8pMJv1SpZna0zxG1DwsKZsreLbXBxw==", + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz", + "integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==", "dev": true, "license": "MIT" }, diff --git a/reconcile-js/src/index.test.ts b/reconcile-js/src/index.test.ts index fa1e41d..b810fea 100644 --- a/reconcile-js/src/index.test.ts +++ b/reconcile-js/src/index.test.ts @@ -1,4 +1,9 @@ -import { reconcile, reconcileWithHistory } from './index'; +import { reconcile, reconcileWithHistory, diff, undiff } from './index'; +import * as fs from 'fs'; +import * as path from 'path'; +import { fileURLToPath } from 'url'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); describe('reconcile', () => { it('call reconcile without cursors', () => { @@ -44,3 +49,35 @@ describe('reconcile', () => { expect(result.history.length).toBeGreaterThan(0); }); }); + +describe('test_merge_files_without_panic', () => { + const resourcesPath = path.join(__dirname, '../../tests/resources'); + + const readFileSlice = (fileName: string, start: number, end: number): string => { + const filePath = path.join(resourcesPath, fileName); + const content = fs.readFileSync(filePath, 'utf-8'); + const chars = Array.from(content); // Handle unicode properly + return chars.slice(start, Math.min(end, chars.length)).join(''); + }; + + const files = ['pride_and_prejudice.txt', 'room_with_a_view.txt', 'blns.txt']; + + const ranges = [{ start: 0, end: 50000 }]; + + files.forEach((file1) => { + files.forEach((file2) => { + ranges.forEach((range1) => { + ranges.forEach((range2) => { + it(`should diff & undiff ${file1}[${range1.start}..${range1.end}], ${file2}[${range2.start}..${range2.end}] without panic`, () => { + const content1 = readFileSlice(file1, range1.start, range1.end); + const content2 = readFileSlice(file2, range2.start, range2.end); + + const changes = diff(content1, content2); + const actual = undiff(content1, changes); + expect(actual).toEqual(content2); + }); + }); + }); + }); + }); +}); diff --git a/reconcile-js/tsconfig.json b/reconcile-js/tsconfig.json index c462052..d275639 100644 --- a/reconcile-js/tsconfig.json +++ b/reconcile-js/tsconfig.json @@ -8,7 +8,6 @@ "declaration": true, "declarationDir": "./dist/types", "skipLibCheck": true, - "inlineSourceMap": true + "inlineSourceMap": true, }, - "exclude": ["./dist", "**/*.test.ts"] }