source: text-formbuilder/trunk/t/Text-FormBuilder.t @ 88

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

BUGFIX: stopped crosstalk of data from one object to another (references were getting shared in the parser grammar code)

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