9 plan skip_all => "JSON required" if $@;
11 use_ok( 'URI::Template' );
14 my @files = glob( $ENV{ UT_SPEC_GLOB } || 't/cases/*.json' );
16 for my $file ( @files ) {
19 # skip these tests for now
20 next if $file =~ m{negative};
22 open( my $json, $file );
23 my $data = do { local $/; <$json> };
26 eval { JSON->VERSION( 2 ) };
27 my $suite = $@ ? JSON::jsonToObj( $data ) : JSON::from_json( $data );
29 for my $name ( sort keys %$suite ) {
30 my $info = $suite->{ $name };
31 my $vars = $info->{ variables };
32 my $cases = $info->{ testcases };
34 note( sprintf( '%s [level %d]', $name, ( $info->{ level } || 4 ) ) );
36 for my $case ( @$cases ) {
37 my ( $input, $expect ) = @$case;
40 my $template = URI::Template->new( $input );
41 $result = $template->process_to_string( $vars );
44 _check_result( $result, $expect, $input );
51 my ( $result, $expect, $input ) = @_;
54 if ( Scalar::Util::blessed( $expect ) ) {
55 ok( !defined $result, $input );
58 # list of possible results
59 elsif ( ref $expect ) {
61 for my $e ( @$expect ) {
62 if ( $result eq $e ) {
67 diag( "got: $result" ) if !$ok;
73 is( $result, $expect, $input );