@@ -19,7 +19,10 @@ use Helper;
19
19
subtest ' equality, using inflated data' => sub {
20
20
foreach my $test (
21
21
[ undef , undef , true ],
22
+ [ undef , false, false ],
23
+ [ undef , true , false ],
22
24
[ undef , 1, false ],
25
+ [ undef , ' 1' , false ],
23
26
[ \0, 0, false ],
24
27
[ \0, false, false ],
25
28
[ \1, 1, false ],
@@ -33,6 +36,10 @@ subtest 'equality, using inflated data' => sub {
33
36
[ [qw( a b) ], [qw( b a) ], false, ' /0' ],
34
37
[ 1, 1, true ],
35
38
[ 1, 1.0, true ],
39
+ [ 1, ' 1.0' , false ],
40
+ [ ' 1.1' , 1.1, false ],
41
+ [ ' 1' , 1, false ],
42
+ [ ' 1.1' , 1.1, false ],
36
43
[ [1,2], [2,1], false, ' /0' ],
37
44
[ { a => 1, b => 2 }, { b => 2, a => 1 }, true ],
38
45
[ { a => 1 }, { a => 1.0 }, true ],
@@ -74,7 +81,6 @@ subtest 'equality, using JSON strings' => sub {
74
81
[ ' {"a":1,"b":2}' , ' {"b":3,"a":1}' , false, ' /b' ],
75
82
[ ' {"a":{"b":1,"c":2},"d":{"e":3,"f":4}}' ,
76
83
' {"a":{"b":1,"c":2},"d":{"e":3,"f":5}}' , false, ' /d/f' ],
77
-
78
84
) {
79
85
my ($x , $y , $expected , $diff_path ) = @$test ;
80
86
($x , $y ) = map $decoder -> decode($_ ), $x , $y ;
@@ -91,4 +97,29 @@ subtest 'equality, using JSON strings' => sub {
91
97
}
92
98
};
93
99
100
+ subtest ' equality, using scalarref booleans' => sub {
101
+ local $JSON::Schema::Tiny::SCALARREF_BOOLEANS = 1;
102
+
103
+ foreach my $test (
104
+ [ \0, true, false ],
105
+ [ \1, true, true ],
106
+ [ \0, false, true ],
107
+ [ \1, false, false ],
108
+ [ undef , \0, false ],
109
+ [ undef , false, false ],
110
+ ) {
111
+ my ($x , $y , $expected , $diff_path ) = @$test ;
112
+ my @types = map JSON::Schema::Tiny::get_type($_ ), $x , $y ;
113
+ my $result = JSON::Schema::Tiny::is_equal($x , $y , my $state = {});
114
+
115
+ ok(!($result xor $expected ), json_sprintf(' %s == %s is %s' , $x , $y , $expected ));
116
+ is($state -> {path }, $diff_path // ' ' , ' two instances differ at the expected place' ) if not $expected ;
117
+
118
+ ok(JSON::Schema::Tiny::is_type($types [0], $x ), ' type of arg 0 was not mutated while making equality check' );
119
+ ok(JSON::Schema::Tiny::is_type($types [1], $y ), ' type of arg 1 was not mutated while making equality check' );
120
+
121
+ note ' ' ;
122
+ }
123
+ };
124
+
94
125
done_testing;
0 commit comments