@@ -347,7 +347,7 @@ void main() {
347
347
check (matchOfName ('o' , 'open_book' )).prefix;
348
348
check (matchOfName ('open' , 'open_book' )).prefix;
349
349
check (matchOfName ('pe' , 'open_book' )).other;
350
- check (matchOfName ('boo' , 'open_book' )).other ;
350
+ check (matchOfName ('boo' , 'open_book' )).wordAligned ;
351
351
check (matchOfName ('ok' , 'open_book' )).other;
352
352
});
353
353
@@ -359,7 +359,7 @@ void main() {
359
359
check (matchOfName ('pen_' , 'open_book' )).none;
360
360
check (matchOfName ('n_b' , 'open_book' )).none;
361
361
362
- check (matchOfName ('blue_dia' , 'large_blue_diamond' )).other ;
362
+ check (matchOfName ('blue_dia' , 'large_blue_diamond' )).wordAligned ;
363
363
});
364
364
365
365
test ('spaces in query behave as underscores' , () {
@@ -370,7 +370,7 @@ void main() {
370
370
check (matchOfName ('pen ' , 'open_book' )).none;
371
371
check (matchOfName ('n b' , 'open_book' )).none;
372
372
373
- check (matchOfName ('blue dia' , 'large_blue_diamond' )).other ;
373
+ check (matchOfName ('blue dia' , 'large_blue_diamond' )).wordAligned ;
374
374
});
375
375
376
376
test ('query is lower-cased' , () {
@@ -389,13 +389,17 @@ void main() {
389
389
check (matchOfNames ('open b' , ['x' , 'open_book' ])).prefix;
390
390
check (matchOfNames ('pen_' , ['x' , 'open_book' ])).none;
391
391
392
+ check (matchOfNames ('blue_dia' , ['x' , 'large_blue_diamond' ])).wordAligned;
393
+
392
394
check (matchOfNames ('Smi' , ['x' , 'smile' ])).prefix;
393
395
});
394
396
395
397
test ('best match among name and aliases prevails' , () {
396
- check (matchOfNames ('a' , ['ab' , 'a' , 'ba' , 'x' ])).exact;
397
- check (matchOfNames ('a' , ['ba' , 'ab' , 'x' ])).prefix;
398
- check (matchOfNames ('a' , ['ba' , 'ab' ])).prefix;
398
+ check (matchOfNames ('a' , ['ab' , 'a' , 'b_a' , 'ba' , 'x' ])).exact;
399
+ check (matchOfNames ('a' , ['ba' , 'ab' , 'b_a' , 'x' ])).prefix;
400
+ check (matchOfNames ('a' , ['ba' , 'ab' , 'b_a' ])).prefix;
401
+ check (matchOfNames ('a' , ['ba' , 'b_a' , 'x' ])).wordAligned;
402
+ check (matchOfNames ('a' , ['b_a' , 'ba' ])).wordAligned;
399
403
check (matchOfNames ('a' , ['ba' , 'x' ])).other;
400
404
check (matchOfNames ('a' , ['x' , 'y' , 'z' ])).none;
401
405
});
@@ -441,7 +445,7 @@ void main() {
441
445
check (matchOf ('eqeq' , realmCandidate ('eqeq' ))).exact;
442
446
check (matchOf ('open_' , realmCandidate ('open_book' ))).prefix;
443
447
check (matchOf ('n_b' , realmCandidate ('open_book' ))).none;
444
- check (matchOf ('blue dia' , realmCandidate ('large_blue_diamond' ))).other ;
448
+ check (matchOf ('blue dia' , realmCandidate ('large_blue_diamond' ))).wordAligned ;
445
449
check (matchOf ('Smi' , realmCandidate ('smile' ))).prefix;
446
450
});
447
451
@@ -476,10 +480,12 @@ void main() {
476
480
477
481
final octopus = unicode (['octopus' ], emojiCode: '1f419' );
478
482
final workingOnIt = unicode (['working_on_it' ], emojiCode: '1f6e0' );
483
+ final love = unicode (['love' ], emojiCode: '2764' ); // aka :heart:
479
484
480
- test ('ranks exact before prefix before other match ' , () {
485
+ test ('ranks match quality exact/ prefix/word-aligned/ other' , () {
481
486
checkPrecedes ('o' , unicode (['o' ]), unicode (['onion' ]));
482
- checkPrecedes ('o' , unicode (['onion' ]), unicode (['book' ]));
487
+ checkPrecedes ('o' , unicode (['onion' ]), unicode (['squared_ok' ]));
488
+ checkPrecedes ('o' , unicode (['squared_ok' ]), unicode (['book' ]));
483
489
});
484
490
485
491
test ('ranks popular before realm before other Unicode' , () {
@@ -498,28 +504,51 @@ void main() {
498
504
checkPrecedes ('o' , octopus, realmCandidate ('open_book' ));
499
505
});
500
506
501
- test ('ranks popular-vs-not more significant than prefix/other ' , () {
502
- // Popular other beats realm prefix.
507
+ test ('ranks popular-vs-not more significant than prefix/word-aligned ' , () {
508
+ // Popular word-aligned beats realm prefix.
503
509
checkPrecedes ('o' , workingOnIt, realmCandidate ('open_book' ));
504
510
});
505
511
506
- test ('ranks prefix/other more significant than custom/other' , () {
507
- // Generic Unicode prefix beats realm other.
508
- checkPrecedes ('o' , unicode (['ok' ]), realmCandidate ('yo' ));
512
+ test ('ranks popular as if generic when non-word-aligned' , () {
513
+ // Generic word-aligned beats popular other.
514
+ checkPrecedes ('o' , unicode (['squared_ok' ]), love);
515
+ // Popular other ranks below even custom other…
516
+ checkPrecedes ('o' , realmCandidate ('yo' ), love);
517
+ // … and same as generic Unicode other.
518
+ checkSameRank ('o' , love, unicode (['book' ]));
519
+
520
+ // And that emoji really does count as popular,
521
+ // beating custom emoji when both have a prefix match.
522
+ checkPrecedes ('l' , love, realmCandidate ('logs' ));
523
+ });
524
+
525
+ test ('ranks custom/other more significant than prefix/word-aligned' , () {
526
+ // Custom word-aligned beats generic prefix.
527
+ checkPrecedes ('o' , realmCandidate ('laughing_blue_octopus' ),
528
+ unicode (['ok' ]));
529
+ });
530
+
531
+ test ('ranks word-aligned/other more significant than custom/other' , () {
532
+ // Generic Unicode word-aligned beats realm other.
533
+ checkPrecedes ('o' , unicode (['squared_ok' ]), realmCandidate ('yo' ));
509
534
});
510
535
511
536
test ('full list of ranks' , () {
512
537
check ([
513
538
rankOf ('o' , unicode (['o' ])), // exact (generic)
514
539
rankOf ('o' , octopus), // prefix popular
515
- rankOf ('o' , workingOnIt), // other popular
540
+ rankOf ('o' , workingOnIt), // word-aligned popular
516
541
rankOf ('o' , realmCandidate ('open_book' )), // prefix realm
517
542
rankOf ('z' , zulipCandidate ()), // == prefix :zulip:
543
+ rankOf ('y' , realmCandidate ('thank_you' )), // word-aligned realm
544
+ // (word-aligned :zulip: is impossible because the name is one word)
518
545
rankOf ('o' , unicode (['ok' ])), // prefix generic
546
+ rankOf ('o' , unicode (['squared_ok' ])), // word-aligned generic
519
547
rankOf ('o' , realmCandidate ('yo' )), // other realm
520
548
rankOf ('p' , zulipCandidate ()), // == other :zulip:
521
549
rankOf ('o' , unicode (['book' ])), // other generic
522
- ]).deepEquals ([0 , 1 , 2 , 3 , 3 , 4 , 5 , 5 , 6 ]);
550
+ rankOf ('o' , love), // == other popular
551
+ ]).deepEquals ([0 , 1 , 2 , 3 , 3 , 4 , 5 , 6 , 7 , 7 , 8 , 8 ]);
523
552
});
524
553
});
525
554
}
@@ -548,6 +577,7 @@ extension EmojiCandidateChecks on Subject<EmojiCandidate> {
548
577
extension EmojiMatchQualityChecks on Subject <EmojiMatchQuality ?> {
549
578
void get exact => equals (EmojiMatchQuality .exact);
550
579
void get prefix => equals (EmojiMatchQuality .prefix);
580
+ void get wordAligned => equals (EmojiMatchQuality .wordAligned);
551
581
void get other => equals (EmojiMatchQuality .other);
552
582
void get none => isNull ();
553
583
}
0 commit comments