File: 02-qast.t

package info (click to toggle)
nqp 2014.07-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 23,596 kB
  • ctags: 7,993
  • sloc: ansic: 22,689; java: 20,240; cpp: 4,956; asm: 3,976; perl: 950; python: 267; sh: 245; makefile: 14
file content (67 lines) | stat: -rw-r--r-- 1,433 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
55
56
57
58
59
60
61
62
63
64
65
66
67
use QAST;

plan(5);

# Following a test infrastructure.
sub compile_qast($qast) {
    my $*QAST_BLOCK_NO_CLOSE := 1;
    nqp::getcomp('nqp').compile($qast, :from('ast'));
}
sub is_qast($qast, $value, $desc) {
    try {
        my $code := compile_qast($qast);
        ok($code() eq $value, $desc);
        CATCH { ok(0, $desc) }
    }
}

is_qast(
    QAST::Block.new(
        QAST::VM.new(
            parrot => QAST::IVal.new( :value(42) ),
            unknown => QAST::IVal.new( :value(69) )
        )
    ),
    42,
    'QAST::VM picks parrot alternative and ignores others');

is_qast(
    QAST::Block.new(
        QAST::VM.new(
            pir => ".return ('Leffe')",
        ),
        QAST::SVal.new( :value('Fosters') )
    ),
    'Leffe',
    'QAST::VM with pir works');

is_qast(
    QAST::Block.new(
        QAST::VM.new(
            pir => "%r = box 'set'",
        )
    ),
    'set',
    'QAST::VM with pir and %r works');

is_qast(
    QAST::Block.new(
        QAST::VM.new(
            pirop => 'add__Iii',
            QAST::IVal.new( :value(15) ),
            QAST::IVal.new( :value(10) )
        )
    ),
    25,
    'QAST::VM with pirop and signature after __');

is_qast(
    QAST::Block.new(
        QAST::VM.new(
            pirop => 'add Iii',
            QAST::IVal.new( :value(15) ),
            QAST::IVal.new( :value(100) )
        )
    ),
    115,
    'QAST::VM with pirop and signature after a space');