File: objects.t

package info (click to toggle)
libreturn-value-perl 1.302-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 116 kB
  • ctags: 13
  • sloc: perl: 87; makefile: 45
file content (43 lines) | stat: -rw-r--r-- 1,297 bytes parent folder | download | duplicates (3)
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
use Test::More tests => 24;
use strict;
$^W = 1;

use_ok 'Return::Value';

my $ret = Return::Value->new;
isa_ok $ret, 'Return::Value';
ok ! $ret->bool, 'false';
is $ret->errno, undef, 'errno 0';
is $ret->string, "", 'empty string';
ok ! $ret->data, 'no data';
is scalar(keys %{$ret->prop}), 0, 'no properties';

$ret = Return::Value->new(
    type   => 'success',
    errno  => 128,
    string => 'string',
    data   => [ 'one' ],
    prop   => { one => 1 },
);

isa_ok $ret, 'Return::Value';
ok $ret->bool, 'true';
is $ret->errno, 128, 'errno 128';
is $ret->errno(undef), undef, 'errno undef';
is $ret->errno,        undef, 'errno still undef';
is $ret->string, 'string', 'string is string';
is ref($ret->data), 'ARRAY', 'data array ref';
is scalar(@{$ret->data}), 1, 'one element in data';
is ref($ret->prop), 'HASH', 'hash in prop';
is $ret->prop->{one}, 1, 'one prop set';

$ret->type('failure');
ok ! $ret->bool, 'now false';
is $ret->prop('one'), 1, 'object access for one';
is $ret->prop(two => 2), 2, 'prop create for two';
is $ret->errno(10), 10, 'set errno with method';
is $ret->type(), 'failure', 'type is currently failure';
is $ret->type("success"), 'success', 'set type with method';

eval { $ret->type("top secret"); };
like($@, qr/invalid result type/, "death on unknown type");