mirror of
https://github.com/keymanapp/keyman.git
synced 2026-10-17 03:17:33 +00:00
change(web): clarify path-last-match assertions
This commit is contained in:
parent
9362f2e0a0
commit
27f7a4727b
1 changed files with 10 additions and 6 deletions
|
|
@ -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