@@ -324,98 +324,99 @@ void main() {
324
324
return EmojiAutocompleteQuery (query).match (candidate);
325
325
}
326
326
327
- bool matchesNames (String query, List <String > names) {
328
- return matchOf (query, unicode (names)) != null ;
327
+ EmojiMatchQuality ? matchOfNames (String query, List <String > names) {
328
+ return matchOf (query, unicode (names));
329
329
}
330
330
331
- bool matchesName (String query, String emojiName) {
332
- return matchesNames (query, [emojiName]);
331
+ EmojiMatchQuality ? matchOfName (String query, String emojiName) {
332
+ return matchOfNames (query, [emojiName]);
333
333
}
334
334
335
335
test ('one-word query matches anywhere in name' , () {
336
- check (matchesName ('' , 'smile' )).isTrue () ;
337
- check (matchesName ('s' , 'smile' )).isTrue () ;
338
- check (matchesName ('sm' , 'smile' )).isTrue () ;
339
- check (matchesName ('smile' , 'smile' )).isTrue () ;
340
- check (matchesName ('m' , 'smile' )).isTrue () ;
341
- check (matchesName ('mile' , 'smile' )).isTrue () ;
342
- check (matchesName ('e' , 'smile' )).isTrue () ;
343
-
344
- check (matchesName ('smiley' , 'smile' )).isFalse () ;
345
- check (matchesName ('a' , 'smile' )).isFalse () ;
346
-
347
- check (matchesName ('o' , 'open_book' )).isTrue () ;
348
- check (matchesName ('open' , 'open_book' )).isTrue () ;
349
- check (matchesName ('pe' , 'open_book' )).isTrue () ;
350
- check (matchesName ('boo' , 'open_book' )).isTrue () ;
351
- check (matchesName ('ok' , 'open_book' )).isTrue () ;
336
+ check (matchOfName ('' , 'smile' )).match ;
337
+ check (matchOfName ('s' , 'smile' )).match ;
338
+ check (matchOfName ('sm' , 'smile' )).match ;
339
+ check (matchOfName ('smile' , 'smile' )).match ;
340
+ check (matchOfName ('m' , 'smile' )).match ;
341
+ check (matchOfName ('mile' , 'smile' )).match ;
342
+ check (matchOfName ('e' , 'smile' )).match ;
343
+
344
+ check (matchOfName ('smiley' , 'smile' )).none ;
345
+ check (matchOfName ('a' , 'smile' )).none ;
346
+
347
+ check (matchOfName ('o' , 'open_book' )).match ;
348
+ check (matchOfName ('open' , 'open_book' )).match ;
349
+ check (matchOfName ('pe' , 'open_book' )).match ;
350
+ check (matchOfName ('boo' , 'open_book' )).match ;
351
+ check (matchOfName ('ok' , 'open_book' )).match ;
352
352
});
353
353
354
354
test ('multi-word query matches from start of a word' , () {
355
- check (matchesName ('open_' , 'open_book' )).isTrue () ;
356
- check (matchesName ('open_b' , 'open_book' )).isTrue () ;
357
- check (matchesName ('open_book' , 'open_book' )).isTrue () ;
355
+ check (matchOfName ('open_' , 'open_book' )).match ;
356
+ check (matchOfName ('open_b' , 'open_book' )).match ;
357
+ check (matchOfName ('open_book' , 'open_book' )).match ;
358
358
359
- check (matchesName ('pen_' , 'open_book' )).isFalse () ;
360
- check (matchesName ('n_b' , 'open_book' )).isFalse () ;
359
+ check (matchOfName ('pen_' , 'open_book' )).none ;
360
+ check (matchOfName ('n_b' , 'open_book' )).none ;
361
361
362
- check (matchesName ('blue_dia' , 'large_blue_diamond' )).isTrue () ;
362
+ check (matchOfName ('blue_dia' , 'large_blue_diamond' )).match ;
363
363
});
364
364
365
365
test ('spaces in query behave as underscores' , () {
366
- check (matchesName ('open ' , 'open_book' )).isTrue () ;
367
- check (matchesName ('open b' , 'open_book' )).isTrue () ;
368
- check (matchesName ('open book' , 'open_book' )).isTrue () ;
366
+ check (matchOfName ('open ' , 'open_book' )).match ;
367
+ check (matchOfName ('open b' , 'open_book' )).match ;
368
+ check (matchOfName ('open book' , 'open_book' )).match ;
369
369
370
- check (matchesName ('pen ' , 'open_book' )).isFalse () ;
371
- check (matchesName ('n b' , 'open_book' )).isFalse () ;
370
+ check (matchOfName ('pen ' , 'open_book' )).none ;
371
+ check (matchOfName ('n b' , 'open_book' )).none ;
372
372
373
- check (matchesName ('blue dia' , 'large_blue_diamond' )).isTrue () ;
373
+ check (matchOfName ('blue dia' , 'large_blue_diamond' )).match ;
374
374
});
375
375
376
376
test ('query is lower-cased' , () {
377
- check (matchesName ('Smi' , 'smile' )).isTrue () ;
377
+ check (matchOfName ('Smi' , 'smile' )).match ;
378
378
});
379
379
380
380
test ('query matches aliases same way as primary name' , () {
381
- check (matchesNames ('a' , ['a' , 'b' ])).isTrue () ;
382
- check (matchesNames ('b' , ['a' , 'b' ])).isTrue () ;
383
- check (matchesNames ('c' , ['a' , 'b' ])).isFalse () ;
381
+ check (matchOfNames ('a' , ['a' , 'b' ])).match ;
382
+ check (matchOfNames ('b' , ['a' , 'b' ])).match ;
383
+ check (matchOfNames ('c' , ['a' , 'b' ])).none ;
384
384
385
- check (matchesNames ('pe' , ['x' , 'open_book' ])).isTrue () ;
386
- check (matchesNames ('ok' , ['x' , 'open_book' ])).isTrue () ;
385
+ check (matchOfNames ('pe' , ['x' , 'open_book' ])).match ;
386
+ check (matchOfNames ('ok' , ['x' , 'open_book' ])).match ;
387
387
388
- check (matchesNames ('open_' , ['x' , 'open_book' ])).isTrue () ;
389
- check (matchesNames ('open b' , ['x' , 'open_book' ])).isTrue () ;
390
- check (matchesNames ('pen_' , ['x' , 'open_book' ])).isFalse () ;
388
+ check (matchOfNames ('open_' , ['x' , 'open_book' ])).match ;
389
+ check (matchOfNames ('open b' , ['x' , 'open_book' ])).match ;
390
+ check (matchOfNames ('pen_' , ['x' , 'open_book' ])).none ;
391
391
392
- check (matchesNames ('Smi' , ['x' , 'smile' ])).isTrue () ;
392
+ check (matchOfNames ('Smi' , ['x' , 'smile' ])).match ;
393
393
});
394
394
395
395
test ('query matches literal Unicode value' , () {
396
- bool matchesLiteral (String query, String emojiCode, {required String aka}) {
396
+ EmojiMatchQuality ? matchOfLiteral (String query, String emojiCode, {
397
+ required String aka}) {
397
398
assert (aka == query);
398
- return matchOf (query, unicode (['asdf' ], emojiCode: emojiCode)) != null ;
399
+ return matchOf (query, unicode (['asdf' ], emojiCode: emojiCode));
399
400
}
400
401
401
402
// Matching the code, in hex, doesn't count.
402
- check (matchesLiteral ('1f642' , aka: '1f642' , '1f642' )).isFalse () ;
403
+ check (matchOfLiteral ('1f642' , aka: '1f642' , '1f642' )).none ;
403
404
404
405
// Matching the Unicode value the code describes does count…
405
- check (matchesLiteral ('🙂' , aka: '\u {1f642}' , '1f642' )).isTrue () ;
406
+ check (matchOfLiteral ('🙂' , aka: '\u {1f642}' , '1f642' )).match ;
406
407
// … and failing to match it doesn't make a match.
407
- check (matchesLiteral ('🙁' , aka: '\u {1f641}' , '1f642' )).isFalse () ;
408
+ check (matchOfLiteral ('🙁' , aka: '\u {1f641}' , '1f642' )).none ;
408
409
409
410
// Multi-code-point emoji work fine.
410
- check (matchesLiteral ('🏳🌈' , aka: '\u {1f3f3}\u {200d}\u {1f308}' ,
411
- '1f3f3-200d-1f308' )).isTrue () ;
411
+ check (matchOfLiteral ('🏳🌈' , aka: '\u {1f3f3}\u {200d}\u {1f308}' ,
412
+ '1f3f3-200d-1f308' )).match ;
412
413
// Only exact matches count; no partial matches.
413
- check (matchesLiteral ('🏳' , aka: '\u {1f3f3}' ,
414
- '1f3f3-200d-1f308' )).isFalse () ;
415
- check (matchesLiteral ('🌈' , aka: '\u {200d}\u {1f308}' ,
416
- '1f3f3-200d-1f308' )).isFalse () ;
417
- check (matchesLiteral ('🏳🌈' , aka: '\u {1f3f3}\u {200d}\u {1f308}' ,
418
- '1f3f3' )).isFalse () ;
414
+ check (matchOfLiteral ('🏳' , aka: '\u {1f3f3}' ,
415
+ '1f3f3-200d-1f308' )).none ;
416
+ check (matchOfLiteral ('🌈' , aka: '\u {200d}\u {1f308}' ,
417
+ '1f3f3-200d-1f308' )).none ;
418
+ check (matchOfLiteral ('🏳🌈' , aka: '\u {1f3f3}\u {200d}\u {1f308}' ,
419
+ '1f3f3' )).none ;
419
420
});
420
421
421
422
test ('can match realm emoji' , () {
@@ -429,11 +430,11 @@ void main() {
429
430
resolvedStillUrl: eg.realmUrl.resolve ('/emoji/1-still.png' )));
430
431
}
431
432
432
- check (matchOf ('eqeq' , realmCandidate ('eqeq' ))).isNotNull () ;
433
- check (matchOf ('open_' , realmCandidate ('open_book' ))).isNotNull () ;
434
- check (matchOf ('n_b' , realmCandidate ('open_book' ))).isNull () ;
435
- check (matchOf ('blue dia' , realmCandidate ('large_blue_diamond' ))).isNotNull () ;
436
- check (matchOf ('Smi' , realmCandidate ('smile' ))).isNotNull () ;
433
+ check (matchOf ('eqeq' , realmCandidate ('eqeq' ))).match ;
434
+ check (matchOf ('open_' , realmCandidate ('open_book' ))).match ;
435
+ check (matchOf ('n_b' , realmCandidate ('open_book' ))).none ;
436
+ check (matchOf ('blue dia' , realmCandidate ('large_blue_diamond' ))).match ;
437
+ check (matchOf ('Smi' , realmCandidate ('smile' ))).match ;
437
438
});
438
439
439
440
test ('can match Zulip extra emoji' , () {
@@ -445,10 +446,10 @@ void main() {
445
446
emojiType: ReactionType .zulipExtraEmoji,
446
447
emojiCode: 'zulip' , emojiName: 'zulip' ));
447
448
448
- check (matchOf ('z' , zulipCandidate)).isNotNull () ;
449
- check (matchOf ('Zulip' , zulipCandidate)).isNotNull () ;
450
- check (matchOf ('p' , zulipCandidate)).isNotNull () ;
451
- check (matchOf ('x' , zulipCandidate)).isNull () ;
449
+ check (matchOf ('z' , zulipCandidate)).match ;
450
+ check (matchOf ('Zulip' , zulipCandidate)).match ;
451
+ check (matchOf ('p' , zulipCandidate)).match ;
452
+ check (matchOf ('x' , zulipCandidate)).none ;
452
453
});
453
454
});
454
455
}
@@ -474,6 +475,11 @@ extension EmojiCandidateChecks on Subject<EmojiCandidate> {
474
475
Subject <EmojiDisplay > get emojiDisplay => has ((x) => x.emojiDisplay, 'emojiDisplay' );
475
476
}
476
477
478
+ extension EmojiMatchQualityChecks on Subject <EmojiMatchQuality ?> {
479
+ void get match => equals (EmojiMatchQuality .match);
480
+ void get none => isNull ();
481
+ }
482
+
477
483
extension EmojiAutocompleteResultChecks on Subject <EmojiAutocompleteResult > {
478
484
Subject <EmojiCandidate > get candidate => has ((x) => x.candidate, 'candidate' );
479
485
}
0 commit comments