File: hashref_escaping.t

package info (click to toggle)
libhtml-formfu-perl 0.09007-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,184 kB
  • sloc: perl: 13,186; makefile: 9; sql: 5
file content (70 lines) | stat: -rw-r--r-- 1,851 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use strict;
use warnings;

use Test::More tests => 8;

use HTML::FormFu;
use HTML::FormFu::Model::HashRef;

my %test = (
    'name_2'       => 'name_2',
    'name_bar_foo' => 'name\\_bar\\_foo',
    'name_2_bar'   => 'name\\_2\\_bar',
    'name_2.bar'   => 'name_2.bar'
);

while ( my ( $k, $v ) = each %test ) {
    is( HTML::FormFu::Model::HashRef::_escape_name($k), $v );
}

is( HTML::FormFu::Model::HashRef::_unescape_name('foo\\_bar'), 'foo_bar' );

is_deeply(
    HTML::FormFu::Model::HashRef::_escape_hash(
        {
            'name_2'       => 'foo',
            'name_bar_foo' => 'bar',
            'name_2_bar'   => 'baz',
            'name_2.bar'   => { 'bas_z' => 1 },
            'bar_z'        => [ { foo_w => 1, foo_2 => 2 } ],
        }
    ),
    {
        'name_2'           => 'foo',
        'name\\_bar\\_foo' => 'bar',
        'name\\_2\\_bar'   => 'baz',
        'name_2.bar'       => { 'bas\\_z' => 1 },
        'bar\\_z'          => [ { 'foo\\_w' => 1, foo_2 => 2 } ]
    }
);

is_deeply(
    HTML::FormFu::Model::HashRef::_unescape_hash(
        {
            'name_2'           => 'foo',
            'name\\_bar\\_foo' => 'bar',
            'name\\_2\\_bar'   => 'baz',
            'name_2.bar'       => { 'bas\\_z' => 1 },
            'bar\\_z'          => [ { 'foo\\_w' => 1, foo_2 => 2 } ]

        }
    ),
    {
        'name_2'       => 'foo',
        'name_bar_foo' => 'bar',
        'name_2_bar'   => 'baz',
        'name_2.bar'   => { 'bas_z' => 1 },
        'bar_z'        => [ { foo_w => 1, foo_2 => 2 } ],
    }
);

my $form = HTML::FormFu->new;
$form->populate(
    {
        elements =>
          [ { name => 'foo' }, { name => 'bar' }, { name => 'foo_bar' } ]
    }
);
$form->process( { foo => 1, bar => 2, foo_bar => 3 } );

is_deeply($form->model('HashRef')->create, { foo => 1, bar => 2, foo_bar => 3 });