4 | 4 |
Test suite for (Python implementations of) the Eightebed programming language.
|
5 | 5 |
"""
|
6 | 6 |
|
7 | |
import doctest
|
8 | |
|
9 | |
from .parser import parse, TypeError
|
10 | |
from .context import Context
|
11 | |
from .drivers import parse_and_check, load_and_go
|
12 | |
|
13 | 7 |
|
14 | 8 |
class Tests(object):
|
15 | 9 |
"""Class containing test cases for Eightebed.
|
16 | 10 |
|
|
11 |
>>> from .parser import parse, Eightebed
|
|
12 |
>>> from .drivers import parse_and_check, load_and_go
|
17 | 13 |
>>> p = parse(Tests.simple_ok)
|
18 | |
>>> print p
|
19 | |
Eightebed([], [VarDecl('jim', TypeInt())], Block([AssignStmt(VarRef('jim'), IntConst(4))]))
|
|
14 |
>>> isinstance(p, Eightebed)
|
|
15 |
True
|
|
16 |
>>> p.typedecls
|
|
17 |
[]
|
|
18 |
>>> p.vardecls
|
|
19 |
[VarDecl('jim', TypeInt())]
|
|
20 |
>>> p.block
|
|
21 |
Block([AssignStmt(VarRef('jim'), IntConst(4))])
|
20 | 22 |
>>> p = parse_and_check(Tests.simple_ok)
|
21 | 23 |
|
22 | 24 |
>>> parse_and_check(Tests.double_declaration)
|
|
68 | 70 |
|
69 | 71 |
>>> p = parse_and_check(Tests.allocated_values_initialized)
|
70 | 72 |
>>> load_and_go(p)
|
71 | |
0
|
|
73 |
'0 '
|
72 | 74 |
|
73 | 75 |
>>> p = parse_and_check(Tests.simple_arith)
|
74 | 76 |
>>> load_and_go(p)
|
75 | |
4
|
|
77 |
'4 '
|
76 | 78 |
|
77 | 79 |
>>> p = parse_and_check(Tests.loop_1)
|
78 | 80 |
>>> load_and_go(p)
|
79 | |
5 4 3 2 1
|
|
81 |
'5 4 3 2 1 '
|
80 | 82 |
|
81 | 83 |
>>> p = parse_and_check(Tests.allocating_loop)
|
82 | 84 |
>>> load_and_go(p)
|
|
85 |
''
|
83 | 86 |
|
84 | 87 |
>>> p = parse_and_check(Tests.free_invalidates)
|
85 | 88 |
>>> load_and_go(p)
|
86 | |
53
|
|
89 |
'53 '
|
87 | 90 |
|
88 | 91 |
>>> p = parse_and_check(Tests.alias_is_invalidated)
|
89 | 92 |
>>> load_and_go(p)
|
90 | |
100 99 98 97 96 95 94 93 92 91 90 89 88
|
|
93 |
'100 99 98 97 96 95 94 93 92 91 90 89 88 '
|
91 | 94 |
|
92 | 95 |
In principle, this test demonstrates that the memory freed by the
|
93 | 96 |
free command can be re-used by a subsequent malloc expression. Of
|
|
97 | 100 |
|
98 | 101 |
>>> p = parse_and_check(Tests.allocate_and_free_loop)
|
99 | 102 |
>>> load_and_go(p)
|
100 | |
50
|
|
103 |
'50 '
|
101 | 104 |
|
102 | 105 |
"""
|
103 | |
|
104 | 106 |
simple_ok = """\
|
105 | 107 |
var int jim;
|
106 | 108 |
{
|
|
162 | 164 |
ptr to node next;
|
163 | 165 |
};
|
164 | 166 |
var ptr to node jim;
|
165 | |
{
|
|
167 |
{
|
166 | 168 |
jim = malloc node;
|
167 | 169 |
print [@jim].value;
|
168 | 170 |
free jim;
|
|
226 | 228 |
};
|
227 | 229 |
var ptr to node jim;
|
228 | 230 |
var ptr to node nestor;
|
229 | |
{
|
|
231 |
{
|
230 | 232 |
jim = malloc node;
|
231 | 233 |
if valid jim {
|
232 | 234 |
print [@jim].value;
|