File: 004_as_pointer.t

package info (click to toggle)
libjson-pointer-perl 0.07-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 252 kB
  • sloc: perl: 578; makefile: 2
file content (31 lines) | stat: -rw-r--r-- 1,016 bytes parent folder | download | duplicates (2)
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
#!perl -w
use strict;
use Test::More;
use JSON::Pointer::Syntax;

sub test_as_pointer {
    my ($tokens, $expect, $desc) = @_;
    subtest $desc => sub {
        my $actual = JSON::Pointer::Syntax->as_pointer($tokens);
        is($actual, $expect, "arrayref");
        $actual = JSON::Pointer::Syntax->as_pointer(@$tokens);
        is($actual, $expect, "array");
    }
}

subtest "JSON Pointer Section 5 examples" => sub {
    test_as_pointer([], '', q{""});
    test_as_pointer(['foo'], '/foo', q{"/foo"});
    test_as_pointer(['foo', 0], '/foo/0', q{"/foo/0"});
    test_as_pointer([''], '/', q{"/"});
    test_as_pointer(['a/b'], '/a~1b', q{"/a~1b"});
    test_as_pointer(['c%d'], '/c%d', q{"/c%d"});
    test_as_pointer(['e^f'], '/e^f', q{"/e^f"});
    test_as_pointer(['g|h'], '/g|h', q{"/g|h"});
    test_as_pointer(['i\\j'], '/i\\j', q{"/i\\j"});
    test_as_pointer(['k"l'], '/k"l', q{"/k\"l"});
    test_as_pointer([' '], '/ ', q{"/ "});
    test_as_pointer(['m~n'], '/m~0n', q{"/m~0n"});
};

done_testing;