9 plan skip_all => "JSON required" if $@;
11 eval { JSON->VERSION( 2 ) };
12 plan skip_all => "JSON version 2 of greater required" if $@;
15 use_ok( 'URI::Template' );
18 my @files = glob( $ENV{ UT_SPEC_GLOB } || 't/cases/*.json' );
20 for my $file ( @files ) {
23 # skip these tests for now
24 next if $file =~ m{negative};
26 open( my $json, $file );
27 my $data = do { local $/; <$json> };
30 my $suite = JSON->new->utf8( 1 )->decode( $data );
32 for my $name ( sort keys %$suite ) {
33 my $info = $suite->{ $name };
34 my $vars = $info->{ variables };
35 my $cases = $info->{ testcases };
37 note( sprintf( '%s [level %d]', $name, ( $info->{ level } || 4 ) ) );
39 for my $case ( @$cases ) {
40 my ( $input, $expect ) = @$case;
43 my $template = URI::Template->new( $input );
44 $result = $template->process_to_string( $vars );
47 _check_result( $result, $expect, $input );
54 my ( $result, $expect, $input ) = @_;
57 if ( Scalar::Util::blessed( $expect ) ) {
58 ok( !defined $result, $input );
61 # list of possible results
62 elsif ( ref $expect ) {
64 for my $e ( @$expect ) {
65 if ( $result eq $e ) {
70 diag( "got: $result" ) if !$ok;
76 is( $result, $expect, $input );