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');
|