File: 90rt150958.t

package info (click to toggle)
libstruct-dumb-perl 0.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 160 kB
  • sloc: perl: 468; makefile: 2
file content (54 lines) | stat: -rw-r--r-- 1,111 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;

use Scalar::Util qw( refaddr );

use Struct::Dumb;

# Check that we can use field names that aren't valid as Perl identifiers

# positional
{
   struct WithDot => [qw( bla.foo )];

   my $val = WithDot( "the value" );

   my $meth = "bla.foo";
   is( $val->$meth, "the value", 'Accessor of instance created with positional constructor' );
}

# leading digits in field names
{
   struct WithDigit => [qw( 1 2 3 )];

   my $val = WithDigit( 4, 5, 6 );

   my $meth = "1";
   is( $val->$meth, 4, 'Accessor of instance with single-digit field names' );
}

# quote symbols in field names
{
   struct WithQuotes => [qw( abc "abc" )];

   my $val = WithQuotes( "first", "second" );

   my $meth = q("abc");
   is( $val->$meth, "second", 'Accessor of instance with quotes on field names' );
}

# named
{
   struct WithDotNamed => [qw( bla.foo )], named_constructor => 1;

   my $val = WithDotNamed( 'bla.foo' => "the value" );

   my $meth = "bla.foo";
   is( $val->$meth, "the value", 'Accessor of instance created with named constructor' );
}

done_testing;