X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=t%2F10-basic.t;h=70514c700a4884fffb1e5bd638d5441cf103e920;hb=bf23e788f027c454711a8421b44945acbb2443b8;hp=4d6f404c8ddcf8d812dbb7149d26a1d6e408109b;hpb=1d94fcb2781945132b9a29e93744b6c168e647aa;p=liburi-template-perl.git diff --git a/t/10-basic.t b/t/10-basic.t index 4d6f404..70514c7 100644 --- a/t/10-basic.t +++ b/t/10-basic.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 21; +use Test::More tests => 28; use_ok( 'URI::Template' ); @@ -17,6 +17,29 @@ use_ok( 'URI::Template' ); } } +# "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; @@ -35,20 +58,20 @@ use_ok( 'URI::Template' ); } { - my $text = 'http://foo.com/{bar}/{baz}?q=%7B'; + my $text = 'http://foo.com/{bar}/{baz}?{foo}=%7B&{abr}=1'; my $template = URI::Template->new( $text ); isa_ok( $template, 'URI::Template' ); - is_deeply( [ sort $template->variables ], [ 'bar', 'baz' ], 'variables()' ); + is_deeply( [ $template->variables ], [ 'bar', 'baz', 'foo', 'abr' ], 'variables() in order of appearance' ); is( "$template", $text, 'stringify' ); { - my $result = $template->process( bar => 'x', baz => 'y' ); - is( $result, 'http://foo.com/x/y?q=%7B', 'process()' ); + my $result = $template->process( bar => 'x', baz => 'y', foo => 'b', abr => 'a' ); + is( $result, 'http://foo.com/x/y?b=%7B&a=1', 'process()' ); isa_ok( $result, 'URI', 'return value from process() isa URI' ); } { - my $result = $template->process_to_string( bar => 'x', baz => 'y' ); - is( $result, 'http://foo.com/x/y?q=%7B', 'process_to_string()' ); + my $result = $template->process_to_string( bar => 'x', baz => 'y', foo => 'b', abr => 'a' ); + is( $result, 'http://foo.com/x/y?b=%7B&a=1', 'process_to_string()' ); ok( !ref $result, 'result is not a ref' ); } }