X-Git-Url: http://erislabs.net/gitweb/?p=liburi-template-perl.git;a=blobdiff_plain;f=t%2F10-basic.t;h=4d6f404c8ddcf8d812dbb7149d26a1d6e408109b;hp=42403674cd7c2ae33d59701da2a12ce7072950ab;hb=1d94fcb2781945132b9a29e93744b6c168e647aa;hpb=53a1b94e04453d9c7eea079af549f2179320b952 diff --git a/t/10-basic.t b/t/10-basic.t index 4240367..4d6f404 100644 --- a/t/10-basic.t +++ b/t/10-basic.t @@ -1,22 +1,45 @@ use strict; use warnings; -use Test::More tests => 15; +use Test::More tests => 21; use_ok( 'URI::Template' ); -# fatal - no template provided +# new, empty template { - eval { URI::Template->new; }; - ok( $@ ); + my $template = URI::Template->new; + isa_ok( $template, 'URI::Template' ); + + { + my $result = $template->process(); + is( $result, '', 'process() for empty template' ); + isa_ok( $result, 'URI', 'return value from process() isa URI' ); + } +} + +# Update template +{ + my $template = URI::Template->new; + is( "$template", '', 'stringify from empty' ); + + my $text = 'http://foo.com/{bar}/{baz}'; + $template->template($text); + + is( "$template", $text, 'stringify from updated template' ); + + { + my $result = $template->process( bar => 'x', baz => 'y' ); + is( $result, 'http://foo.com/x/y', 'process() for updated template' ); + isa_ok( $result, 'URI', 'return value from process() isa URI' ); + } } { my $text = 'http://foo.com/{bar}/{baz}?q=%7B'; my $template = URI::Template->new( $text ); isa_ok( $template, 'URI::Template' ); - is_deeply( [ sort $template->variables ], [ qw( bar baz ) ], 'variables()' ); - is( "$template", $text, 'as_string()' ); + is_deeply( [ sort $template->variables ], [ 'bar', 'baz' ], 'variables()' ); + is( "$template", $text, 'stringify' ); { my $result = $template->process( bar => 'x', baz => 'y' ); @@ -43,7 +66,7 @@ use_ok( 'URI::Template' ); is( $result, 'http://foo.com/%7Bx%7D/', 'values are uri escaped' ); } { - my $result = $template->process( ); + my $result = $template->process(); is( $result, 'http://foo.com//', 'no value sent' ); } { @@ -54,7 +77,7 @@ use_ok( 'URI::Template' ); { my $template = URI::Template->new( 'http://foo.com/{z}/{z}/' ); - is_deeply( [ $template->variables ], [ 'z' ], 'unique vars' ); + is_deeply( [ sort $template->variables ], [ 'z' ], 'no duplicates in variables()' ); my $result = $template->process( 'z' => 'x' ); is( $result, 'http://foo.com/x/x/', 'multiple replaces' ); }