#!/usr/local/bin/perl -w
=head1 NAME
00p4form.t - Testing of p4 form parsing.
=cut
use strict;
use Carp;
use Test qw( plan skip );
use VCP::Utils::p4;
eval "use Test::Differences";
sub ok {
goto &eq_or_diff if defined &eq_or_diff;
goto &Test::ok;
}
my $f = <<END_OF_FORM;
# comment 1
Foo: Bar
Biz: Baz
Block:
Tackle
Offense
# comment 2
# comment 3
END_OF_FORM
my @f;
my %f;
## It's a mix in, but we don't need that since we're not testing the
## forms of these methods that invoce the p4 command.
my $p4 = bless {}, "VCP::Utils::p4";
my @tests = (
sub {
%f = @f = $p4->parse_p4_form( $f );
ok 0+@f, 10, "names+values from form";
},
sub { ok $f{Foo}, "Bar" },
sub { ok $f{Biz}, "Baz" },
sub { ok $f{Block}, "Tackle\nOffense" },
sub { ok $f{"#"}, "comment 2\ncomment 3" },
sub {
return skip "skipped: need Test::Differences", 1 unless defined &eq_or_diff;
( my $f2 = $f ) =~ s/\n\n+/\n/g;
my @f2 = $p4->parse_p4_form( $f2 );
eq_or_diff( \@f2, \@f );
},
sub {
my $fout = $p4->build_p4_form( @f );
ok $fout, $f;
},
) ;
plan tests => scalar( @tests ) ;
$_->() for @tests ;