File: assignment.t

package info (click to toggle)
libmakefile-dom-perl 0.004-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 616 kB
  • ctags: 535
  • sloc: perl: 6,552; makefile: 2
file content (75 lines) | stat: -rw-r--r-- 1,423 bytes parent folder | download | duplicates (5)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use lib 'inc';
use Test::Base;
use MDOM::Document::Gmake;

plan tests => 8 * blocks();

run {
    my $block = shift;
    my $name = $block->name;

    my $dom = MDOM::Document::Gmake->new(\$block->src);
    ok $dom, "DOM tree okay - $name";
    my $assign = $dom->child(0);

    ok $assign, "Assignment obj okay - $name";
    my @got_lhs = $assign->lhs;
    my @expected_lhs = eval $block->lhs;
    die "eval lhs failed ($name) - $@" if $@;
    is fmt(@got_lhs), fmt(@expected_lhs), "lhs array okay - $name";
    is
        join('', @{ scalar($assign->lhs) }),
        join('', @expected_lhs),
        "lhs calar okay - $name";

    ok $assign, "Assignment obj okay - $name";
    my @got_rhs = $assign->rhs;
    my @expected_rhs = eval $block->rhs;
    die "eval rhs failed ($name) - $@" if $@;
    is fmt(@got_rhs), fmt(@expected_rhs), "rhs array okay - $name";
    is
        join('', @{ scalar($assign->rhs) }),
        join('', @expected_rhs),
        "rhs calar okay - $name";

    is $assign->op, $block->op, "op okay - $name";

};

sub fmt {
    join ', ', map { "'$_'" } @_;
}

__DATA__

=== TEST 1:
--- src
a := 3
--- lhs
'a'
--- op: :=
--- rhs
'3'


=== TEST 2:
--- src
 foo bar=hello, world !  # this is a comment
--- lhs
'foo', ' ', 'bar'
--- op: =
--- rhs
'hello,', ' ', 'world', ' ', '!', '  '



=== TEST 3:
--- src
@D ?= hello \
	world!
--- lhs
'@D'
--- op: ?=
--- rhs
'hello', ' ', "\\\n", "\t", 'world!'