Last active
December 15, 2015 18:09
-
-
Save jberger/5301776 to your computer and use it in GitHub Desktop.
JSON pointer tests that follow the examples in RFC 6901
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Mojo::Base -strict; | |
use Test::More; | |
use Mojo::JSON::Pointer; | |
my $json = { | |
'foo' => ['bar', 'baz'], | |
'' => 0, | |
'a/b' => 1, | |
'c%d' => 2, | |
'e^f' => 3, | |
'g|h' => 4, | |
'i\\j'=> 5, | |
'k\'l'=> 6, | |
' ' => 7, | |
'm~n' => 8 | |
}; | |
my %tests = ( | |
'' => $json, | |
'/foo' => ['bar', 'baz'], | |
'/foo/0' => 'bar', | |
'/' => 0, | |
'/a~1b' => 1, | |
'/c%25d' => 2, | |
'/e%5Ef' => 3, | |
'/g%7Ch' => 4, | |
'/i%5Cj' => 5, | |
'/k%27l' => 6, | |
'/%20' => 7, | |
'/m~0n' => 8, | |
); | |
my $p = Mojo::JSON::Pointer->new; | |
for my $pointer ( keys %tests ) { | |
is_deeply $p->get($json, $pointer), $tests{$pointer}, "right value for pointer $pointer"; | |
} | |
done_testing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment