From: Jarkko Hietaniemi Date: Sun, 27 Apr 2003 07:38:17 +0000 (+0000) Subject: Add Dave Mitchell's test case for fields. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0ea4badca0069846e0da75feed0fdb587e8fc275;p=p5sagit%2Fp5-mst-13.2.git Add Dave Mitchell's test case for fields. p4raw-id: //depot/perl@19350 --- diff --git a/lib/fields.t b/lib/fields.t index c4d5ef6..dee9447 100755 --- a/lib/fields.t +++ b/lib/fields.t @@ -93,8 +93,10 @@ my %expect = ( 'Foo::Bar::Baz' => 'b1:1,b2:2,b3:3,foo:4,bar:5,baz:6', ); -plan tests => keys(%expect) + 17; +plan tests => keys(%expect) + 21; + my $testno = 0; + while (my($class, $exp) = each %expect) { no strict 'refs'; my $fstr = fstr(\%{$class."::FIELDS"}); @@ -213,3 +215,25 @@ package Test::Version3; use base qw(Has::Version_0); ::is( $Has::Version_0::VERSION, 0, '$VERSION==0 preserved' ); +package Test::FooBar; + +use fields qw(a b c); + +sub new { + my $self = fields::new(shift); + %$self = @_ if @_; + $self; +} + +package main; + +{ + my $x = Test::FooBar->new( a => 1, b => 2); + + is(ref $x, 'Test::FooBar', 'x is a Test::FooBar'); + ok(exists $x->{a}, 'x has a'); + ok(exists $x->{b}, 'x has b'); + is(scalar keys %$x, 2, 'x has two fields'); +} + +