git @ Cat's Eye Technologies Eightebed / 84f7c9c
pep8-ify & pyflakes-ify tests.py. catseye 13 years ago
2 changed file(s) with 22 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
7979 file = open("tmp.c", "w")
8080 ast.emit(file, options)
8181 file.close()
82 sys.stdout.write(compile_and_run("tmp.c", options))
82 return compile_and_run("tmp.c", options)
8383
8484
8585 def cmdline(options):
9494 break
9595 try:
9696 ast = parse_and_check(cmd, options=options)
97 load_and_go(ast, options)
97 result = load_and_go(ast, options=options)
98 sys.stdout.write(result)
9899 except Exception, e:
99100 print "Exception!", repr(e)
44 Test suite for (Python implementations of) the Eightebed programming language.
55 """
66
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
137
148 class Tests(object):
159 """Class containing test cases for Eightebed.
1610
11 >>> from .parser import parse, Eightebed
12 >>> from .drivers import parse_and_check, load_and_go
1713 >>> 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))])
2022 >>> p = parse_and_check(Tests.simple_ok)
2123
2224 >>> parse_and_check(Tests.double_declaration)
6870
6971 >>> p = parse_and_check(Tests.allocated_values_initialized)
7072 >>> load_and_go(p)
71 0
73 '0 '
7274
7375 >>> p = parse_and_check(Tests.simple_arith)
7476 >>> load_and_go(p)
75 4
77 '4 '
7678
7779 >>> p = parse_and_check(Tests.loop_1)
7880 >>> load_and_go(p)
79 5 4 3 2 1
81 '5 4 3 2 1 '
8082
8183 >>> p = parse_and_check(Tests.allocating_loop)
8284 >>> load_and_go(p)
85 ''
8386
8487 >>> p = parse_and_check(Tests.free_invalidates)
8588 >>> load_and_go(p)
86 53
89 '53 '
8790
8891 >>> p = parse_and_check(Tests.alias_is_invalidated)
8992 >>> 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 '
9194
9295 In principle, this test demonstrates that the memory freed by the
9396 free command can be re-used by a subsequent malloc expression. Of
97100
98101 >>> p = parse_and_check(Tests.allocate_and_free_loop)
99102 >>> load_and_go(p)
100 50
103 '50 '
101104
102105 """
103
104106 simple_ok = """\
105107 var int jim;
106108 {
162164 ptr to node next;
163165 };
164166 var ptr to node jim;
165 {
167 {
166168 jim = malloc node;
167169 print [@jim].value;
168170 free jim;
226228 };
227229 var ptr to node jim;
228230 var ptr to node nestor;
229 {
231 {
230232 jim = malloc node;
231233 if valid jim {
232234 print [@jim].value;