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