File: 01_test.t

package info (click to toggle)
libtest-deep-json-perl 0.05-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 124 kB
  • sloc: perl: 33; makefile: 2
file content (85 lines) | stat: -rw-r--r-- 1,693 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use strict;
use warnings;
use Test::Tester;
use Test::More tests => 6;
use Test::Deep;
use Test::Deep::JSON;

cmp_deeply {
    foo => 'bar',
    json => '{"a":1}',
}, {
    foo => 'bar',
    json => json({ a => ignore() })
};

cmp_deeply {
    foo => 'bar',
    json => '{"a":1}',
}, superhashof {
    json => json({ a => 1 })
};

subtest 'JSON cmp failure (expect raw hash)' => sub {
    check_test sub {
        cmp_deeply {
            json => '{"a":1}',
        }, {
            json => json({ a => 2 })
        }
    }, {
        ok => 0,
        diag => <<'__DIAG__'
Compared $data->{"json"}->{"a"}
   got : '1'
expect : '2'
__DIAG__
    };
};

subtest 'JSON cmp failure (expect Test::Deep object)' => sub {
    check_test sub {
        cmp_deeply {
            json => '{"a":1}',
        }, {
            json => json(superhashof { x => ignore() })
        };
    }, {
        ok => 0,
        diag => <<'__DIAG__'
Comparing hash keys of $data->{"json"}
Missing: 'x'
__DIAG__
    };
};

subtest 'JSON parse error' => sub {
    check_test sub {
        cmp_deeply {
            json => '{ invalid json }',
        }, {
            json => json({ a => ignore() })
        };
    }, {
        ok => 0,
    };
};

subtest 'failture on nested' => sub {
    check_test sub {
        cmp_deeply {
            json => '{"foo":"X"}',
        }, {
            json => json(code(sub { ( $_[0]->{foo} eq 'Y', 'foo should be Y' ) }))
        };
    }, {
        ok => 0,
        diag => [ run_tests sub {
            cmp_deeply {
                json => '{"foo":"X"}'
            }, {
                json => code(sub { ( 0, 'foo should be Y' ) })
            };
        } ]->[1]->{diag},
    };
};