Add undiff tests
This commit is contained in:
parent
ee6277c13f
commit
9c23229627
3 changed files with 46 additions and 10 deletions
14
reconcile-js/package-lock.json
generated
14
reconcile-js/package-lock.json
generated
|
|
@ -1231,13 +1231,13 @@
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "24.0.10",
|
"version": "24.10.1",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.0.10.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.1.tgz",
|
||||||
"integrity": "sha512-ENHwaH+JIRTDIEEbDK6QSQntAYGtbvdDXnMXnZaZ6k13Du1dPMmprkEHIL7ok2Wl2aZevetwTAb5S+7yIF+enA==",
|
"integrity": "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"undici-types": "~7.8.0"
|
"undici-types": "~7.16.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@types/stack-utils": {
|
"node_modules/@types/stack-utils": {
|
||||||
|
|
@ -5274,9 +5274,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/undici-types": {
|
"node_modules/undici-types": {
|
||||||
"version": "7.8.0",
|
"version": "7.16.0",
|
||||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.8.0.tgz",
|
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz",
|
||||||
"integrity": "sha512-9UJ2xGDvQ43tYyVMpuHlsgApydB8ZKfVYTsLDhXkFL/6gfkp+U8xTGdh8pMJv1SpZna0zxG1DwsKZsreLbXBxw==",
|
"integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -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', () => {
|
describe('reconcile', () => {
|
||||||
it('call reconcile without cursors', () => {
|
it('call reconcile without cursors', () => {
|
||||||
|
|
@ -44,3 +49,35 @@ describe('reconcile', () => {
|
||||||
expect(result.history.length).toBeGreaterThan(0);
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"declarationDir": "./dist/types",
|
"declarationDir": "./dist/types",
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"inlineSourceMap": true
|
"inlineSourceMap": true,
|
||||||
},
|
},
|
||||||
"exclude": ["./dist", "**/*.test.ts"]
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue