File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ import 'dart:collection' ;
2
+
1
3
import 'package:flutter/foundation.dart' ;
2
4
3
5
import '../api/model/events.dart' ;
@@ -369,3 +371,21 @@ class ChannelStoreImpl with ChannelStore {
369
371
}
370
372
}
371
373
}
374
+
375
+ /// A [Map] with [TopicName] keys and [V] values.
376
+ ///
377
+ /// When one of these is created by [makeTopicKeyedMap] ,
378
+ /// key equality is done case-insensitively; see there.
379
+ ///
380
+ /// This type should only be used for maps created by [makeTopicKeyedMap] .
381
+ /// It would be nice to enforce that.
382
+ typedef TopicKeyedMap <V > = Map <TopicName , V >;
383
+
384
+ /// Make a case-insensitive, case-preserving [TopicName] -keyed [LinkedHashMap] .
385
+ ///
386
+ /// The equality function is [TopicName.isSameAs] ,
387
+ /// and the hash code is [String.hashCode] of [TopicName.canonicalize] .
388
+ TopicKeyedMap <V > makeTopicKeyedMap <V >() => LinkedHashMap <TopicName , V >(
389
+ equals: (a, b) => a.isSameAs (b),
390
+ hashCode: (k) => k.canonicalize ().hashCode,
391
+ );
Original file line number Diff line number Diff line change @@ -7,7 +7,9 @@ import 'package:zulip/api/model/model.dart';
7
7
import 'package:zulip/model/store.dart' ;
8
8
import 'package:zulip/model/channel.dart' ;
9
9
10
+ import '../api/model/model_checks.dart' ;
10
11
import '../example_data.dart' as eg;
12
+ import '../stdlib_checks.dart' ;
11
13
import 'test_store.dart' ;
12
14
13
15
void main () {
@@ -412,4 +414,30 @@ void main() {
412
414
.equals (UserTopicVisibilityPolicy .none);
413
415
});
414
416
});
417
+
418
+ group ('makeTopicKeyedMap' , () {
419
+ test ('"a" equals "A"' , () {
420
+ final map = makeTopicKeyedMap <int >()
421
+ ..[eg.t ('a' )] = 1
422
+ ..[eg.t ('A' )] = 2 ;
423
+ check (map)
424
+ ..[eg.t ('a' )].equals (2 )
425
+ ..[eg.t ('A' )].equals (2 )
426
+ ..entries.which ((it) => it.single
427
+ ..key.apiName.equals ('a' )
428
+ ..value.equals (2 ));
429
+ });
430
+
431
+ test ('"A" equals "a"' , () {
432
+ final map = makeTopicKeyedMap <int >()
433
+ ..[eg.t ('A' )] = 1
434
+ ..[eg.t ('a' )] = 2 ;
435
+ check (map)
436
+ ..[eg.t ('A' )].equals (2 )
437
+ ..[eg.t ('a' )].equals (2 )
438
+ ..entries.which ((it) => it.single
439
+ ..key.apiName.equals ('A' )
440
+ ..value.equals (2 ));
441
+ });
442
+ });
415
443
}
Original file line number Diff line number Diff line change @@ -16,6 +16,11 @@ extension ListChecks<T> on Subject<List<T>> {
16
16
Subject <T > operator [](int index) => has ((l) => l[index], '[$index ]' );
17
17
}
18
18
19
+ extension MapEntryChecks <K , V > on Subject <MapEntry <K , V >> {
20
+ Subject <K > get key => has ((e) => e.key, 'key' );
21
+ Subject <V > get value => has ((e) => e.value, 'value' );
22
+ }
23
+
19
24
extension NullableMapChecks <K , V > on Subject <Map <K , V >?> {
20
25
void deepEquals (Map <Object ?, Object ?>? expected) {
21
26
if (expected == null ) {
You can’t perform that action at this time.
0 commit comments