Debian Codegraph @

t/unit/Test2/Harness/Settings/Prefix.t

raw
1 use Test2::V0 -target => 'Test2::Harness::Settings::Prefix';
2
3 my $one = $CLASS->new();
4 isa_ok($one, [$CLASS], "Created an instance");
5 ref_ok($one, 'REF', "Hash is slightly obscured by an extra deref");
6
7 like(
8 dies { $one->foo },
9 qr/The 'foo' field does not exist/,
10 "Must use a valid field"
11 );
12
13 ref_ok($one->vivify_field('foo'), 'SCALAR', "vivify returns a ref");
14 is($one->foo, undef, "Not set yet");
15
16 $one->foo('bar');
17 is($one->foo, 'bar', "Set value");
18
19 if ("$]" >= 5.016) {
20 $one->foo = 'baz';
21 is($one->foo, 'baz', "Set via lvalue");
22 }
23 else {
24 $one->field(foo => 'baz');
25 }
26
27 is($one->field('foo'), 'baz', "Got via field");
28 $one->field('foo', 'xxx');
29 is($one->field('foo'), 'xxx', "Set via field");
30
31 like(
32 dies { $one->field('foo', 'bar', 'baz') },
33 qr/Too many arguments for field\(\)/,
34 "Field only takes 2 args"
35 );
36
37 like(
38 dies { $CLASS->foo },
39 qr/Method foo\(\) must be called on a blessed instance/,
40 "Autload does not work on class"
41 );
42
43 is(
44 $one->TO_JSON,
45 { foo => 'xxx' },
46 "JSON structure"
47 );
48
49 {
50 $INC{'TheThing.pm'} = 1;
51 package TheThing;
52 use Test2::Harness::Util::HashBase qw/foo bar/;
53 }
54
55 my $res = $one->build('TheThing', bar => 'yyy');
56 isa_ok($res, ['TheThing'], "Created an instance");
57 is(
58 $res,
59 {
60 foo => 'xxx',
61 bar => 'yyy',
62 },
63 "Created with args"
64 );
65
66 done_testing;