@@ -26,6 +26,10 @@ test("allow empty text", (t) => {
26
26
t . throws ( ( ) => {
27
27
textInput . appendChar ( A , 100 ) ;
28
28
} ) ;
29
+
30
+ t . throws ( ( ) => {
31
+ textInput . appendChar ( Space , 100 ) ;
32
+ } ) ;
29
33
} ) ;
30
34
31
35
test ( "advance to completion" , ( t ) => {
@@ -177,35 +181,25 @@ test("accumulate and delete garbage", (t) => {
177
181
t . false ( textInput . completed ) ;
178
182
} ) ;
179
183
180
- test ( "emoji " , ( t ) => {
181
- const textInput = new TextInput ( "🍬🍭 " , {
182
- stopOnError : true ,
183
- forgiveErrors : true ,
184
+ test ( "limit garbage length " , ( t ) => {
185
+ const textInput = new TextInput ( "abc " , {
186
+ stopOnError : false ,
187
+ forgiveErrors : false ,
184
188
spaceSkipsWords : true ,
185
189
} ) ;
186
190
191
+ for ( let i = 1 ; i <= 100 ; i ++ ) {
192
+ t . is ( textInput . appendChar ( X , i * 100 ) , Feedback . Failed ) ;
193
+ }
194
+
187
195
t . is ( stepsString ( textInput . steps ) , "" ) ;
188
- t . is ( charsString ( textInput . chars ) , "[🍬]|🍭 " ) ;
189
- t . is ( textInput . length , 2 ) ;
196
+ t . is ( charsString ( textInput . chars ) , "*x|*x|*x|*x|*x|*x|*x|*x|*x|*x|[a]|b|c " ) ;
197
+ t . is ( textInput . length , 3 ) ;
190
198
t . is ( textInput . pos , 0 ) ;
191
199
t . false ( textInput . completed ) ;
192
-
193
- t . is ( textInput . appendChar ( 0x1f36c , 100 ) , Feedback . Succeeded ) ;
194
- t . is ( stepsString ( textInput . steps ) , "🍬,100" ) ;
195
- t . is ( charsString ( textInput . chars ) , "🍬|[🍭]" ) ;
196
- t . is ( textInput . length , 2 ) ;
197
- t . is ( textInput . pos , 1 ) ;
198
- t . false ( textInput . completed ) ;
199
-
200
- t . is ( textInput . appendChar ( 0x1f36d , 200 ) , Feedback . Succeeded ) ;
201
- t . is ( stepsString ( textInput . steps ) , "🍬,100|🍭,200" ) ;
202
- t . is ( charsString ( textInput . chars ) , "🍬|🍭" ) ;
203
- t . is ( textInput . length , 2 ) ;
204
- t . is ( textInput . pos , 2 ) ;
205
- t . true ( textInput . completed ) ;
206
200
} ) ;
207
201
208
- test ( "handle backspace at the start of text " , ( t ) => {
202
+ test ( "handle backspace at the start of a word " , ( t ) => {
209
203
const textInput = new TextInput ( "abc" , {
210
204
stopOnError : false ,
211
205
forgiveErrors : false ,
@@ -249,7 +243,7 @@ test("handle backspace at the start of text", (t) => {
249
243
t . false ( textInput . completed ) ;
250
244
} ) ;
251
245
252
- test ( "handle backspace in the middle of text " , ( t ) => {
246
+ test ( "handle backspace in the middle of a word " , ( t ) => {
253
247
const textInput = new TextInput ( "abc" , {
254
248
stopOnError : false ,
255
249
forgiveErrors : false ,
@@ -302,24 +296,6 @@ test("handle backspace in the middle of text", (t) => {
302
296
t . false ( textInput . completed ) ;
303
297
} ) ;
304
298
305
- test ( "limit garbage length" , ( t ) => {
306
- const textInput = new TextInput ( "abc" , {
307
- stopOnError : false ,
308
- forgiveErrors : false ,
309
- spaceSkipsWords : true ,
310
- } ) ;
311
-
312
- for ( let i = 1 ; i <= 100 ; i ++ ) {
313
- t . is ( textInput . appendChar ( X , i * 100 ) , Feedback . Failed ) ;
314
- }
315
-
316
- t . is ( stepsString ( textInput . steps ) , "" ) ;
317
- t . is ( charsString ( textInput . chars ) , "*x|*x|*x|*x|*x|*x|*x|*x|*x|*x|[a]|b|c" ) ;
318
- t . is ( textInput . length , 3 ) ;
319
- t . is ( textInput . pos , 0 ) ;
320
- t . false ( textInput . completed ) ;
321
- } ) ;
322
-
323
299
test ( "forgive an inserted character" , ( t ) => {
324
300
const textInput = new TextInput ( "abc" , {
325
301
stopOnError : true ,
@@ -465,16 +441,39 @@ test("recover from a forgiven error", (t) => {
465
441
t . true ( textInput . completed ) ;
466
442
} ) ;
467
443
468
- test ( "ignore whitespace keys at the start of text " , ( t ) => {
444
+ test ( "ignore the whitespace key " , ( t ) => {
469
445
const textInput = new TextInput ( "text" , {
470
446
stopOnError : true ,
471
- forgiveErrors : false ,
472
- spaceSkipsWords : true ,
447
+ forgiveErrors : true ,
448
+ spaceSkipsWords : false ,
473
449
} ) ;
474
450
475
451
t . is ( textInput . appendChar ( Space , 100 ) , Feedback . Succeeded ) ;
476
452
t . is ( stepsString ( textInput . steps ) , "" ) ;
477
453
t . is ( charsString ( textInput . chars ) , "[t]|e|x|t" ) ;
454
+ t . is ( textInput . length , 4 ) ;
455
+ t . is ( textInput . pos , 0 ) ;
456
+ t . false ( textInput . completed ) ;
457
+
458
+ t . is ( textInput . appendChar ( T , 200 ) , Feedback . Succeeded ) ;
459
+ t . is ( stepsString ( textInput . steps ) , "t,200" ) ;
460
+ t . is ( charsString ( textInput . chars ) , "t|[e]|x|t" ) ;
461
+ t . is ( textInput . length , 4 ) ;
462
+ t . is ( textInput . pos , 1 ) ;
463
+ t . false ( textInput . completed ) ;
464
+
465
+ t . is ( textInput . appendChar ( Space , 300 ) , Feedback . Succeeded ) ;
466
+ t . is ( stepsString ( textInput . steps ) , "t,200" ) ;
467
+ t . is ( charsString ( textInput . chars ) , "t|[e]|x|t" ) ;
468
+ t . is ( textInput . length , 4 ) ;
469
+ t . is ( textInput . pos , 1 ) ;
470
+ t . false ( textInput . completed ) ;
471
+
472
+ t . is ( textInput . appendChar ( E , 400 ) , Feedback . Succeeded ) ;
473
+ t . is ( stepsString ( textInput . steps ) , "t,200|e,400" ) ;
474
+ t . is ( charsString ( textInput . chars ) , "t|e|[x]|t" ) ;
475
+ t . is ( textInput . length , 4 ) ;
476
+ t . is ( textInput . pos , 2 ) ;
478
477
t . false ( textInput . completed ) ;
479
478
} ) ;
480
479
@@ -485,26 +484,33 @@ test("space in garbage", (t) => {
485
484
spaceSkipsWords : false ,
486
485
} ) ;
487
486
488
- t . is ( textInput . appendChar ( A , 100 ) , Feedback . Succeeded ) ;
487
+ t . is ( textInput . appendChar ( X , 100 ) , Feedback . Failed ) ;
489
488
t . is ( textInput . appendChar ( Space , 200 ) , Feedback . Failed ) ;
490
- t . is ( stepsString ( textInput . steps ) , "a,100 " ) ;
491
- t . is ( charsString ( textInput . chars ) , "a |* |[b] |c" ) ;
489
+ t . is ( stepsString ( textInput . steps ) , "" ) ;
490
+ t . is ( charsString ( textInput . chars ) , "*x |* |[a]|b |c" ) ;
492
491
t . is ( textInput . length , 3 ) ;
493
- t . is ( textInput . pos , 1 ) ;
492
+ t . is ( textInput . pos , 0 ) ;
494
493
t . false ( textInput . completed ) ;
495
494
496
495
t . is ( textInput . clearChar ( ) , Feedback . Succeeded ) ;
497
- t . is ( stepsString ( textInput . steps ) , "a,100 " ) ;
498
- t . is ( charsString ( textInput . chars ) , "a|[b] |c" ) ;
496
+ t . is ( stepsString ( textInput . steps ) , "" ) ;
497
+ t . is ( charsString ( textInput . chars ) , "*x|[a]|b |c" ) ;
499
498
t . is ( textInput . length , 3 ) ;
500
- t . is ( textInput . pos , 1 ) ;
499
+ t . is ( textInput . pos , 0 ) ;
501
500
t . false ( textInput . completed ) ;
502
501
503
- t . is ( textInput . appendChar ( B , 400 ) , Feedback . Recovered ) ;
504
- t . is ( stepsString ( textInput . steps ) , "a,100|!b,400 " ) ;
505
- t . is ( charsString ( textInput . chars ) , "a|!b|[c] " ) ;
502
+ t . is ( textInput . clearChar ( ) , Feedback . Succeeded ) ;
503
+ t . is ( stepsString ( textInput . steps ) , "" ) ;
504
+ t . is ( charsString ( textInput . chars ) , "[a]|b|c " ) ;
506
505
t . is ( textInput . length , 3 ) ;
507
- t . is ( textInput . pos , 2 ) ;
506
+ t . is ( textInput . pos , 0 ) ;
507
+ t . false ( textInput . completed ) ;
508
+
509
+ t . is ( textInput . appendChar ( A , 500 ) , Feedback . Recovered ) ;
510
+ t . is ( stepsString ( textInput . steps ) , "!a,500" ) ;
511
+ t . is ( charsString ( textInput . chars ) , "!a|[b]|c" ) ;
512
+ t . is ( textInput . length , 3 ) ;
513
+ t . is ( textInput . pos , 1 ) ;
508
514
t . false ( textInput . completed ) ;
509
515
} ) ;
510
516
@@ -534,7 +540,7 @@ test("space skips words at the beginning of a word, ignore space", (t) => {
534
540
t . is ( charsString ( textInput . chars ) , "x| |[a]|b|c" ) ;
535
541
t . false ( textInput . completed ) ;
536
542
537
- t . is ( textInput . appendChar ( Space , 300 ) , Feedback . Failed ) ;
543
+ t . is ( textInput . appendChar ( Space , 300 ) , Feedback . Succeeded ) ;
538
544
t . is ( stepsString ( textInput . steps ) , "x,100| ,200" ) ;
539
545
t . is ( charsString ( textInput . chars ) , "x| |[a]|b|c" ) ;
540
546
t . false ( textInput . completed ) ;
@@ -648,7 +654,7 @@ test("normalize characters", (t) => {
648
654
t . true ( textInput . completed ) ;
649
655
} ) ;
650
656
651
- test ( "handle whitespace" , ( t ) => {
657
+ test ( "whitespace" , ( t ) => {
652
658
const textInput = new TextInput ( "a " , {
653
659
stopOnError : true ,
654
660
forgiveErrors : false ,
@@ -663,6 +669,34 @@ test("handle whitespace", (t) => {
663
669
t . true ( textInput . completed ) ;
664
670
} ) ;
665
671
672
+ test ( "emoji" , ( t ) => {
673
+ const textInput = new TextInput ( "🍬🍭" , {
674
+ stopOnError : true ,
675
+ forgiveErrors : true ,
676
+ spaceSkipsWords : true ,
677
+ } ) ;
678
+
679
+ t . is ( stepsString ( textInput . steps ) , "" ) ;
680
+ t . is ( charsString ( textInput . chars ) , "[🍬]|🍭" ) ;
681
+ t . is ( textInput . length , 2 ) ;
682
+ t . is ( textInput . pos , 0 ) ;
683
+ t . false ( textInput . completed ) ;
684
+
685
+ t . is ( textInput . appendChar ( 0x1f36c , 100 ) , Feedback . Succeeded ) ;
686
+ t . is ( stepsString ( textInput . steps ) , "🍬,100" ) ;
687
+ t . is ( charsString ( textInput . chars ) , "🍬|[🍭]" ) ;
688
+ t . is ( textInput . length , 2 ) ;
689
+ t . is ( textInput . pos , 1 ) ;
690
+ t . false ( textInput . completed ) ;
691
+
692
+ t . is ( textInput . appendChar ( 0x1f36d , 200 ) , Feedback . Succeeded ) ;
693
+ t . is ( stepsString ( textInput . steps ) , "🍬,100|🍭,200" ) ;
694
+ t . is ( charsString ( textInput . chars ) , "🍬|🍭" ) ;
695
+ t . is ( textInput . length , 2 ) ;
696
+ t . is ( textInput . pos , 2 ) ;
697
+ t . true ( textInput . completed ) ;
698
+ } ) ;
699
+
666
700
function stepsString ( steps : readonly Step [ ] ) : string {
667
701
return steps
668
702
. map ( ( { codePoint, timeStamp, typo } ) => {
0 commit comments