@@ -363,6 +363,109 @@ void main() {
363363 });
364364 });
365365
366+ group ('Simple Equatable (map custom key)' , () {
367+ test ('should correct toString' , () {
368+ final instance = SimpleEquatable (< SimpleEquatable <String >, dynamic > {});
369+ expect (
370+ instance.toString (),
371+ 'SimpleEquatable<Map<SimpleEquatable<String>, dynamic>>({})' ,
372+ );
373+ });
374+
375+ test ('should return true when instance is the same' , () {
376+ final instance = SimpleEquatable (
377+ {
378+ SimpleEquatable <String >('a' ): 1 ,
379+ SimpleEquatable <String >('b' ): 2 ,
380+ SimpleEquatable <String >('c' ): 3
381+ },
382+ );
383+ expect (instance == instance, true );
384+ });
385+
386+ test ('should return correct hashCode' , () {
387+ final instance = SimpleEquatable (
388+ {
389+ SimpleEquatable <String >('a' ): 1 ,
390+ SimpleEquatable <String >('b' ): 2 ,
391+ SimpleEquatable <String >('c' ): 3
392+ },
393+ );
394+ expect (
395+ instance.hashCode,
396+ instance.runtimeType.hashCode ^ mapPropsToHashCode (instance.props),
397+ );
398+ });
399+
400+ test ('should have same hashCode when values are equal' , () {
401+ final instanceA = SimpleEquatable (
402+ {
403+ SimpleEquatable <String >('a' ): 1 ,
404+ SimpleEquatable <String >('b' ): 2 ,
405+ SimpleEquatable <String >('c' ): 3
406+ },
407+ );
408+ final instanceB = SimpleEquatable (
409+ {
410+ SimpleEquatable <String >('b' ): 2 ,
411+ SimpleEquatable <String >('a' ): 1 ,
412+ SimpleEquatable <String >('c' ): 3
413+ },
414+ );
415+ expect (instanceA == instanceB, true );
416+ expect (instanceA.hashCode, instanceB.hashCode);
417+ });
418+
419+ test ('should return true when instances are different' , () {
420+ final instanceA = SimpleEquatable (
421+ {
422+ SimpleEquatable <String >('a' ): 1 ,
423+ SimpleEquatable <String >('b' ): 2 ,
424+ SimpleEquatable <String >('c' ): 3
425+ },
426+ );
427+ final instanceB = SimpleEquatable (
428+ {
429+ SimpleEquatable <String >('a' ): 1 ,
430+ SimpleEquatable <String >('b' ): 2 ,
431+ SimpleEquatable <String >('c' ): 3
432+ },
433+ );
434+ expect (instanceA == instanceB, true );
435+ expect (instanceA.hashCode == instanceB.hashCode, true );
436+ });
437+
438+ test ('should return false when compared to non-equatable' , () {
439+ final instanceA = SimpleEquatable (
440+ {
441+ SimpleEquatable <String >('a' ): 1 ,
442+ SimpleEquatable <String >('b' ): 2 ,
443+ SimpleEquatable <String >('c' ): 3
444+ },
445+ );
446+ final instanceB = NonEquatable ();
447+ expect (instanceA == instanceB, false );
448+ });
449+
450+ test ('should return false when values are different' , () {
451+ final instanceA = SimpleEquatable (
452+ {
453+ SimpleEquatable <String >('a' ): 1 ,
454+ SimpleEquatable <String >('b' ): 2 ,
455+ SimpleEquatable <String >('c' ): 3
456+ },
457+ );
458+ final instanceB = SimpleEquatable (
459+ {
460+ SimpleEquatable <String >('a' ): 1 ,
461+ SimpleEquatable <String >('b' ): 2 ,
462+ SimpleEquatable <String >('c' ): 2
463+ },
464+ );
465+ expect (instanceA == instanceB, false );
466+ });
467+ });
468+
366469 group ('Simple Equatable (Equatable)' , () {
367470 test ('should correct toString' , () {
368471 final instance = SimpleEquatable (EquatableData (
0 commit comments