change(web): moves isSubstitutionAlignable unit tests

This commit is contained in:
Joshua Horton 2025-08-08 09:40:31 -05:00
parent 21a6c6fe8b
commit c7e84cdff7
2 changed files with 76 additions and 73 deletions

View file

@ -0,0 +1,76 @@
import { assert } from 'chai';
import { getEditPathLastMatch, isSubstitutionAlignable } from '#./correction/alignment-helpers.js';
describe('isSubstitutionAlignable', () => {
it(`returns true: 'ca' => 'can'`, () => {
assert.isTrue(isSubstitutionAlignable('can', 'ca'));
});
// Leading word in context window starts sliding out of said window.
it(`returns true: 'can' => 'an'`, () => {
assert.isTrue(isSubstitutionAlignable('an', 'can'));
});
// Same edits on both sides: not valid.
it(`returns false: 'apple' => 'grapples'`, () => {
assert.isFalse(isSubstitutionAlignable('grapples', 'apple'));
});
// Edits on one side: valid.
it(`returns true: 'apple' => 'grapple'`, () => {
assert.isTrue(isSubstitutionAlignable('grapple', 'apple'));
});
// Edits on one side: valid.
it(`returns true: 'apple' => 'grapple'`, () => {
assert.isTrue(isSubstitutionAlignable('apples', 'apple'));
});
// Same edits on both sides: not valid.
it(`returns false: 'grapples' => 'apple'`, () => {
assert.isFalse(isSubstitutionAlignable('apple', 'grapples'));
});
// Substitution: not valid when not permitted via parameter.
it(`returns false: 'apple' => 'banana'`, () => {
// edit path: 'insert' ('b' of banana), 'match' (on leading a), rest are 'substitute'.
assert.isFalse(isSubstitutionAlignable('banana', 'apple'));
});
// Substitution: not valid if too much is substituted, even if allowed via parameter.
it(`returns false: 'apple' => 'banana' (subs allowed)`, () => {
// edit path: 'insert' ('b' of banana), 'match' (on leading a), rest are 'substitute'.
// 1 match vs 4 substitute = no bueno. It'd require too niche of a keyboard rule.
assert.isFalse(isSubstitutionAlignable('banana', 'apple', true));
});
it(`returns true: 'a' => 'à' (subs allowed)`, () => {
assert.isTrue(isSubstitutionAlignable('à', 'a', true));
});
// Leading substitution: valid if enough of the remaining word matches.
// Could totally happen from a legit Keyman keyboard rule.
it(`returns true: 'can' => 'van' (subs allowed)`, () => {
assert.isTrue(isSubstitutionAlignable('van', 'can', true));
});
// Trailing substitution: invalid if not allowed.
it(`returns false: 'can' => 'cap' (subs not allowed)`, () => {
assert.isFalse(isSubstitutionAlignable('cap', 'can'));
});
// Trailing substitution: valid.
it(`returns false: 'can' => 'cap' (subs allowed)`, () => {
assert.isTrue(isSubstitutionAlignable('cap', 'can', true));
});
it(`returns true: 'clasts' => 'clasps' (subs allowed)`, () => {
assert.isTrue(isSubstitutionAlignable('clasps', 'clasts', true));
});
// random deletion at the start + later substitution = still permitted
it(`returns false: 'clasts' => 'lasps' (subs allowed)`, () => {
assert.isTrue(isSubstitutionAlignable('lasps', 'clasts', true));
});
});

View file

@ -20,79 +20,6 @@ function toToken(text) {
return token;
}
describe('isSubstitutionAlignable', () => {
it(`returns true: 'ca' => 'can'`, () => {
assert.isTrue(isSubstitutionAlignable('can', 'ca'));
});
// Leading word in context window starts sliding out of said window.
it(`returns true: 'can' => 'an'`, () => {
assert.isTrue(isSubstitutionAlignable('an', 'can'));
});
// Same edits on both sides: not valid.
it(`returns false: 'apple' => 'grapples'`, () => {
assert.isFalse(isSubstitutionAlignable('grapples', 'apple'));
});
// Edits on one side: valid.
it(`returns true: 'apple' => 'grapple'`, () => {
assert.isTrue(isSubstitutionAlignable('grapple', 'apple'));
});
// Edits on one side: valid.
it(`returns true: 'apple' => 'grapple'`, () => {
assert.isTrue(isSubstitutionAlignable('apples', 'apple'));
});
// Same edits on both sides: not valid.
it(`returns false: 'grapples' => 'apple'`, () => {
assert.isFalse(isSubstitutionAlignable('apple', 'grapples'));
});
// Substitution: not valid when not permitted via parameter.
it(`returns false: 'apple' => 'banana'`, () => {
// edit path: 'insert' ('b' of banana), 'match' (on leading a), rest are 'substitute'.
assert.isFalse(isSubstitutionAlignable('banana', 'apple'));
});
// Substitution: not valid if too much is substituted, even if allowed via parameter.
it(`returns false: 'apple' => 'banana' (subs allowed)`, () => {
// edit path: 'insert' ('b' of banana), 'match' (on leading a), rest are 'substitute'.
// 1 match vs 4 substitute = no bueno. It'd require too niche of a keyboard rule.
assert.isFalse(isSubstitutionAlignable('banana', 'apple', true));
});
it(`returns true: 'a' => 'à' (subs allowed)`, () => {
assert.isTrue(isSubstitutionAlignable('à', 'a', true));
});
// Leading substitution: valid if enough of the remaining word matches.
// Could totally happen from a legit Keyman keyboard rule.
it(`returns true: 'can' => 'van' (subs allowed)`, () => {
assert.isTrue(isSubstitutionAlignable('van', 'can', true));
});
// Trailing substitution: invalid if not allowed.
it(`returns false: 'can' => 'cap' (subs not allowed)`, () => {
assert.isFalse(isSubstitutionAlignable('cap', 'can'));
});
// Trailing substitution: valid.
it(`returns false: 'can' => 'cap' (subs allowed)`, () => {
assert.isTrue(isSubstitutionAlignable('cap', 'can', true));
});
it(`returns true: 'clasts' => 'clasps' (subs allowed)`, () => {
assert.isTrue(isSubstitutionAlignable('clasps', 'clasts', true));
});
// random deletion at the start + later substitution = still permitted
it(`returns false: 'clasts' => 'lasps' (subs allowed)`, () => {
assert.isTrue(isSubstitutionAlignable('lasps', 'clasts', true));
});
});
describe('ContextTokenization', function() {
describe("<constructor>", () => {
it("constructs from just a token array", () => {