Top Level Namespace

Defined Under Namespace

Modules: CRubyExtension, Comparable, Enumerable, Flags, Integral, Kernel, MRuby, Rand, ScriptCore Classes: Addrinfo, ArgumentError, Array, Base, BasicSocket, BinTest_MrubyBinDebugger, Complex, ComplexLikeNumeric, Decimal, Derived, EOFError, Enumerator, FalseClass, File, Fixnum, Float, FloatDomainError, FrozenError, Hash, IO, IOError, IPSocket, IndexError, InlineStructTest, Integer, Interpreter, Isect, KeyError, LocalJumpError, MRubyTestSkip, Method, Module, NameError, NilClass, NoMethodError, NotImplementedError, Numeric, Object, Plane, Proc, Range, RangeError, Rational, Ray, RegexpError, RubyExtension, Scene, Socket, SocketError, Sphere, StopIteration, String, Struct, SubArray, Symbol, TCPServer, TCPSocket, Time, TrueClass, TypeError, UDPSocket, UNIXServer, UNIXSocket, UserDefinedNumeric, Vec

Constant Summary collapse

GEMNAME =
""
UTF8STRING =

String(Ext) Test

__ENCODING__ == "UTF-8"
NUM =
300
SIZE =
10000
IMAGE_WIDTH =

AO render benchmark Original program © Syoyo Fujita in Javascript (and other languages)

https://code.google.com/p/aobench/

Ruby(yarv2llvm) version by Hideki Miura mruby version by Hideki Miura

64
IMAGE_HEIGHT =
64
NSUBSAMPLES =
2
NAO_SAMPLES =
8
STDIN =
IO.open(0, "r")
STDOUT =
IO.open(1, "w")
STDERR =
IO.open(2, "w")
FIRST =
-> l { LEFT[RIGHT[l]] }
IF =
-> b { b }
LEFT =
-> p { p[-> x { -> y { x } } ] }
RIGHT =
-> p { p[-> x { -> y { y } } ] }
IS_EMPTY =
LEFT
REST =
-> l { RIGHT[RIGHT[l]] }
PACK_IS_LITTLE_ENDIAN =
"\x01\00".unpack('S')[0] == 0x01
INVCMD =
"invalid command"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.include(*modules) ⇒ Object



2
3
4
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-toplevel-ext/mrblib/toplevel.rb', line 2

def self.include (*modules)
  self.class.include(*modules)
end

.private(*methods) ⇒ Object



6
7
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-toplevel-ext/mrblib/toplevel.rb', line 6

def self.private(*methods)
end

.protected(*methods) ⇒ Object



8
9
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-toplevel-ext/mrblib/toplevel.rb', line 8

def self.protected(*methods)
end

.public(*methods) ⇒ Object



10
11
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-toplevel-ext/mrblib/toplevel.rb', line 10

def self.public(*methods)
end

Instance Method Details

#_assert_include(affirmed, collection, obj, msg = nil) ⇒ Object



220
221
222
223
224
225
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 220

def _assert_include(affirmed, collection, obj, msg = nil)
  unless ret = collection.include?(obj) == affirmed
    diff = "    Expected #{collection.inspect} to #{'not ' unless affirmed}include #{obj.inspect}."
  end
  assert_true(ret, msg, diff)
end

#_assert_match(affirmed, pattern, str, msg = nil) ⇒ Object



269
270
271
272
273
274
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 269

def _assert_match(affirmed, pattern, str, msg = nil)
  unless ret = _str_match?(pattern, str) == affirmed
    diff = "    Expected #{pattern.inspect} to #{'not ' unless affirmed}match #{str.inspect}."
  end
  assert_true(ret, msg, diff)
end

#_assert_operator(affirmed, obj1, op, obj2 = $undefined, msg = nil) ⇒ Object



238
239
240
241
242
243
244
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 238

def _assert_operator(affirmed, obj1, op, obj2 = $undefined, msg = nil)
  return _assert_predicate(affirmed, obj1, op, msg) if $undefined.equal?(obj2)
  unless ret = obj1.__send__(op, obj2) == affirmed
    diff = "    Expected #{obj1.inspect} to #{'not ' unless affirmed}be #{op} #{obj2.inspect}."
  end
  assert_true(ret, msg, diff)
end

#_assert_predicate(affirmed, obj, op, msg = nil) ⇒ Object



229
230
231
232
233
234
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 229

def _assert_predicate(affirmed, obj, op, msg = nil)
  unless ret = obj.__send__(op) == affirmed
    diff = "    Expected #{obj.inspect} to #{'not ' unless affirmed}be #{op}."
  end
  assert_true(ret, msg, diff)
end

#_assert_raise_with_message(type, exc, exp_msg, msg = nil, &block) ⇒ Object



337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 337

def _assert_raise_with_message(type, exc, exp_msg, msg = nil, &block)
  e = msg ? assert_raise(exc, msg, &block) : assert_raise(exc, &block)
  e ? ($mrbtest_assert_idx[-1]-=1) : (return e)

  err_msg = e.message
  unless ret = type == :pattern ? _str_match?(exp_msg, err_msg) : exp_msg == err_msg
    diff = "    Expected Exception(#{exc}) was raised, but the message doesn't match.\n"
    if type == :pattern
      diff += "    Expected #{exp_msg.inspect} to match #{err_msg.inspect}."
    else
      diff += assertion_diff(exp_msg, err_msg)
    end
  end
  assert_true(ret, msg, diff)
end

#_assert_same(affirmed, exp, act, msg = nil) ⇒ Object



194
195
196
197
198
199
200
201
202
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 194

def _assert_same(affirmed, exp, act, msg = nil)
  unless ret = exp.equal?(act) == affirmed
    exp_str, act_str = [exp, act].map do |o|
      "#{o.inspect} (class=#{o.class}, oid=#{o.__id__})"
    end
    diff = "    Expected #{act_str} to #{'not ' unless affirmed}be the same as #{exp_str}."
  end
  assert_true(ret, msg, diff)
end

#_eval_assertion(meth, exp, act_or_msg, msg, block) ⇒ Object



388
389
390
391
392
393
394
395
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 388

def _eval_assertion(meth, exp, act_or_msg, msg, block)
  if block
    exp, act, msg = exp, block.call, act_or_msg
  else
    exp, act, msg = exp, act_or_msg, msg
  end
  return exp.__send__(meth, act), exp, act, msg
end

#_pp(cmd, src, tgt = nil, options = {}) ⇒ Object



23
24
25
26
27
28
29
# File 'ext/enterprise_script_service/mruby/lib/mruby-core-ext.rb', line 23

def _pp(cmd, src, tgt=nil, options={})
  return if Rake.verbose

  width = 5
  template = options[:indent] ? "%#{width*options[:indent]}s %s %s" : "%-#{width}s %s %s"
  puts template % [cmd, src, tgt ? "-> #{tgt}" : nil]
end

#_str_match?(pattern, str) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 18

def _str_match?(pattern, str)
  File.fnmatch?(pattern, str, File::FNM_EXTGLOB|File::FNM_DOTMATCH)
end

#ArgumentErrorObject

ArgumentError ISO Test



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'ext/enterprise_script_service/mruby/test/t/argumenterror.rb', line 4

assert('ArgumentError', '15.2.24') do
  e2 = nil
  a = []
  begin
    # this will cause an exception due to the wrong arguments
    a[]
  rescue => e1
    e2 = e1
  end

  assert_equal(Class, ArgumentError.class)
  assert_equal(ArgumentError, e2.class)
end

#ArrayObject

Array ISO Test



4
5
6
# File 'ext/enterprise_script_service/mruby/test/t/array.rb', line 4

assert('Array', '15.2.12') do
  assert_equal(Class, Array.class)
end

#assert(str = 'assert', iso = '') ⇒ Object

Verify a code block.

str : A remark which will be printed in case

this assertion fails

iso : The ISO reference code of the feature

which will be tested by this
assertion


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
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 79

def assert(str = 'assert', iso = '')
  t_print(str, (iso != '' ? " [#{iso}]" : ''), ' : ') if $mrbtest_verbose
  begin
    $mrbtest_child_noassert ||= [0]
    $mrbtest_child_noassert << 0
    parent_asserts = $asserts
    $asserts = []
    parent_mrbtest_assert = $mrbtest_assert
    $mrbtest_assert = []

    if $mrbtest_assert_idx && !$mrbtest_assert_idx.empty?
      $mrbtest_assert_idx[-1] += 1
      $mrbtest_assert_idx << 0
    else
      $mrbtest_assert_idx = [0]
      class << $mrbtest_assert_idx
        alias to_s _assertion_join
      end
    end

    yield
    if $mrbtest_assert.size > 0
      if $mrbtest_assert.size == $mrbtest_child_noassert[-1]
        $asserts.push(assertion_string('Skip: ', str, iso))
        $mrbtest_child_noassert[-2] += 1
        $skip_test += 1
        t_print('?')
      else
        $asserts.push(assertion_string('Fail: ', str, iso))
        $ko_test += 1
        t_print('F')
      end
    elsif $mrbtest_assert_idx[-1] == 0
      $asserts.push(assertion_string('Warn: ', str, iso, 'no assertion'))
      $warning_test += 1
      t_print('W')
    else
      $ok_test += 1
      t_print('.')
    end
  rescue MRubyTestSkip => e
    $asserts.push(assertion_string('Skip: ', str, iso, e))
    $skip_test += 1
    $mrbtest_child_noassert[-2] += 1
    t_print('?')
  rescue Exception => e
    bt = e.backtrace if $mrbtest_verbose
    $asserts.push(assertion_string("#{e.class}: ", str, iso, e, bt))
    $kill_test += 1
    t_print('X')
  ensure
    if $mrbtest_assert_idx.size > 1
      $asserts.each do |mesg|
        idx = $mrbtest_assert_idx[0..-2]._assertion_join
        mesg = mesg._assertion_indent("    ")

        # Give `mesg` as a `diff` argument to avoid adding extra periods.
        parent_mrbtest_assert << [idx, nil, mesg]
      end
    else
      parent_asserts.concat $asserts
    end
    $asserts = parent_asserts

    $mrbtest_assert = parent_mrbtest_assert
    $mrbtest_assert_idx.pop
    $mrbtest_assert_idx = nil if $mrbtest_assert_idx.empty?
    $mrbtest_child_noassert.pop

    nil
  end
  t_print("\n") if $mrbtest_verbose
end

#assert_cmp(exp, o1, o2) ⇒ Object



44
45
46
47
48
49
50
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-rational/test/rational.rb', line 44

def assert_cmp(exp, o1, o2)
  if exp == (o1 <=> o2)
    pass
  else
    flunk "", "    Expected #{o1.inspect} <=> #{o2.inspect} to be #{exp}."
  end
end

#assert_combination(exp, receiver, *args) ⇒ Object



17
18
19
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/test/array.rb', line 17

def assert_combination(exp, receiver, *args)
  assert_permutation_combination(exp, receiver, :combination, *args)
end

#assert_complex(real, exp) ⇒ Object



1
2
3
4
5
6
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-complex/test/complex.rb', line 1

def assert_complex(real, exp)
  assert "assert_complex" do
    assert_float real.real,      exp.real
    assert_float real.imaginary, exp.imaginary
  end
end

#assert_equal(exp, act_or_msg = nil, msg = nil, &block) ⇒ Object



176
177
178
179
180
181
182
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 176

def assert_equal(exp, act_or_msg = nil, msg = nil, &block)
  ret, exp, act, msg = _eval_assertion(:==, exp, act_or_msg, msg, block)
  unless ret
    diff = assertion_diff(exp, act)
  end
  assert_true(ret, msg, diff)
end

#assert_equal_rational(exp, o1, o2) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-rational/test/rational.rb', line 32

def assert_equal_rational(exp, o1, o2)
  assert "assert_equal_rational" do
    if exp
      assert_operator(o1, :==, o2)
      assert_not_operator(o1, :!=, o2)
    else
      assert_not_operator(o1, :==, o2)
      assert_operator(o1, :!=, o2)
    end
  end
end

#assert_false(obj, msg = nil, diff = nil) ⇒ Object



169
170
171
172
173
174
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 169

def assert_false(obj, msg = nil, diff = nil)
  unless obj == false
    diff ||= "    Expected #{obj.inspect} to be false."
  end
  assert_true(!obj, msg, diff)
end

#assert_float(exp, act, msg = nil) ⇒ Object

Fails unless exp is equal to act in terms of a Float



287
288
289
290
291
292
293
294
295
296
297
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 287

def assert_float(exp, act, msg = nil)
  e, a = exp.to_f, act.to_f
  if e.finite? && a.finite? && (n = (e - a).abs) > Mrbtest::FLOAT_TOLERANCE
    flunk(msg, "    Expected |#{exp} - #{act}| (#{n}) to be <= #{Mrbtest::FLOAT_TOLERANCE}.")
  elsif (e.infinite? || a.infinite?) && e != a ||
     e.nan? && !a.nan? || !e.nan? && a.nan?
    flunk(msg, "    Expected #{act} to be #{exp}.")
  else
    pass
  end
end

#assert_float_and_int(exp_ary, act_ary) ⇒ Object

Math Test



4
5
6
7
8
9
10
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-math/test/math.rb', line 4

def assert_float_and_int(exp_ary, act_ary)
  assert('assert_float_and_int') do
    flo_exp, int_exp, flo_act, int_act = *exp_ary, *act_ary
    assert_float(flo_exp, flo_act)
    assert_operator(int_exp, :eql?, int_act)
  end
end

#assert_include(*args) ⇒ Object



218
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 218

def assert_include(*args); _assert_include(true, *args) end

#assert_io_open(meth) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/io.rb', line 7

def assert_io_open(meth)
  assert "assert_io_open" do
    fd = IO.sysopen($mrbtest_io_rfname)
    assert_equal Fixnum, fd.class
    io1 = IO.__send__(meth, fd)
    begin
      assert_equal IO, io1.class
      assert_equal $mrbtest_io_msg, io1.read
    ensure
      io1.close
    end

    io2 = IO.__send__(meth, IO.sysopen($mrbtest_io_rfname))do |io|
      if meth == :open
        assert_equal $mrbtest_io_msg, io.read
      else
        flunk "IO.#{meth} does not take block"
      end
    end
    io2.close unless meth == :open
  end
end

#assert_kind_of(cls, obj, msg = nil) ⇒ Object

Fails unless obj is a kind of cls.



278
279
280
281
282
283
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 278

def assert_kind_of(cls, obj, msg = nil)
  unless ret = obj.kind_of?(cls)
    diff = "    Expected #{obj.inspect} to be a kind of #{cls}, not #{obj.class}."
  end
  assert_true(ret, msg, diff)
end

#assert_match(*args) ⇒ Object

Fail unless str matches against pattern.

pattern is interpreted as pattern for File.fnmatch?. It may contain the following metacharacters:

*

Matches any string.

?

Matches any one character.

[SET], [^SET] ([!SET])

Matches any one character in SET. Behaves like character sets in Regexp, including set negation ([^a-z]).

{A,B}

Matches pattern A or pattern B.

\

Escapes the next character.



267
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 267

def assert_match(*args); _assert_match(true, *args) end

#assert_mruby(exp_out, exp_err, exp_success, args) ⇒ Object



4
5
6
7
8
9
10
11
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/bintest/mruby.rb', line 4

def assert_mruby(exp_out, exp_err, exp_success, args)
  out, err, stat = Open3.capture3(cmd("mruby"), *args)
  assert "assert_mruby" do
    assert_operator(exp_out, :===, out, "standard output")
    assert_operator(exp_err, :===, err, "standard error")
    assert_equal(exp_success, stat.success?, "exit success?")
  end
end

#assert_nil(obj, msg = nil) ⇒ Object



204
205
206
207
208
209
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 204

def assert_nil(obj, msg = nil)
  unless ret = obj.nil?
    diff = "    Expected #{obj.inspect} to be nil."
  end
  assert_true(ret, msg, diff)
end

#assert_not_equal(exp, act_or_msg = nil, msg = nil, &block) ⇒ Object



184
185
186
187
188
189
190
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 184

def assert_not_equal(exp, act_or_msg = nil, msg = nil, &block)
  ret, exp, act, msg = _eval_assertion(:==, exp, act_or_msg, msg, block)
  if ret
    diff = "    Expected #{act.inspect} to not be equal to #{exp.inspect}."
  end
  assert_true(!ret, msg, diff)
end

#assert_not_include(*args) ⇒ Object



219
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 219

def assert_not_include(*args); _assert_include(false, *args) end

#assert_not_match(*args) ⇒ Object



268
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 268

def assert_not_match(*args); _assert_match(false, *args) end

#assert_not_nil(obj, msg = nil) ⇒ Object



211
212
213
214
215
216
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 211

def assert_not_nil(obj, msg = nil)
  if ret = obj.nil?
    diff = "    Expected #{obj.inspect} to not be nil."
  end
  assert_false(ret, msg, diff)
end

#assert_not_operator(*args) ⇒ Object



237
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 237

def assert_not_operator(*args); _assert_operator(false, *args) end

#assert_not_predicate(*args) ⇒ Object



228
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 228

def assert_not_predicate(*args); _assert_predicate(false, *args) end

#assert_not_same(*args) ⇒ Object



193
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 193

def assert_not_same(*args); _assert_same(false, *args) end

#assert_nothing_raised(msg = nil) ⇒ Object



318
319
320
321
322
323
324
325
326
327
328
329
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 318

def assert_nothing_raised(msg = nil)
  begin
    yield
  rescue Exception => e
    diff = "    Exception raised:\n" \
           "    Class: <#{e.class}>\n" \
           "    Message: <#{e}>"
    flunk(msg, diff)
  else
    pass
  end
end

#assert_operator(*args) ⇒ Object



236
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 236

def assert_operator(*args); _assert_operator(true, *args) end

#assert_pack(tmpl, packed, unpacked) ⇒ Object



3
4
5
6
7
8
9
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-pack/test/pack.rb', line 3

def assert_pack tmpl, packed, unpacked
  t = tmpl.inspect
  assert "assert_pack" do
    assert_equal packed, unpacked.pack(tmpl), "#{unpacked.inspect}.pack(#{t})"
    assert_equal unpacked, packed.unpack(tmpl), "#{packed.inspect}.unpack(#{t})"
  end
end

#assert_permutation(exp, receiver, *args) ⇒ Object



13
14
15
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/test/array.rb', line 13

def assert_permutation(exp, receiver, *args)
  assert_permutation_combination(exp, receiver, :permutation, *args)
end

#assert_permutation_combination(exp, receiver, meth, *args) ⇒ Object

Array(Ext) Test



4
5
6
7
8
9
10
11
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/test/array.rb', line 4

def assert_permutation_combination(exp, receiver, meth, *args)
  act = []
  ret = receiver.__send__(meth, *args) { |v| act << v }
  assert "assert_#{meth}" do
    assert_equal(exp, act.sort)
    assert_same(receiver, ret)
  end
end

#assert_predicate(*args) ⇒ Object



227
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 227

def assert_predicate(*args); _assert_predicate(true, *args) end

#assert_raise(*exc) ⇒ Object



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 299

def assert_raise(*exc)
  msg = (exc.last.is_a? String) ? exc.pop : nil
  exc = exc.empty? ? StandardError : exc.size == 1 ? exc[0] : exc
  begin
    yield
  rescue *exc => e
    pass
    e
  rescue Exception => e
    diff = "    #{exc} exception expected, not\n" \
           "    Class: <#{e.class}>\n" \
           "    Message: <#{e}>"
    flunk(msg, diff)
  else
    diff = "    #{exc} expected but nothing was raised."
    flunk(msg, diff)
  end
end

#assert_raise_with_message(*args, &block) ⇒ Object



331
332
333
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 331

def assert_raise_with_message(*args, &block)
  _assert_raise_with_message(:plain, *args, &block)
end

#assert_raise_with_message_pattern(*args, &block) ⇒ Object



334
335
336
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 334

def assert_raise_with_message_pattern(*args, &block)
  _assert_raise_with_message(:pattern, *args, &block)
end

#assert_rational(exp, real) ⇒ Object



25
26
27
28
29
30
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-rational/test/rational.rb', line 25

def assert_rational(exp, real)
  assert "assert_rational" do
    assert_float exp.numerator,   real.numerator
    assert_float exp.denominator, real.denominator
  end
end

#assert_same(*args) ⇒ Object



192
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 192

def assert_same(*args); _assert_same(true, *args) end

#assert_step(exp, receiver, args, inf: false) ⇒ Object

Numeric ISO Test



4
5
6
7
8
9
10
11
12
13
14
15
# File 'ext/enterprise_script_service/mruby/test/t/numeric.rb', line 4

def assert_step(exp, receiver, args, inf: false)
  act = []
  ret = receiver.step(*args) do |i|
    act << i
    break if inf && exp.size == act.size
  end
  expr = "#{receiver.inspect}.step(#{args.map(&:inspect).join(', ')})"
  assert "assert_step" do
    assert_true(exp.eql?(act), "#{expr}: counters", assertion_diff(exp, act))
    assert_same(receiver, ret, "#{expr}: return value") unless inf
  end
end

#assert_take(exp, enumerator) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/test/enumerator.rb', line 9

def assert_take(exp, enumerator)
  result = []
  n = exp.size
  enumerator.each do |v|
    result << v
    n -= 1
    break if n == 0
  end if n > 0
  assert_equal exp, result
end

#assert_true(obj, msg = nil, diff = nil) ⇒ Object



158
159
160
161
162
163
164
165
166
167
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 158

def assert_true(obj, msg = nil, diff = nil)
  if $mrbtest_assert_idx && $mrbtest_assert_idx.size > 0
    $mrbtest_assert_idx[-1] += 1
    unless obj == true
      diff ||= "    Expected #{obj.inspect} to be true."
      $mrbtest_assert.push([$mrbtest_assert_idx.to_s, msg, diff])
    end
  end
  obj
end

#assert_uninitialized_const(&block) ⇒ Object



24
25
26
# File 'ext/enterprise_script_service/mruby/test/t/module.rb', line 24

def assert_uninitialized_const(&block)
  assert_raise_with_message_pattern(NameError, "uninitialized constant *", &block)
end

#assert_upto(exp, receiver, *args) ⇒ Object



7
8
9
10
11
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/test/string.rb', line 7

def assert_upto(exp, receiver, *args)
  act = []
  receiver.upto(*args) { |v| act << v }
  assert_equal exp, act
end

#assert_wrong_const_name(&block) ⇒ Object



28
29
30
# File 'ext/enterprise_script_service/mruby/test/t/module.rb', line 28

def assert_wrong_const_name(&block)
  assert_raise_with_message_pattern(NameError, "wrong constant name *", &block)
end

#assertion_diff(exp, act) ⇒ Object



153
154
155
156
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 153

def assertion_diff(exp, act)
  "    Expected: #{exp.inspect}\n" \
  "      Actual: #{act.inspect}"
end

#assertion_string(err, str, iso = nil, e = nil, bt = nil) ⇒ Object

Create the assertion in a readable way



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 55

def assertion_string(err, str, iso=nil, e=nil, bt=nil)
  msg = "#{err}#{str}"
  msg += " [#{iso}]" if iso && !iso.empty?
  msg += " => #{e}" if e && !e.to_s.empty?
  msg += " (#{GEMNAME == 'mruby-test' ? 'core' : "mrbgems: #{GEMNAME}"})"
  if $mrbtest_assert
    $mrbtest_assert.each do |idx, assert_msg, diff|
      msg += "\n - Assertion[#{idx}]"
      msg += " #{assert_msg}." if assert_msg && !assert_msg.empty?
      msg += "\n#{diff}" if diff && !diff.empty?
    end
  end
  msg += "\nbacktrace:\n        #{bt.join("\n        ")}" if bt
  msg
end

#backtrace_available?Boolean

Returns:

  • (Boolean)


381
382
383
384
385
386
387
# File 'ext/enterprise_script_service/mruby/test/t/exception.rb', line 381

def backtrace_available?
  begin
    raise "XXX"
  rescue => exception
    not exception.backtrace.empty?
  end
end

#BasicObjectObject

BasicObject



4
5
6
# File 'ext/enterprise_script_service/mruby/test/t/basicobject.rb', line 4

assert('BasicObject') do
  assert_equal(Class, BasicObject.class)
end

#clamp(f) ⇒ Object



171
172
173
174
175
176
177
178
179
180
# File 'ext/enterprise_script_service/mruby/benchmark/bm_ao_render.rb', line 171

def clamp(f)
  i = f * 255.5
  if i > 255.0
    i = 255.0
  end
  if i < 0.0
    i = 0.0
  end
  i.to_i
end

#ClassObject

Class ISO Test



4
5
6
# File 'ext/enterprise_script_service/mruby/test/t/class.rb', line 4

assert('Class', '15.2.3') do
  assert_equal(Class, Class.class)
end

#cmd(s) ⇒ Object



6
7
8
9
10
11
12
13
# File 'ext/enterprise_script_service/mruby/test/bintest.rb', line 6

def cmd(s)
  case RbConfig::CONFIG['host_os']
  when /mswin(?!ce)|mingw|bccwin/
    "bin\\#{s}.exe"
  else
    "bin/#{s}"
  end
end

#enable_debug_info?Boolean

Proc(Ext) Test

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/test/proc.rb', line 4

def enable_debug_info?
  return @enable_debug_info unless @enable_debug_info == nil
  begin
    raise
  rescue => e
    @enable_debug_info = !e.backtrace.empty?
  end
end

#EnumerableObject

Enumerable ISO Test



4
5
6
# File 'ext/enterprise_script_service/mruby/test/t/enumerable.rb', line 4

assert('Enumerable', '15.3.2') do
  assert_equal(Module, Enumerable.class)
end

#ExceptionObject

Exception ISO Test



4
5
6
# File 'ext/enterprise_script_service/mruby/test/t/exception.rb', line 4

assert('Exception', '15.2.22') do
  assert_equal Class, Exception.class
end

#FalseClassObject

FalseClass ISO Test



4
5
6
# File 'ext/enterprise_script_service/mruby/test/t/false.rb', line 4

assert('FalseClass', '15.2.6') do
  assert_equal Class, FalseClass.class
end

#fib(n) ⇒ Object



2
3
4
5
# File 'ext/enterprise_script_service/mruby/benchmark/bm_fib.rb', line 2

def fib n
  return n if n < 2
  fib(n-2) + fib(n-1)
end

#flunk(msg = "Epic Fail!", diff = "") ⇒ Object



357
358
359
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 357

def flunk(msg = "Epic Fail!", diff = "")
  assert_true(false, msg, diff)
end

#HashObject

Hash ISO Test



4
5
6
# File 'ext/enterprise_script_service/mruby/test/t/hash.rb', line 4

assert('Hash', '15.2.13') do
  assert_equal Class, Hash.class
end

#IndexErrorObject

IndexError ISO Test



4
5
6
# File 'ext/enterprise_script_service/mruby/test/t/indexerror.rb', line 4

assert('IndexError', '15.2.33') do
  assert_equal Class, IndexError.class
end

#IntegerObject

Integer ISO Test



4
5
6
# File 'ext/enterprise_script_service/mruby/test/t/integer.rb', line 4

assert('Integer', '15.2.8') do
  assert_equal Class, Integer.class
end

#KernelObject

Kernel ISO Test



4
5
6
# File 'ext/enterprise_script_service/mruby/test/t/kernel.rb', line 4

assert('Kernel', '15.3.1') do
  assert_equal Module, Kernel.class
end

#labeled_class(name, supklass = Object, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'ext/enterprise_script_service/mruby/test/t/module.rb', line 14

def labeled_class(name, supklass = Object, &block)
  Class.new(supklass) do
    (class <<self; self end).class_eval do
      define_method(:to_s) { name }
      alias_method :inspect, :to_s
    end
    class_eval(&block) if block
  end
end

#labeled_module(name, &block) ⇒ Object

Module ISO Test



4
5
6
7
8
9
10
11
12
# File 'ext/enterprise_script_service/mruby/test/t/module.rb', line 4

def labeled_module(name, &block)
  Module.new do
    (class <<self; self end).class_eval do
      define_method(:to_s) { name }
      alias_method :inspect, :to_s
    end
    class_eval(&block) if block
  end
end

#NameErrorObject

NameError ISO Test



4
5
6
# File 'ext/enterprise_script_service/mruby/test/t/nameerror.rb', line 4

assert('NameError', '15.2.31') do
  assert_equal Class, NameError.class
end

#NilClassObject

NilClass ISO Test



4
5
6
# File 'ext/enterprise_script_service/mruby/test/t/nil.rb', line 4

assert('NilClass', '15.2.4') do
  assert_equal Class, NilClass.class
end

#NoMethodErrorObject

NoMethodError ISO Test



4
5
6
7
8
9
# File 'ext/enterprise_script_service/mruby/test/t/nomethoderror.rb', line 4

assert('NoMethodError', '15.2.32') do
  NoMethodError.class == Class
  assert_raise NoMethodError do
    doesNotExistAsAMethodNameForVerySure("")
  end
end

#ObjectObject

Object ISO Test



4
5
6
# File 'ext/enterprise_script_service/mruby/test/t/object.rb', line 4

assert('Object', '15.2.1') do
  assert_equal Class, Object.class
end

#otherBasis(basis, n) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'ext/enterprise_script_service/mruby/benchmark/bm_ao_render.rb', line 182

def otherBasis(basis, n)
  basis[2] = Vec.new(n.x, n.y, n.z)
  basis[1] = Vec.new(0.0, 0.0, 0.0)

  if n.x < 0.6 and n.x > -0.6
    basis[1].x = 1.0
  elsif n.y < 0.6 and n.y > -0.6
    basis[1].y = 1.0
  elsif n.z < 0.6 and n.z > -0.6
    basis[1].z = 1.0
  else
    basis[1].x = 1.0
  end

  basis[0] = basis[1].vcross(basis[2])
  basis[0] = basis[0].vnormalize

  basis[1] = basis[2].vcross(basis[0])
  basis[1] = basis[1].vnormalize
end

#passObject



353
354
355
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 353

def pass
  assert_true(true)
end

#ProcObject

Proc ISO Test



4
5
6
# File 'ext/enterprise_script_service/mruby/test/t/proc.rb', line 4

assert('Proc', '15.2.17') do
  assert_equal Class, Proc.class
end

#RangeObject

Range ISO Test



4
5
6
# File 'ext/enterprise_script_service/mruby/test/t/range.rb', line 4

assert('Range', '15.2.14') do
  assert_equal Class, Range.class
end

#RangeErrorObject

RangeError ISO Test



4
5
6
# File 'ext/enterprise_script_service/mruby/test/t/rangeerror.rb', line 4

assert('RangeError', '15.2.26') do
  assert_equal Class, RangeError.class
end

#reportObject

Report the test result and print all assertions which were reported broken.



364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 364

def report
  t_print("\n")

  $asserts.each do |msg|
    t_print("#{msg}\n")
  end

  $total_test = $ok_test + $ko_test + $kill_test + $warning_test + $skip_test
  t_print("  Total: #{$total_test}\n")

  t_print("     OK: #{$ok_test}\n")
  t_print("     KO: #{$ko_test}\n")
  t_print("  Crash: #{$kill_test}\n")
  t_print("Warning: #{$warning_test}\n")
  t_print("   Skip: #{$skip_test}\n")

  if Object.const_defined?(:Time)
    t_time = Time.now - $test_start
    t_print("   Time: #{t_time.round(2)} seconds\n")
  end

  $ko_test == 0 && $kill_test == 0
end

#RuntimeErrorObject

RuntimeError ISO Test



4
5
6
# File 'ext/enterprise_script_service/mruby/test/t/runtimeerror.rb', line 4

assert('RuntimeError', '15.2.28') do
  assert_equal Class, RuntimeError.class
end

#shellquote(s) ⇒ Object



15
16
17
18
19
20
21
22
# File 'ext/enterprise_script_service/mruby/test/bintest.rb', line 15

def shellquote(s)
  case RbConfig::CONFIG['host_os']
  when /mswin(?!ce)|mingw|bccwin/
    "\"#{s}\""
  else
    "'#{s}'"
  end
end

#skip(cause = "") ⇒ Object

Raises:



401
402
403
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 401

def skip(cause = "")
  raise MRubyTestSkip.new(cause)
end

#StandardErrorObject

StandardError ISO Test



4
5
6
# File 'ext/enterprise_script_service/mruby/test/t/standarderror.rb', line 4

assert('StandardError', '15.2.23') do
  assert_equal Class, StandardError.class
end

#StructObject

Struct ISO Test



4
5
6
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-struct/test/struct.rb', line 4

assert('Struct', '15.2.18') do
  assert_equal Class, Struct.class
end

#SymbolObject

Symbol ISO Test



4
5
6
7
8
9
# File 'ext/enterprise_script_service/mruby/test/t/symbol.rb', line 4

assert('Symbol') do
  assert_equal :"a", :a
  assert_equal :"a#{1}", :a1
  assert_equal :'a', :a
  assert_equal :'a#{1}', :"a\#{1}"
end

#t_print(*args) ⇒ Object



12
13
14
15
16
# File 'ext/enterprise_script_service/mruby/test/assert.rb', line 12

def t_print(*args)
  print(*args)
  $stdout.flush
  nil
end

#test_listsObject



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
# File 'ext/enterprise_script_service/mruby/benchmark/bm_so_lists.rb', line 6

def test_lists()
  # create a list of integers (Li1) from 1 to SIZE
  li1 = (1..SIZE).to_a
  # copy the list to li2 (not by individual items)
  li2 = li1.dup
  # remove each individual item from left side of li2 and
  # append to right side of li3 (preserving order)
  li3 = Array.new
  while (not li2.empty?)
    li3.push(li2.shift)
  end
  # li2 must now be empty
  # remove each individual item from right side of li3 and
  # append to right side of li2 (reversing list)
  until li3.empty?
    li2.push(li3.pop)
  end
  # li3 must now be empty
  # reverse li1 in place
  li1.reverse!
  # check that first item is now SIZE
  if li1[0] != SIZE
    p "not SIZE"
    0
  else
    # compare li1 and li2 for equality
    if li1 != li2
      return(0)
    else
      # return the length of the list
      li1.length
    end
  end
end

#to_array(proc) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'ext/enterprise_script_service/mruby/benchmark/bm_app_lc_fizzbuzz.rb', line 28

def to_array(proc)
  array = []

  until to_boolean(IS_EMPTY[proc])
    array.push(FIRST[proc])
    proc = REST[proc]
  end

  array
end

#to_boolean(proc) ⇒ Object



24
25
26
# File 'ext/enterprise_script_service/mruby/benchmark/bm_app_lc_fizzbuzz.rb', line 24

def to_boolean(proc)
  IF[proc][true][false]
end

#to_char(c) ⇒ Object



39
40
41
# File 'ext/enterprise_script_service/mruby/benchmark/bm_app_lc_fizzbuzz.rb', line 39

def to_char(c)
  '0123456789BFiuz'.slice(to_integer(c))
end

#to_integer(proc) ⇒ Object



20
21
22
# File 'ext/enterprise_script_service/mruby/benchmark/bm_app_lc_fizzbuzz.rb', line 20

def to_integer(proc)
  proc[-> n { n + 1 }][0]
end

#to_string(s) ⇒ Object



43
44
45
# File 'ext/enterprise_script_service/mruby/benchmark/bm_app_lc_fizzbuzz.rb', line 43

def to_string(s)
  to_array(s).map { |c| to_char(c) }.join
end

#TrueClassObject

TrueClass ISO Test



4
5
6
# File 'ext/enterprise_script_service/mruby/test/t/true.rb', line 4

assert('TrueClass', '15.2.5') do
  assert_equal Class, TrueClass.class
end

#TypeErrorObject

TypeError ISO Test



4
5
6
# File 'ext/enterprise_script_service/mruby/test/t/typeerror.rb', line 4

assert('TypeError', '15.2.29') do
  assert_equal Class, TypeError.class
end

#unixserver_test_blockObject



3
4
5
6
7
8
9
10
11
12
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-socket/test/unix.rb', line 3

def unixserver_test_block
  path = SocketTest.tmppath
  File.unlink path rescue nil
  begin
    result = yield path
  ensure
    File.unlink path rescue nil
  end
  result
end

#with_unix_clientObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-socket/test/unix.rb', line 22

def with_unix_client
  with_unix_server do |path, server|
    UNIXSocket.open(path) do |csock|
      ssock = server.accept
      begin
        yield path, server, ssock, csock
      ensure
        ssock.close unless ssock.closed? rescue nil
      end
    end
  end
end

#with_unix_serverObject



14
15
16
17
18
19
20
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-socket/test/unix.rb', line 14

def with_unix_server
  unixserver_test_block do |path|
    UNIXServer.open(path) { |server|
      yield path, server
    }
  end
end