source: text-formbuilder/trunk/t/01-field.t @ 76

Last change on this file since 76 was 76, checked in by peichman, 19 years ago

added more test scripts, including pod coverage test

File size: 3.4 KB
Line 
1use strict;
2
3use Test::More qw(no_plan); #tests => 6;
4BEGIN { use_ok('Text::FormBuilder::Parser'); };
5
6my $p = Text::FormBuilder::Parser->new;
7
8# this is the minimal hash that is returned with every field that is parsed
9my %base = (
10    comment  => undef,
11    growable => undef,
12    label    => undef,
13    list     => undef,
14    name     => undef,
15    other    => undef,
16    required => undef,
17    type     => undef,
18    validate => undef,
19    value    => undef,
20);
21
22my @test_fields = (
23    {
24        comment => 'just the name of the field',
25        fieldspec => 'name',
26        expecting => { name => 'name' },
27    },
28    {
29        comment => 'different single word label',
30        fieldspec => 'name|Moniker',
31        expecting => {
32            name => 'name',
33            label => 'Moniker',
34        },
35    },
36    {
37        comment => 'multi-word label',
38        fieldspec => 'name|Full name',
39        expecting => {
40            name => 'name',
41            label => 'Full name',
42        },
43    },
44    {
45        comment => 'quoted label',
46        fieldspec => "name|'Name/nickname'",
47        expecting => {
48            name => 'name',
49            label => 'Name/nickname',
50        },
51    },
52    {
53        comment => 'quoted label with \ escapes',
54        fieldspec => "name|'Your \\'name\\''",
55        expecting => {
56            name => 'name',
57            label => "Your 'name'",
58        },
59    },
60
61    # field types
62    {
63        comment => 'field type "text"',
64        fieldspec => 'name:text',
65        expecting => {
66            name => 'name',
67            type => 'text',
68        },
69    },
70    {
71        comment => 'field type "textarea"',
72        fieldspec => 'name:textarea',
73        expecting => {
74            name => 'name',
75            type => 'textarea',
76        },
77    },
78    {
79        comment => 'field type "password"',
80        fieldspec => 'name:password',
81        expecting => {
82            name => 'name',
83            type => 'password',
84        },
85    },
86    {
87        comment => 'field type "checkbox"',
88        fieldspec => 'name:checkbox',
89        expecting => {
90            name => 'name',
91            type => 'checkbox',
92        },
93    },
94    {
95        comment => 'field type "radio"',
96        fieldspec => 'name:radio',
97        expecting => {
98            name => 'name',
99            type => 'radio',
100        },
101    },
102    {
103        comment => 'field type "select"',
104        fieldspec => 'name:select',
105        expecting => {
106            name => 'name',
107            type => 'select',
108        },
109    },
110
111
112    {
113        comment => 'text field with size',
114        fieldspec => 'name[25]:text',
115        expecting => {
116            name => 'name',
117            type => 'text',
118            size => 25,
119        },
120    },
121    {
122        comment => 'text field with size and maxlength',
123        fieldspec => 'name[25!]:text',
124        expecting => {
125            name => 'name',
126            type => 'text',
127            size => 25,
128            maxlength => 25,
129        },
130    },
131    {
132        comment => 'textarea field with size (rows and columns)',
133        fieldspec => 'name[4,40]:textarea',
134        expecting => {
135            name => 'name',
136            type => 'textarea',
137            rows => 4,
138            cols => 40,
139        },
140    },
141
142);
143
144foreach (@test_fields) {
145    my $field = $p->field($_->{fieldspec});
146    ok(eq_hash($field, { %base, %{ $_->{expecting} } }), $_->{comment});
147}
Note: See TracBrowser for help on using the repository browser.