forked from pannous/english-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_test.rb
executable file
·216 lines (178 loc) · 4.85 KB
/
string_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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/usr/bin/env ruby
$use_tree=false
# $use_tree=true
$verbose =false
require_relative '../parser_test_helper'
class StringTest < ParserBaseTest
include ParserTestHelper
def test_string_methods
parse "invert 'hi'"
assert_equals @result, "ih"
end
def test_nth_word
assert "3rd word in 'hi my friend !!!' is 'friend'"
end
def _test_advanced_string_methods
parse "x='hi' inverted"
assert @result=="ih"
assert(@variableValues['x']== 'ih');
end
def _test_select_character
assert "first character of 'hi' is 'h'"
assert "second character of 'hi' is 'i'"
assert "last character of 'hi' is 'i'"
end
def _test_select_word
assert "first word of 'hi you' is 'hi'"
assert "second word of 'hi you' is 'you'"
assert "last word of 'hi you' is 'you'"
end
def test_gerunds
init "gerunding"
init "gerunded"
x
end
def test_concatenation
@parser.do_interpret!
parse "x is 'Hi'; y is 'World';z is x plus y"
assert_equals variables["z"], 'HiWorld'
end
def test_concatenation_b
init "x is 'hi'"
@parser.setter
assert(variables['x']== 'hi');
init "x + ' world'"
assert_equals r,"hi world"
#statement
# @parser.root
parse "x + ' world'"
assert_equals result,"hi world"
parse "y is ' world'"
parse "z is x + y"
assert_equals(variables['z'],'hi world');
parse "y is ' you'
z is x + y"
assert_equals(variables['z'],'hi you');
end
def test_concatenation_b
init "x is 'hi'"
@parser.setter
assert(variables['x']== 'hi');
init "x + ' world'"
assert_equals r,"hi world"
#statement
# @parser.root
parse "x + ' world'"
assert_equals result,"hi world"
parse "y is ' world'"
parse "z is x + y"
assert_equals(variables['z'],'hi world');
end
def test_concatenation_c
parse "x is 'hi'"
parse "y is ' you'"
parse "z is x + y"
# parse "y is ' you';
# z is x + y"
assert_equals(variables['z'],'hi you');
end
def test_newline_statements
parse "x is 'hi';
z='ho'"
assert_equals(variables['z'],'ho');
end
def test_concatenation_c3
parse "x is 'hi'"
parse "y is ' you';z is x + y"
assert_equals(variables['z'],'hi you');
end
def DONT_test_concatenation_by_and
parse("z = x and y");
assert(variables['z']== 'hi world');
assert("x and y == 'hi world'");
parse "z is x and ' ' and y"
assert("type of z is string or list")
end
def dont_test_list_concatenation
# 'abc' == 'a' 'b' 'c'
# really ? or 'a' 'b' 'c' == ['a','b','c'] ??
# really ? or 'a' 'b' 'c' == 'a b c' ??
init "'hi' ' ' 'world'"
assert_equals z, 'hi world'
variables['x']='hi'
variables['y']='world'
init "z=x ' ' y"
# assert [email protected] #todo ooo
assert_equals z, 'hi world'
parse "x is 'hi'; y is 'world';z is x ' ' y"
assert("type of z is string or type of z is list")
assert("type of z is string or list")
assert_equals variables["z"], 'hi world' #NICE TODO!
assert("z is 'hi world' OR z is 'hi',' ','world'");
end
def test_concatenation2
parse "x is 'hi'; y = ' world'"
assert_equals(parse("x + y"), "hi world");
assert("x plus y == 'hi world'");
end
def test_concatenation2b
assert_equals(parse("'hi'+ ' '+'world'"),'hi world');
assert_result_is("'hi'+ ' '+'world'","'hi world'");
parse "x is 'hi'; y is 'world';z is x plus ' ' plus y"
assert_equals variables["z"], 'hi world'
assert("z is 'hi world'");
end
def test_type
parse "x='hi'"
assert_result_is "type of x", String
assert "type of x is string"
end
def test_type3
parse "x be 'hello world';"
# assert variables['y']==String
assert("x is a string")
assert("type of x is string")
assert("class of x is string")
assert("kind of x is string")
parse "y= class of x"
assert variables['y']==Quote
assert("y is string")
parse "y is type of x"
assert("y is string")
end
def test_type1
init "class of 'hi'"
@parser.evaluate_property
assert_equals result, Quote
# assert_equals result,String todo!
init "class of 'hi'"
@parser.expressions
assert_equals result, Quote
# assert_equals result,String
parse "class of 'hi'"
assert_equals result, Quote
# assert result==String
end
def test_type2
parse "x='hi';
class of x"
parse "x='hi';class of x"
assert_equals result, Quote
# assert result==String
end
def test_result
parse "x be 'hello world';show x;x; class of x"
assert("type of x is string")
assert("class of x is string")
#assert("kind of x is string")
parse "y is type of x"
assert("y is string")
end
end