[1] | 1 | # Before `make install' is performed this script should be runnable with |
---|
| 2 | # `make test'. After `make install' it should work as `perl Text-FormBuilder.t' |
---|
| 3 | |
---|
| 4 | ######################### |
---|
| 5 | |
---|
[89] | 6 | ## use Test::More qw(no_plan); |
---|
| 7 | use Test::More tests => 11; |
---|
| 8 | |
---|
[9] | 9 | BEGIN { use_ok('Text::FormBuilder'); }; |
---|
| 10 | |
---|
| 11 | my $p = Text::FormBuilder->new; |
---|
| 12 | isa_ok($p, 'Text::FormBuilder', 'new parser'); |
---|
[53] | 13 | isa_ok($p, 'Class::ParseText::Base', 'subclass of Class::Parsetext::Base'); |
---|
| 14 | can_ok($p, qw(parse_file parse_array parse_text parse)); # inherited parse_* methods |
---|
| 15 | |
---|
[19] | 16 | isa_ok($p->parse_text('')->build->form, 'CGI::FormBuilder', 'generated CGI::FormBuilder object (build->form)'); |
---|
| 17 | isa_ok($p->parse_text('')->form, 'CGI::FormBuilder', 'generated CGI::FormBuilder object (form)'); |
---|
[9] | 18 | |
---|
[19] | 19 | $p = Text::FormBuilder->parse_text(''); |
---|
| 20 | isa_ok($p, 'Text::FormBuilder', 'new parser (from parse_text as class method)'); |
---|
| 21 | |
---|
| 22 | $p = Text::FormBuilder->parse(\''); |
---|
| 23 | isa_ok($p, 'Text::FormBuilder', 'new parser (from parse as class method)'); |
---|
| 24 | |
---|
[42] | 25 | |
---|
| 26 | my $simple = <<END; |
---|
| 27 | name |
---|
| 28 | email |
---|
| 29 | phone |
---|
| 30 | END |
---|
| 31 | |
---|
| 32 | my $form = $p->parse(\$simple)->form; |
---|
| 33 | # we should have three fields |
---|
| 34 | is(keys %{ $form->fields }, 3, 'correct number of fields'); |
---|
| 35 | |
---|
[88] | 36 | # create some additional parsers, to make sure we aren't sharing data |
---|
| 37 | my $p2 = Text::FormBuilder->parse_text($simple); |
---|
| 38 | is(keys %{ $p2->form->fields }, 3, 'correct number of fields from parse_text'); |
---|
| 39 | |
---|
| 40 | my $p3 = Text::FormBuilder->parse_array(qw(code title semester instructor)); |
---|
| 41 | is(keys %{ $p3->form->fields }, 4, 'correct number of fields from parse_array'); |
---|