forked from pannous/english-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloop_test.rb
executable file
·98 lines (83 loc) · 2.45 KB
/
loop_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
#!/usr/bin/env ruby
# encoding: utf-8
$use_tree=false
# $use_tree=true
require_relative '../parser_test_helper'
class LoopTest < ParserBaseTest
include ParserTestHelper
def _test_forever # OK ;{TRUST ME;}
init 'beep forever'
loops
parse 'beep forever' # OK ;{TRUST ME;}
end
def test_while_return
assert_equals parse('c=0;while c<1:c++;beep;done'), "beeped"
end
# def test_repeat_while #todo
# parse 'x=0;repeat while x<4: x++'
# assert_equals variables["x"], 4
# parse 'repeat x++ while x<4'
# assert_equals variables["x"], 4
# parse 'repeat x++ until x>4'
# assert_equals variables["x"], 5
# end
def test_while_loop
parse 'c=0;while c<3:c++;beep;done'
assert variables["c"]==3
end
def test_expressions
#s "counter=0"
#setter
parse 'counter=1'
#counter=@variables['counter']
#@variables['counter']=1
#parse "counter+1"
#r=expression0
assert(@variableValues['counter']==1)
parse 'counter++'
#r=expression0
assert(@variableValues['counter']==2)
#@variables['counter']=2
parse 'counter+=1'
#r=plusEqual
#r=expression0
assert(@variableValues['counter']==3)
parse 'counter=counter+counter'
#r=setter
#r=algebra
#r=expression0
counter=@variableValues['counter']
assert counter==6
end
def test_repeat # NEEEEDS blocks!! Parser.new(block)
parse "counter =0; repeat three times: increase the counter; okay"
assert "counter=3"
assert_equals @variableValues['counter'], 3
# assert_equals @variables[:counter],3
#s "counter=counter+1;"
#@interpret=false
#action
#@interpret=true
end
def test_repeat3
assert_result_is 'counter =0; repeat three times: counter=counter+1; okay',3
# parse 'counter =0; repeat three times: counter=counter+1; okay'
# assert 'counter =3' #if $use_tree # counter=counter+1 not repeatable as string
assert_result_is 'counter =0; repeat while counter < 3: counter=counter+1; okay',3
end
def test_repeat1
# @parser.verbose=true
parse 'counter =0; repeat three times: counter+=1; okay'
assert 'counter =3'
parse 'counter =0; repeat three times: counter++; okay'
counter=@variableValues['counter']
assert 'counter =3'
assert counter ==3
#parse "counter =0; repeat three times: increase the counter by two; okay"
#assert "counter =10"
end
def _test_forever # OK ;{TRUST ME;}
@parser.s 'beep forever'
@parser.loops
end
end