diff options
Diffstat (limited to 't/01point.t')
-rw-r--r-- | t/01point.t | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/t/01point.t b/t/01point.t new file mode 100644 index 0000000..2e95949 --- /dev/null +++ b/t/01point.t @@ -0,0 +1,31 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More; +use Test::Fatal; + +use Struct::Dumb; + +struct Point => [qw( x y )]; + +my $point = Point(10, 20); +ok( ref $point, '$point is a ref' ); + +can_ok( $point, "x" ); + +is( $point->x, 10, '$point->x is 10' ); + +$point->y = 30; +is( $point->y, 30, '$point->y is 30 after mutation' ); + +like( exception { $point->z }, + qr/^main::Point does not have a 'z' field at \S+ line \d+\.?\n/, + '$point->z throws exception' ); + +like( exception { Point(30) }, + qr/^usage: main::Point\(\$x, \$y\) at \S+ line \d+\.?\n/, + 'Point(30) throws usage exception' ); + +done_testing; |