File: Object.t

package info (click to toggle)
libmock-quick-perl 1.111-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 200 kB
  • sloc: perl: 1,014; makefile: 2
file content (49 lines) | stat: -r--r--r-- 1,011 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
44
45
46
47
48
49
#!/usr/bin/perl
use strict;
use warnings;

use Test::More;
use Fennec::Lite;
use Mock::Quick::Method;

our $CLASS;

BEGIN {
    $CLASS = 'Mock::Quick::Object';
    use_ok( $CLASS );
}

tests get_set => sub {
    my $obj = $CLASS->new( foo => 'bar' );

    ok( $obj->can('zed'), "can do random sub" );

    is( $obj->foo(), 'bar', "have property" );

    ok( !$obj->baz(), "No property set" );
    is( $obj->baz( 1 ), 1, "setting property" );
    is( $obj->baz(), 1, "Stored value" );
};

tests methods => sub {
    my @args;
    my $obj = $CLASS->new(
        foo => Mock::Quick::Method->new( sub {
            @args = @_;
            return "foo was called";
        }),
    );

    is( $obj->foo( qw/bar baz/ ), "foo was called", "called virtualmethod" );
    is_deeply(
        \@args,
        [ $obj, qw/bar baz/ ],
        "Correct arguments",
    );

    is( $obj->foo( \$Mock::Quick::Util::CLEAR ), undef, "clearing method" );
    is( $obj->foo(), undef, "cleared method" );
};

run_tests;
done_testing;