Imported upstream version 0.12
[liburi-template-perl.git] / t / 20-deparse.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 11;
5
6 use_ok( 'URI::Template' );
7
8 {
9     my $template
10         = URI::Template->new( 'http://{domain}.com/{dir}/{file}.html' );
11     isa_ok( $template, 'URI::Template' );
12     my %result = $template->deparse( 'http://example.com/test/1.html' );
13     is_deeply( \%result, { domain => 'example', dir => 'test', file => '1' },
14         'deparse()' );
15 }
16
17 {
18     my $template = URI::Template->new( 'http://test.com/{x}/{y}/{x}/{y}' );
19     isa_ok( $template, 'URI::Template' );
20     my %result = $template->deparse( 'http://test.com/1/2/1/2' );
21     is_deeply(
22         \%result,
23         { x => 1, y => 2 },
24         'deparse() with multiple values'
25     );
26 }
27
28 {
29     my $template = URI::Template->new( 'http://ex.com/{x}' );
30     isa_ok( $template, 'URI::Template' );
31     my %input = ( x => 'y' );
32     my $uri = $template->process( x => 'y' );
33     is( $uri, 'http://ex.com/y' );
34     my %result = $template->deparse( $uri );
35     is_deeply( \%result, \%input, 'process => deparse' );
36 }
37
38 {
39     my $template = URI::Template->new( 'http://ex.com/{test}' );
40     isa_ok( $template, 'URI::Template' );
41     my %input = ( test => 'test' );
42     my $uri = $template->process( test => 'test' );
43     is( $uri, 'http://ex.com/test' );
44     my %result = $template->deparse( $uri );
45     is_deeply( \%result, \%input, 'process => deparse w/ multiple chars' );
46 }