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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
|
##
# Kernel ISO Test
assert('Kernel', '15.3.1') do
Kernel.class == Module
end
assert('Kernel.block_given?', '15.3.1.2.2') do
def bg_try(&b)
if Kernel.block_given?
yield
else
"no block"
end
end
(Kernel.block_given? == false) and
# test without block
(bg_try == "no block") and
# test with block
((bg_try { "block" }) == "block") and
# test with block
((bg_try do "block" end) == "block")
end
assert('Kernel.global_variables', '15.3.1.2.4') do
Kernel.global_variables.class == Array
end
assert('Kernel.iterator?', '15.3.1.2.5') do
Kernel.iterator? == false
end
assert('Kernel.lambda', '15.3.1.2.6') do
l = Kernel.lambda do
true
end
m = Kernel.lambda(&l)
l.call and l.class == Proc and m.call and m.class == Proc
end
# Not implemented at the moment
#assert('Kernel.local_variables', '15.3.1.2.7') do
# Kernel.local_variables.class == Array
#end
assert('Kernel.loop', '15.3.1.2.8') do
i = 0
Kernel.loop do
i += 1
break if i == 100
end
i == 100
end
assert('Kernel.p', '15.3.1.2.9') do
# TODO search for a way to test p to stdio
true
end
assert('Kernel.print', '15.3.1.2.10') do
# TODO search for a way to test print to stdio
true
end
assert('Kernel.puts', '15.3.1.2.11') do
# TODO search for a way to test puts to stdio
true
end
assert('Kernel.raise', '15.3.1.2.12') do
e_list = []
begin
Kernel.raise
rescue => e
e_list << e
end
begin
Kernel.raise RuntimeError.new
rescue => e
e_list << e
end
# result without argument
e_list[0].class == RuntimeError and
# result with RuntimeError argument
e_list[1].class == RuntimeError
end
assert('Kernel#__id__', '15.3.1.3.3') do
__id__.class == Fixnum
end
assert('Kernel#__send__', '15.3.1.3.4') do
# test with block
l = __send__(:lambda) do
true
end
l.call and l.class == Proc and
# test with argument
__send__(:respond_to?, :nil?) and
# test without argument and without block
__send__(:public_methods).class == Array
end
assert('Kernel#block_given?', '15.3.1.3.6') do
def bg_try(&b)
if block_given?
yield
else
"no block"
end
end
(block_given? == false) and
(bg_try == "no block") and
((bg_try { "block" }) == "block") and
((bg_try do "block" end) == "block")
end
assert('Kernel#class', '15.3.1.3.7') do
Kernel.class == Module
end
assert('Kernel#clone', '15.3.1.3.8') do
class KernelCloneTest
def initialize
@v = 0
end
def get
@v
end
def set(v)
@v = v
end
end
a = KernelCloneTest.new
a.set(1)
b = a.clone
def a.test
end
a.set(2)
c = a.clone
a.get == 2 and b.get == 1 and c.get == 2 &&
a.respond_to?(:test) == true and
b.respond_to?(:test) == false and
c.respond_to?(:test) == true
end
assert('Kernel#dup', '15.3.1.3.9') do
class KernelDupTest
def initialize
@v = 0
end
def get
@v
end
def set(v)
@v = v
end
end
a = KernelDupTest.new
a.set(1)
b = a.dup
def a.test
end
a.set(2)
c = a.dup
a.get == 2 and b.get == 1 and c.get == 2 and
a.respond_to?(:test) == true and
b.respond_to?(:test) == false and
c.respond_to?(:test) == false
end
assert('Kernel#extend', '15.3.1.3.13') do
class Test4ExtendClass
end
module Test4ExtendModule
def test_method; end
end
a = Test4ExtendClass.new
a.extend(Test4ExtendModule)
b = Test4ExtendClass.new
a.respond_to?(:test_method) == true && b.respond_to?(:test_method) == false
end
assert('Kernel#global_variables', '15.3.1.3.14') do
global_variables.class == Array
end
assert('Kernel#hash', '15.3.1.3.15') do
hash == hash
end
assert('Kernel#inspect', '15.3.1.3.17') do
inspect.class == String
end
assert('Kernel#instance_variables', '15.3.1.3.23') do
instance_variables.class == Array
end
assert('Kernel#is_a?', '15.3.1.3.24') do
is_a?(Kernel) and not is_a?(Array)
end
assert('Kernel#iterator?', '15.3.1.3.25') do
iterator? == false
end
assert('Kernel#kind_of?', '15.3.1.3.26') do
kind_of?(Kernel) and not kind_of?(Array)
end
assert('Kernel#lambda', '15.3.1.3.27') do
l = lambda do
true
end
m = lambda(&l)
l.call and l.class == Proc and m.call and m.class == Proc
end
# Not implemented yet
#assert('Kernel#local_variables', '15.3.1.3.28') do
# local_variables.class == Array
#end
assert('Kernel#loop', '15.3.1.3.29') do
i = 0
loop do
i += 1
break if i == 100
end
i == 100
end
assert('Kernel#methods', '15.3.1.3.31') do
methods.class == Array
end
assert('Kernel#nil?', '15.3.1.3.32') do
nil.nil? == true
end
assert('Kernel#object_id', '15.3.1.3.33') do
object_id.class == Fixnum
end
assert('Kernel#private_methods', '15.3.1.3.36') do
private_methods.class == Array
end
assert('Kernel#protected_methods', '15.3.1.3.37') do
protected_methods.class == Array
end
assert('Kernel#public_methods', '15.3.1.3.38') do
public_methods.class == Array
end
assert('Kernel#raise', '15.3.1.3.40') do
e_list = []
begin
raise
rescue => e
e_list << e
end
begin
raise RuntimeError.new
rescue => e
e_list << e
end
# result without argument
e_list[0].class == RuntimeError and
# result with RuntimeError argument
e_list[1].class == RuntimeError
end
assert('Kernel#respond_to?', '15.3.1.3.43') do
class Test4RespondTo
def test_method; end
undef test_method
end
respond_to?(:nil?) and Test4RespondTo.new.respond_to?(:test_method) == false
end
assert('Kernel#send', '15.3.1.3.44') do
# test with block
l = send(:lambda) do
true
end
l.call and l.class == Proc and
# test with argument
send(:respond_to?, :nil?) and
# test without argument and without block
send(:public_methods).class == Array
end
assert('Kernel#singleton_methods', '15.3.1.3.45') do
singleton_methods.class == Array
end
assert('Kernel#to_s', '15.3.1.3.46') do
# TODO looks strange..
to_s == ''
end
|