Skip to content

Commit 1caa108

Browse files
committed
Fix behavior with string unicodes diffs
1 parent 0283328 commit 1caa108

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

β€Žsrc/diff/lcs.tsβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
function lcs<T>(a: T[], b: T[], compareFunc: (a: T, b: T) => boolean): number {
1+
function lcs<T>(_a: T[], _b: T[], compareFunc: (a: T, b: T) => boolean): number {
2+
const a = [..._a], // normalize string unicodes
3+
b = [..._b];
24
const M = a.length,
35
N = b.length;
46
const MAX = M + N;

β€Žsrc/test/patch.spec.tsβ€Ž

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ describe('Get Patch', () => {
1919
type: 'add',
2020
oldPos,
2121
newPos,
22-
items: str.split(''),
22+
items: [...str],
2323
};
2424
}
2525
function remove(oldPos: number, newPos: number, str: string): es.PatchItem<string> {
2626
return {
2727
type: 'remove',
2828
oldPos,
2929
newPos,
30-
items: str.split(''),
30+
items: [...str],
3131
};
3232
}
3333
function es_str(a: string, b: string, script: es.Patch<string>, msg?: string) {
34-
assert.deepStrictEqual(es.getPatch(a.split(''), b.split('')), script, msg);
34+
assert.deepStrictEqual(es.getPatch([...a], [...b]), script, msg);
3535
}
3636

3737
es_str('', '', [], 'empty');
@@ -103,5 +103,7 @@ describe('Get Patch', () => {
103103
[add(12, 12, '12345678901234567890')],
104104
'remove 12345678901234567890',
105105
);
106+
107+
es_str('πŸ’’πŸ’©πŸ’§', 'πŸ’’πŸ’«πŸ’§', [remove(1, 1, 'πŸ’©'), add(2, 1, 'πŸ’«')], 'works with unicodes')
106108
});
107109
});

β€Žtsconfig.jsonβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"declaration": true,
99
"outDir": "./dist",
1010
"strict": true,
11-
"esModuleInterop": true
11+
"esModuleInterop": true,
12+
"downlevelIteration": true
1213
}
1314
}

0 commit comments

Comments
Β (0)