mirror of
https://github.com/keymanapp/keyman.git
synced 2026-10-17 03:17:33 +00:00
Merge branch 'fix/web/sliding-tokenization-alignment' into refactor/web/independent-compute-alignment
This commit is contained in:
commit
fae2dec1fe
2 changed files with 11 additions and 7 deletions
|
|
@ -66,7 +66,7 @@ export type ContextStateAlignment = {
|
|||
* - ['to', ' ', 'apple', ' ', ''] => ['to', ' ', 'apply', ' ', '']
|
||||
* - ['to', ' ', 'apple', ' ', ''] => ['to', ' ', 'apply', ' ', 'n']
|
||||
*
|
||||
* Edit path for these example case:
|
||||
* Edit path for these example cases:
|
||||
* - ['match', 'match', 'substitute', 'match', 'match']
|
||||
* - ['match', 'match', 'substitute', 'match', 'substitute']
|
||||
*
|
||||
|
|
|
|||
|
|
@ -14,28 +14,32 @@ import { computeAlignment, EditOperation, getEditPathLastMatch, isSubstitutionAl
|
|||
describe('getEditPathLastMatch', () => {
|
||||
it('returns the last match when no substitutions exist', () => {
|
||||
const path: EditOperation[] = ['delete', 'delete', 'match', 'match', 'match', 'match', 'insert'];
|
||||
assert.equal(getEditPathLastMatch(path), path.lastIndexOf('match'));
|
||||
assert.equal(path.lastIndexOf('match'), 5);
|
||||
assert.equal(getEditPathLastMatch(path), 5);
|
||||
});
|
||||
|
||||
it('returns the last match when no substitutions exist left of a "match"', () => {
|
||||
const path: EditOperation[] = ['delete', 'delete', 'match', 'match', 'match', 'match', 'substitute', 'insert'];
|
||||
assert.equal(getEditPathLastMatch(path), path.lastIndexOf('match'));
|
||||
assert.equal(path.lastIndexOf('match'), 5);
|
||||
assert.equal(getEditPathLastMatch(path), 5);
|
||||
});
|
||||
|
||||
// is intended to handle application of suggestions.
|
||||
it('returns the last match before a substitute occurring after the first match', () => {
|
||||
// limitation: if there is _anything_ after that last match, the first assertion will fail.
|
||||
// 0 1 2 3 4 5 6
|
||||
const path: EditOperation[] = ['delete', 'delete', 'match', 'match', 'substitute', 'match', 'match'];
|
||||
assert.notEqual(getEditPathLastMatch(path), path.lastIndexOf('match'));
|
||||
assert.equal(getEditPathLastMatch(path), path.lastIndexOf('match', path.lastIndexOf('substitute')));
|
||||
assert.notEqual(getEditPathLastMatch(path), 6);
|
||||
assert.equal(getEditPathLastMatch(path), 3);
|
||||
});
|
||||
|
||||
// is intended to handle complex transforms that include a whitespace and affect prior tokens.
|
||||
it('returns the last match before a substitute occurring after the first match', () => {
|
||||
// limitation: if there is _anything_ after that last match, the first assertion will fail.
|
||||
// 0 1 2 3 4 5 6
|
||||
const path: EditOperation[] = ['delete', 'delete', 'match', 'match', 'substitute', 'match', 'substitute'];
|
||||
assert.notEqual(getEditPathLastMatch(path), path.lastIndexOf('match'));
|
||||
assert.equal(getEditPathLastMatch(path), path.lastIndexOf('match', path.indexOf('substitute')));
|
||||
assert.notEqual(getEditPathLastMatch(path), 5);
|
||||
assert.equal(getEditPathLastMatch(path), 3);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue