PageRenderTime 25ms CodeModel.GetById 1ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 0ms

/xt/params.t

http://github.com/gshank/html-formhandler
Unknown | 85 lines | 69 code | 16 blank | 0 comment | 0 complexity | 5e17d67dd7d7f2d1aabd88223e2360f3 MD5 | raw file
 1use Test::More tests => 6;
 2
 3use_ok( 'HTML::FormHandler::Params' );
 4
 5my $_params = HTML::FormHandler::Params->new;
 6
 7my $p1 = {
 8   'book.author' => 'J.Doe',
 9   'book.title' =>  'Doing something',
10   'book.date' => '2002',
11};
12
13my $p1_exp = $_params->expand_hash( $p1 );
14
15is_deeply( $p1_exp, { book => { author => 'J.Doe',
16                         title => 'Doing something',
17                         date => '2002' } }, 'get expanded has' );
18
19my $p2 = {
20   'books.0.author' => 'Jane Doe',
21   'books.0.title' => 'Janes Book',
22   'books.0.date' => '2003',
23   'books.1.author' => 'Miss Muffet',
24   'books.1.title' => 'Sitting on a Tuffet',
25   'books.1.date' => '2004'
26};
27
28my $p_hash = {
29   books => [
30      {  author => 'Jane Doe',
31         title  => 'Janes Book',
32         date   => '2003',
33      },
34      {
35         author => 'Miss Muffet',
36         title  => 'Sitting on a Tuffet',
37         date   => '2004',
38      }
39   ]
40};
41
42my $p2_exp = $_params->expand_hash( $p2 );
43is_deeply( $p2_exp, $p_hash, 'get expanded hash for dot notation' );
44
45my $p3 = {
46   'books+0+author' => 'Jane Doe',
47   'books+0+title' => 'Janes Book',
48   'books+0+date' => '2003',
49   'books+1+author' => 'Miss Muffet',
50   'books+1+title' => 'Sitting on a Tuffet',
51   'books+1+date' => '2004'
52};
53
54my $p3_exp = $_params->expand_hash( $p3, '+' );
55is_deeply( $p3_exp, $p_hash, 'get expanded hash for plus notation' );
56
57
58my $p4 = {
59   'books[0]author' => 'Jane Doe',
60   'books[0]title' => 'Janes Book',
61   'books[0]date' => '2003',
62   'books[1]author' => 'Miss Muffet',
63   'books[1]title' => 'Sitting on a Tuffet',
64   'books[1]date' => '2004'
65};
66
67my $p4_exp = $_params->expand_hash( $p4, '[]' );
68is_deeply( $p4_exp, $p_hash, 'get expanded hash for bracket notation' );
69
70my $p5 = {
71   'book.author' => 'Jane Doe',
72   'book.title' => 'Janes Book',
73   'book.date' => '2003',
74};
75
76my $p5_hash = {
77   book =>
78      {  author => 'Jane Doe',
79         title  => 'Janes Book',
80         date   => '2003',
81      },
82   };
83my $p5_exp = $_params->expand_hash( $p5 );
84is_deeply( $p5_exp, $p5_hash, 'get hash from single brackets');
85