88 * validating potential substitution edit operations.
99 */
1010
11- import { assert } from 'chai' ;
12- import { isSubstitutionAlignable } from '@keymanapp/lm-worker/test-index' ;
13-
14- describe ( 'isSubstitutionAlignable' , ( ) => {
15- it ( `returns true: 'ca' => 'can'` , ( ) => {
16- assert . isTrue ( isSubstitutionAlignable ( 'can' , 'ca' ) ) ;
17- } ) ;
18-
19- // Leading word in context window starts sliding out of said window.
20- it ( `returns true: 'can' => 'an'` , ( ) => {
21- assert . isTrue ( isSubstitutionAlignable ( 'an' , 'can' ) ) ;
22- } ) ;
23-
24- // Same edits on both sides: not valid.
25- it ( `returns false: 'apple' => 'grapples'` , ( ) => {
26- assert . isFalse ( isSubstitutionAlignable ( 'grapples' , 'apple' ) ) ;
27- } ) ;
28-
29- // Edits on one side: valid.
30- it ( `returns true: 'apple' => 'grapple'` , ( ) => {
31- assert . isTrue ( isSubstitutionAlignable ( 'grapple' , 'apple' ) ) ;
32- } ) ;
33-
34- // Edits on one side: valid.
35- it ( `returns true: 'apple' => 'grapple'` , ( ) => {
36- assert . isTrue ( isSubstitutionAlignable ( 'apples' , 'apple' ) ) ;
37- } ) ;
38-
39- // Same edits on both sides: not valid.
40- it ( `returns false: 'grapples' => 'apple'` , ( ) => {
41- assert . isFalse ( isSubstitutionAlignable ( 'apple' , 'grapples' ) ) ;
42- } ) ;
43-
44- // Substitution: not valid when not permitted via parameter.
45- it ( `returns false: 'apple' => 'banana'` , ( ) => {
46- // edit path: 'insert' ('b' of banana), 'match' (on leading a), rest are 'substitute'.
47- assert . isFalse ( isSubstitutionAlignable ( 'banana' , 'apple' ) ) ;
48- } ) ;
49-
50- // Substitution: not valid if too much is substituted, even if allowed via parameter.
51- it ( `returns false: 'apple' => 'banana' (subs allowed)` , ( ) => {
52- // edit path: 'insert' ('b' of banana), 'match' (on leading a), rest are 'substitute'.
53- // 1 match vs 4 substitute = no bueno. It'd require too niche of a keyboard rule.
54- assert . isFalse ( isSubstitutionAlignable ( 'banana' , 'apple' , true ) ) ;
55- } ) ;
56-
57- it ( `returns true: 'a' => 'à' (subs allowed)` , ( ) => {
58- assert . isTrue ( isSubstitutionAlignable ( 'à' , 'a' , true ) ) ;
59- } ) ;
60-
61- // Leading substitution: valid if enough of the remaining word matches.
62- // Could totally happen from a legit Keyman keyboard rule.
63- it ( `returns true: 'can' => 'van' (subs allowed)` , ( ) => {
64- assert . isTrue ( isSubstitutionAlignable ( 'van' , 'can' , true ) ) ;
65- } ) ;
66-
67- // Trailing substitution: invalid if not allowed.
68- it ( `returns false: 'can' => 'cap' (subs not allowed)` , ( ) => {
69- assert . isFalse ( isSubstitutionAlignable ( 'cap' , 'can' ) ) ;
70- } ) ;
71-
72- // Trailing substitution: valid.
73- it ( `returns false: 'can' => 'cap' (subs allowed)` , ( ) => {
74- assert . isTrue ( isSubstitutionAlignable ( 'cap' , 'can' , true ) ) ;
75- } ) ;
76-
77- it ( `returns true: 'clasts' => 'clasps' (subs allowed)` , ( ) => {
78- assert . isTrue ( isSubstitutionAlignable ( 'clasps' , 'clasts' , true ) ) ;
79- } ) ;
80-
81- // random deletion at the start + later substitution = still permitted
82- it ( `returns false: 'clasts' => 'lasps' (subs allowed)` , ( ) => {
83- assert . isTrue ( isSubstitutionAlignable ( 'lasps' , 'clasts' , true ) ) ;
84- } ) ;
85-
86- // deletion, then sub at the start, duplicate letters with one dropped
87- it ( `returns true: 'applesauce' => 'plesauce' (subs not allowed)` , ( ) => {
88- // The double-p adds a fun complication once the first gets dropped.
89- assert . isTrue ( isSubstitutionAlignable ( 'applesauce' , 'plesauce' ) ) ;
90- } ) ;
91- } ) ;
11+ // No longer needed.
0 commit comments