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