Imported Upstream version 0.14.01
[liburi-template-perl.git] / t / 12-suite.t
index 19b0914..1acb5b5 100644 (file)
@@ -4,8 +4,8 @@ use warnings;
 use Test::More;
 
 BEGIN {
-       eval "use JSON ();";
-       plan skip_all => "JSON required" if $@;
+    eval "use JSON ();";
+    plan skip_all => "JSON required" if $@;
     plan( 'no_plan' );
     use_ok( 'URI::Template' );
 }
@@ -14,18 +14,19 @@ my @files = glob( 't/data/*.json' );
 
 for my $file ( @files ) {
     open( my $json, $file );
-    my $suite = JSON::jsonToObj( do { local $/; <$json> } );
+    my $data = do { local $/; <$json> };
     close( $json );
 
-    my %variables = %{ $suite->{ variables } };
+    eval { JSON->VERSION( 2 ) };
+    my $suite     = $@ ? JSON::jsonToObj( $data ) : JSON::from_json( $data );
+    my $variables = $suite->{variables};
 
     my $count = 0;
-    for my $test ( @{ $suite->{ tests } } ) {
-        my $template = URI::Template->new( $test->{ template } );
-        my $result = $template->process( %variables );
+    for my $test (@{ $suite->{tests} }) {
+        my $template = URI::Template->new( $test->{template} );
+        my $result   = $template->process( $variables );
         $count++;
-        is( $result, $test->{ expected }, "${file}#${count}" );
+        is( $result, $test->{expected}, "${file} test ${count}" );
     }
 }
 
-