Skip to content

Commit d9d6a5e

Browse files
some more equality tests
1 parent 45c538d commit d9d6a5e

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

t/equality.t

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ use Helper;
1919
subtest 'equality, using inflated data' => sub {
2020
foreach my $test (
2121
[ undef, undef, true ],
22+
[ undef, false, false ],
23+
[ undef, true , false ],
2224
[ undef, 1, false ],
25+
[ undef, '1', false ],
2326
[ \0, 0, false ],
2427
[ \0, false, false ],
2528
[ \1, 1, false ],
@@ -33,6 +36,10 @@ subtest 'equality, using inflated data' => sub {
3336
[ [qw(a b)], [qw(b a)], false, '/0' ],
3437
[ 1, 1, true ],
3538
[ 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 ],
3643
[ [1,2], [2,1], false, '/0' ],
3744
[ { a => 1, b => 2 }, { b => 2, a => 1 }, true ],
3845
[ { a => 1 }, { a => 1.0 }, true ],
@@ -74,7 +81,6 @@ subtest 'equality, using JSON strings' => sub {
7481
[ '{"a":1,"b":2}', '{"b":3,"a":1}', false, '/b' ],
7582
[ '{"a":{"b":1,"c":2},"d":{"e":3,"f":4}}',
7683
'{"a":{"b":1,"c":2},"d":{"e":3,"f":5}}', false, '/d/f' ],
77-
7884
) {
7985
my ($x, $y, $expected, $diff_path) = @$test;
8086
($x, $y) = map $decoder->decode($_), $x, $y;
@@ -91,4 +97,29 @@ subtest 'equality, using JSON strings' => sub {
9197
}
9298
};
9399

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+
94125
done_testing;

0 commit comments

Comments
 (0)