X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=t%2F10-basic.t;h=c7b57c3b517a78fc250429df33c566499f22c0a1;hb=refs%2Ftags%2Fupstream%2F0.20;hp=162063cbc7b09900c9bf6ce2b0576b7033a2c4ab;hpb=7c69490596e221b9d4be4d94de939429258ff7b3;p=liburi-template-perl.git diff --git a/t/10-basic.t b/t/10-basic.t index 162063c..c7b57c3 100644 --- a/t/10-basic.t +++ b/t/10-basic.t @@ -1,16 +1,68 @@ use strict; use warnings; -use Test::More tests => 14; +use Test::More tests => 28; use_ok( 'URI::Template' ); +# new, empty template +{ + 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' ); + } +} + +# "0" as a template +{ + my $template = URI::Template->new( '0' ); + isa_ok( $template, 'URI::Template' ); + is( $template->template, '0', 'template() is "0"' ); + + { + my $result = $template->process(); + is( $result, '0', 'process() for "0" template' ); + isa_ok( $result, 'URI', 'return value from process() isa URI' ); + } + + # set template back to empty + $template->template( '' ); + is( $template->template, '', 'template() is empty' ); + + { + my $result = $template->process(); + is( $result, '', 'process() for new 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' ); @@ -37,7 +89,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' ); } { @@ -48,7 +100,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' ); }