-
Notifications
You must be signed in to change notification settings - Fork 138
/
lexinfo.t
95 lines (76 loc) · 1.74 KB
/
lexinfo.t
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!./parrot
# Copyright (C) 2006-2010, Parrot Foundation.
=head1 NAME
t/pmc/lexinfo.t - test LexInfo PMC
=head1 SYNOPSIS
% prove t/pmc/lexinfo.t
=head1 DESCRIPTION
Tests the LexInfo PMC.
=cut
.include 'except_types.pasm'
.sub main :main
.include 'test_more.pir'
plan(5)
inspect_test()
inspect_invalid_test()
declare_lex_preg_test()
.end
.sub inspect_test
.lex "$a", $P0
.lex "$b", $P1
$P2 = new 'ParrotInterpreter'
$P2 = $P2['sub']
$P2 = $P2.'get_lexinfo'()
$P2 = inspect $P2, 'symbols'
$I0 = elements $P2
is($I0, 2, "correct number of symbol in introspection hash")
.local int have_a, have_b
have_a = 0
have_b = 0
$S0 = $P2[0]
if $S0 != "$a" goto not_a_1
inc have_a
not_a_1:
if $S0 != "$b" goto not_b_1
inc have_b
not_b_1:
$S0 = $P2[1]
if $S0 != "$a" goto not_a_2
inc have_a
not_a_2:
if $S0 != "$b" goto not_b_2
inc have_b
not_b_2:
is(have_a, 1, "$a symbol was in list")
is(have_b, 1, "$b symbol was in list")
.end
.sub inspect_invalid_test
.local pmc li, in, ex
.local int r, type
li = new ['LexInfo']
r = 0
push_eh catch
in = inspect li, 'fubar'
goto done
catch:
.get_results(ex)
type = ex['type']
r = iseq type, .EXCEPTION_INVALID_OPERATION
done:
ok(r, 'invalid introspection key throws as expected')
.end
.sub declare_lex_preg_test
.const string preg_name = 'foo'
.const int preg_value = 42
.local pmc li
li = new ['LexInfo']
li.'declare_lex_preg'(preg_name, preg_value)
.local int r
r = li[preg_name]
is(r, preg_value, 'declare_lex_preg method')
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: