4 use Test::More tests => 14;
6 use_ok( 'URI::Template' );
9 my $text = 'http://foo.com/{bar}/{baz}?q=%7B';
10 my $template = URI::Template->new( $text );
11 isa_ok( $template, 'URI::Template' );
12 is_deeply( [ sort $template->variables ], [ qw( bar baz ) ], 'variables()' );
13 is( "$template", $text, 'as_string()' );
16 my $result = $template->process( bar => 'x', baz => 'y' );
17 is( $result, 'http://foo.com/x/y?q=%7B', 'process()' );
18 isa_ok( $result, 'URI', 'return value from process() isa URI' );
21 my $result = $template->process_to_string( bar => 'x', baz => 'y' );
22 is( $result, 'http://foo.com/x/y?q=%7B', 'process_to_string()' );
23 ok( !ref $result, 'result is not a ref' );
28 my $template = URI::Template->new( 'http://foo.com/{z(}/' );
29 my $result = $template->process( 'z(' => 'x' );
30 is( $result, 'http://foo.com/x/', 'potential regex issue escaped' );
34 my $template = URI::Template->new( 'http://foo.com/{z}/' );
36 my $result = $template->process( 'z' => '{x}' );
37 is( $result, 'http://foo.com/%7Bx%7D/', 'values are uri escaped' );
40 my $result = $template->process( );
41 is( $result, 'http://foo.com//', 'no value sent' );
44 my $result = $template->process( 'y' => '1' );
45 is( $result, 'http://foo.com//', 'no valid keys used' );
50 my $template = URI::Template->new( 'http://foo.com/{z}/{z}/' );
51 is_deeply( [ $template->variables ], [ 'z' ], 'unique vars' );
52 my $result = $template->process( 'z' => 'x' );
53 is( $result, 'http://foo.com/x/x/', 'multiple replaces' );