Skip to content

Instantly share code, notes, and snippets.

@jberger
Last active December 15, 2015 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jberger/5301776 to your computer and use it in GitHub Desktop.
Save jberger/5301776 to your computer and use it in GitHub Desktop.
JSON pointer tests that follow the examples in RFC 6901
#!/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