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
217
218
|
##
# Literals ISO Test
assert('Literals Numerical', '8.7.6.2') do
# signed and unsigned integer
1 == 1 and -1 == -1 and +1 == +1 and
# signed and unsigned float
1.0 == 1.0 and -1.0 == -1.0 and
# binary
0b10000000 == 128 and 0B10000000 == 128
# octal
0o10 == 8 and 0O10 == 8 and 0_10 == 8
# hex
0xff == 255 and 0Xff == 255 and
# decimal
0d999 == 999 and 0D999 == 999 and
# decimal seperator
10_000_000 == 10000000 and 1_0 == 10 and
# integer with exponent
1e1 == 10.0 and 1e-1 == 0.1 and 1e+1 == 10.0
# float with exponent
1.0e1 == 10.0 and 1.0e-1 == 0.1 and 1.0e+1 == 10.0
end
assert('Literals Strings Single Quoted', '8.7.6.3.2') do
'abc' == 'abc' and '\'' == '\'' and '\\' == '\\'
end
assert('Literals Strings Double Quoted', '8.7.6.3.3') do
a = "abc"
"abc" == "abc" and "\"" == "\"" and "\\" == "\\" and
"#{a}" == "abc"
end
assert('Literals Strings Quoted Non-Expanded', '8.7.6.3.4') do
a = %q{abc}
b = %q(abc)
c = %q[abc]
d = %q<abc>
e = %q/abc/
f = %q/ab\/c/
g = %q{#{a}}
a == 'abc' and b == 'abc' and c == 'abc' and d == 'abc' and
e == 'abc' and f == 'ab/c' and g == '#{a}'
end
assert('Literals Strings Quoted Expanded', '8.7.6.3.5') do
a = %Q{abc}
b = %Q(abc)
c = %Q[abc]
d = %Q<abc>
e = %Q/abc/
f = %Q/ab\/c/
g = %Q{#{a}}
a == 'abc' and b == 'abc' and c == 'abc' and d == 'abc' and
e == 'abc' and f == 'ab/c' and g == 'abc'
end
assert('Literals Strings Here documents', '8.7.6.3.6') do
a = <<AAA
aaa
AAA
b = <<b_b
bbb
b_b
c = [<<CCC1, <<"CCC2", <<'CCC3']
c1
CCC1
c 2
CCC2
c 3
CCC3
d = <<DDD
d#{1+2}DDD
d\t
DDD\n
DDD
e = <<'EEE'
e#{1+2}EEE
e\t
EEE\n
EEE
f = <<"FFF"
F
FF#{"f"}FFF
F
FFF
g = <<-GGG
ggg
GGG
h = <<-"HHH"
hhh
HHH
i = <<-'III'
iii
III
j = [<<-JJJ1 , <<-"JJJ2" , <<-'JJJ3' ]
j#{1}j
JJJ1
j#{2}j
JJJ2
j#{3}j
JJJ3
k = <<'KKK'.to_i
123
KKK
z = <<'ZZZ'
ZZZ
a == "aaa\n" and
b == "bbb\n" and
c == ["c1\n", "c 2\n", "c 3\n"] and
d == "d3DDD\nd\t\nDDD\n\n" and
e == "e\#{1+2}EEE\ne\\t\nEEE\\n\n" and
f == "F\nFFfFFF\nF\n" and
g == " ggg\n" and
h == " hhh\n" and
i == " iii\n" and
j == [" j1j\n", " j2j\n", " j\#{3}j\n"] and
k == 123 and
z == ""
end
assert('Literals Array', '8.7.6.4') do
a = %W{abc#{1+2}def \}g}
b = %W(abc #{2+3} def \(g)
c = %W[#{3+4}]
d = %W< #{4+5} >
e = %W//
f = %W[[ab cd][ef]]
g = %W{
ab
#{-1}1
2#{2}
}
h = %W(a\nb
test\ abc
c\
d
x\y x\\y x\\\y)
test1 = (a == ['abc3def', '}g'] and
b == ['abc', '5', 'def', '(g'] and
c == ['7'] and
d == ['9'] and
e == [] and
f == ['[ab', 'cd][ef]'] and
g == ['ab', '-11', '22'] and
h == ["a\nb", 'test abc', "c\nd", "xy", "x\\y", "x\\y"]
)
a = %w{abc#{1+2}def \}g}
b = %w(abc #{2+3} def \(g)
c = %w[#{3+4}]
d = %w< #{4+5} >
e = %w//
f = %w[[ab cd][ef]]
g = %w{
ab
#{-1}1
2#{2}
}
h = %w(a\nb
test\ abc
c\
d
x\y x\\y x\\\y)
test2 = (a == ['abc#{1+2}def', '}g'] and
b == ['abc', '#{2+3}', 'def', '(g'] and
c == ['#{3+4}'] and
d == ['#{4+5}'] and
e == [] and
f == ['[ab', 'cd][ef]'] and
g == ['ab', '#{-1}1', '2#{2}'] and
h == ["a\\nb", "test abc", "c\nd", "x\\y", "x\\y", "x\\\\y"]
)
test1 and test2
end
assert('Literals Symbol', '8.7.6.6') do
/* do not compile error */
:$asd
:@asd
:@@asd
:asd=
:asd!
:asd?
:+
:+@
:if
:BEGIN
a = :"asd qwe"
b = :'foo bar'
c = :"a#{1+2}b"
d = %s(asd)
e = %s( foo \))
f = %s[asd \[
qwe]
g = %s/foo#{1+2}bar/
h = %s{{foo bar}}
a == :'asd qwe' and b == :"foo bar" and c == :a3b and d == :asd and
e == :' foo )' and f == :"asd [\nqwe" and g == :'foo#{1+2}bar' and
h == :'{foo bar}'
end
# Not Implemented ATM assert('Literals Regular expression', '8.7.6.5') do
|