@@ -384,7 +384,7 @@ void main() {
384
384
check (matchOfName ('o' , 'open_book' )).prefix;
385
385
check (matchOfName ('open' , 'open_book' )).prefix;
386
386
check (matchOfName ('pe' , 'open_book' )).other;
387
- check (matchOfName ('boo' , 'open_book' )).other ;
387
+ check (matchOfName ('boo' , 'open_book' )).wordAligned ;
388
388
check (matchOfName ('ok' , 'open_book' )).other;
389
389
});
390
390
@@ -396,7 +396,7 @@ void main() {
396
396
check (matchOfName ('pen_' , 'open_book' )).none;
397
397
check (matchOfName ('n_b' , 'open_book' )).none;
398
398
399
- check (matchOfName ('blue_dia' , 'large_blue_diamond' )).other ;
399
+ check (matchOfName ('blue_dia' , 'large_blue_diamond' )).wordAligned ;
400
400
});
401
401
402
402
test ('spaces in query behave as underscores' , () {
@@ -407,7 +407,7 @@ void main() {
407
407
check (matchOfName ('pen ' , 'open_book' )).none;
408
408
check (matchOfName ('n b' , 'open_book' )).none;
409
409
410
- check (matchOfName ('blue dia' , 'large_blue_diamond' )).other ;
410
+ check (matchOfName ('blue dia' , 'large_blue_diamond' )).wordAligned ;
411
411
});
412
412
413
413
test ('query is lower-cased' , () {
@@ -426,13 +426,17 @@ void main() {
426
426
check (matchOfNames ('open b' , ['x' , 'open_book' ])).prefix;
427
427
check (matchOfNames ('pen_' , ['x' , 'open_book' ])).none;
428
428
429
+ check (matchOfNames ('blue_dia' , ['x' , 'large_blue_diamond' ])).wordAligned;
430
+
429
431
check (matchOfNames ('Smi' , ['x' , 'smile' ])).prefix;
430
432
});
431
433
432
434
test ('best match among name and aliases prevails' , () {
433
- check (matchOfNames ('a' , ['ab' , 'a' , 'ba' , 'x' ])).exact;
434
- check (matchOfNames ('a' , ['ba' , 'ab' , 'x' ])).prefix;
435
- check (matchOfNames ('a' , ['ba' , 'ab' ])).prefix;
435
+ check (matchOfNames ('a' , ['ab' , 'a' , 'b_a' , 'ba' , 'x' ])).exact;
436
+ check (matchOfNames ('a' , ['ba' , 'ab' , 'b_a' , 'x' ])).prefix;
437
+ check (matchOfNames ('a' , ['ba' , 'ab' , 'b_a' ])).prefix;
438
+ check (matchOfNames ('a' , ['ba' , 'b_a' , 'x' ])).wordAligned;
439
+ check (matchOfNames ('a' , ['b_a' , 'ba' ])).wordAligned;
436
440
check (matchOfNames ('a' , ['ba' , 'x' ])).other;
437
441
check (matchOfNames ('a' , ['x' , 'y' , 'z' ])).none;
438
442
});
@@ -478,7 +482,7 @@ void main() {
478
482
check (matchOf ('eqeq' , realmCandidate ('eqeq' ))).exact;
479
483
check (matchOf ('open_' , realmCandidate ('open_book' ))).prefix;
480
484
check (matchOf ('n_b' , realmCandidate ('open_book' ))).none;
481
- check (matchOf ('blue dia' , realmCandidate ('large_blue_diamond' ))).other ;
485
+ check (matchOf ('blue dia' , realmCandidate ('large_blue_diamond' ))).wordAligned ;
482
486
check (matchOf ('Smi' , realmCandidate ('smile' ))).prefix;
483
487
});
484
488
@@ -513,10 +517,12 @@ void main() {
513
517
514
518
final octopus = unicode (['octopus' ], emojiCode: '1f419' );
515
519
final workingOnIt = unicode (['working_on_it' ], emojiCode: '1f6e0' );
520
+ final love = unicode (['love' ], emojiCode: '2764' ); // aka :heart:
516
521
517
- test ('ranks exact before prefix before other match ' , () {
522
+ test ('ranks match quality exact/ prefix/word-aligned/ other' , () {
518
523
checkPrecedes ('o' , unicode (['o' ]), unicode (['onion' ]));
519
- checkPrecedes ('o' , unicode (['onion' ]), unicode (['book' ]));
524
+ checkPrecedes ('o' , unicode (['onion' ]), unicode (['squared_ok' ]));
525
+ checkPrecedes ('o' , unicode (['squared_ok' ]), unicode (['book' ]));
520
526
});
521
527
522
528
test ('ranks popular before realm before other Unicode' , () {
@@ -535,28 +541,51 @@ void main() {
535
541
checkPrecedes ('o' , octopus, realmCandidate ('open_book' ));
536
542
});
537
543
538
- test ('ranks popular-vs-not more significant than prefix/other ' , () {
539
- // Popular other beats realm prefix.
544
+ test ('ranks popular-vs-not more significant than prefix/word-aligned ' , () {
545
+ // Popular word-aligned beats realm prefix.
540
546
checkPrecedes ('o' , workingOnIt, realmCandidate ('open_book' ));
541
547
});
542
548
543
- test ('ranks prefix/other more significant than custom/other' , () {
544
- // Generic Unicode prefix beats realm other.
545
- checkPrecedes ('o' , unicode (['ok' ]), realmCandidate ('yo' ));
549
+ test ('ranks popular as if generic when non-word-aligned' , () {
550
+ // Generic word-aligned beats popular other.
551
+ checkPrecedes ('o' , unicode (['squared_ok' ]), love);
552
+ // Popular other ranks below even custom other…
553
+ checkPrecedes ('o' , realmCandidate ('yo' ), love);
554
+ // … and same as generic Unicode other.
555
+ checkSameRank ('o' , love, unicode (['book' ]));
556
+
557
+ // And that emoji really does count as popular,
558
+ // beating custom emoji when both have a prefix match.
559
+ checkPrecedes ('l' , love, realmCandidate ('logs' ));
560
+ });
561
+
562
+ test ('ranks custom/other more significant than prefix/word-aligned' , () {
563
+ // Custom word-aligned beats generic prefix.
564
+ checkPrecedes ('o' , realmCandidate ('laughing_blue_octopus' ),
565
+ unicode (['ok' ]));
566
+ });
567
+
568
+ test ('ranks word-aligned/other more significant than custom/other' , () {
569
+ // Generic Unicode word-aligned beats realm other.
570
+ checkPrecedes ('o' , unicode (['squared_ok' ]), realmCandidate ('yo' ));
546
571
});
547
572
548
573
test ('full list of ranks' , () {
549
574
check ([
550
575
rankOf ('o' , unicode (['o' ])), // exact (generic)
551
576
rankOf ('o' , octopus), // prefix popular
552
- rankOf ('o' , workingOnIt), // other popular
577
+ rankOf ('o' , workingOnIt), // word-aligned popular
553
578
rankOf ('o' , realmCandidate ('open_book' )), // prefix realm
554
579
rankOf ('z' , zulipCandidate ()), // == prefix :zulip:
580
+ rankOf ('y' , realmCandidate ('thank_you' )), // word-aligned realm
581
+ // (word-aligned :zulip: is impossible because the name is one word)
555
582
rankOf ('o' , unicode (['ok' ])), // prefix generic
583
+ rankOf ('o' , unicode (['squared_ok' ])), // word-aligned generic
556
584
rankOf ('o' , realmCandidate ('yo' )), // other realm
557
585
rankOf ('p' , zulipCandidate ()), // == other :zulip:
558
586
rankOf ('o' , unicode (['book' ])), // other generic
559
- ]).deepEquals ([0 , 1 , 2 , 3 , 3 , 4 , 5 , 5 , 6 ]);
587
+ rankOf ('o' , love), // == other popular
588
+ ]).deepEquals ([0 , 1 , 2 , 3 , 3 , 4 , 5 , 6 , 7 , 7 , 8 , 8 ]);
560
589
});
561
590
});
562
591
}
@@ -585,6 +614,7 @@ extension EmojiCandidateChecks on Subject<EmojiCandidate> {
585
614
extension EmojiMatchQualityChecks on Subject <EmojiMatchQuality ?> {
586
615
void get exact => equals (EmojiMatchQuality .exact);
587
616
void get prefix => equals (EmojiMatchQuality .prefix);
617
+ void get wordAligned => equals (EmojiMatchQuality .wordAligned);
588
618
void get other => equals (EmojiMatchQuality .other);
589
619
void get none => isNull ();
590
620
}
0 commit comments