/
integration_test.rb
117 lines (96 loc) · 1.69 KB
/
integration_test.rb
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
require 'test_helper'
class NoscriptTest < MiniTest::Unit::TestCase
def test_hello_world
output = `./bin/noscript examples/hello_world.ns`.split("\n")
assert_equal [
"Negative johnny is",
"-4000",
"43",
"760",
"111",
"cool!",
"bar",
"baz",
"Johnny is still",
"4000",
"lord",
"hello world",
], output
end
def test_objects
output = `./bin/noscript examples/objects.ns`.split("\n")
assert_equal [
"running!",
"10",
"vroom",
"99",
], output
end
def test_traits
output = `./bin/noscript examples/traits.ns`.split("\n")
assert_equal [
"John is running with traits at speed 10",
], output
end
def test_conditionals
[
"""
foo = 3
if foo != 91
'ok'
end
""",
"""
foo = 3
if foo > 2
'ok'
else
'ko'
end
""",
"""
foo = 3
if foo < 2
'ko'
else
'ok'
end
""",
"""
foo = 3
if foo <= 3
'ok'
else
'ko'
end
""",
"""
foo = 4
if foo >= 3
'ok'
else
'ko'
end
"""
].each do |code|
compiles(code) do |retval|
assert_equal Noscript::AST::String.new('ok'), retval
end
end
end
def test_while
[
"""
foo = 3
while foo > 0
foo = foo - 1
end
foo
"""
].each do |code|
compiles(code) do |retval|
assert_equal Noscript::AST::Integer.new(0), retval
end
end
end
end