Top Level Namespace

Defined Under Namespace

Modules: CRubyExtension, Comparable, Enumerable, Flags, Kernel, MRuby, Rand, ScriptCore Classes: Addrinfo, ArgumentError, Array, Base, BasicObject, BasicSocket, BinTest_MrubyBinDebugger, Complex, ComplexLikeNumeric, Decimal, Derived, EOFError, EnsureYieldBreak, Enumerator, FalseClass, File, Fixnum, Float, FloatDomainError, FrozenError, Hash, HashEntries, HashKey, 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, ThrowCatchJump, Time, TrueClass, TypeError, UDPSocket, UNIXServer, UNIXSocket, UserDefinedNumeric, Vec, ZeroDivisionError

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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, indent: nil) ⇒ Object



30
31
32
33
34
35
36
# File 'ext/enterprise_script_service/mruby/lib/mruby/core_ext.rb', line 30

def _pp(cmd, src, tgt=nil, indent: nil)
  return if Rake.application.options.silent

  width = 5
  template = indent ? "%#{width * 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

#ar_entriesObject



64
65
66
67
68
69
70
71
72
73
74
# File 'ext/enterprise_script_service/mruby/test/t/hash.rb', line 64

def ar_entries
  HashEntries[
    [1, "one"],
    [HashKey[2], :two],
    [nil, :two],
    [:one, 1],
    ["&", "&"],
    [HashKey[6], :six],
    [HashKey[5], :five],  # same hash code as HashKey[2]
  ]
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


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

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
    $asserts.push(assertion_string("#{e.class}: ", str, iso, e, e.backtrace))
    $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_argnum_error(given, expected, &block) ⇒ Object

ArgumentError ISO Test



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

def assert_argnum_error(given, expected, &block)
  assert("wrong number of arguments") do
    message = "wrong number of arguments (given #{given}, expected #{expected})"
    assert_raise_with_message(ArgumentError, message, &block)
  end
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



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

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



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

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



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

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



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

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
29
30
31
# 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 Integer, 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

    assert_raise(RuntimeError) { IO.__send__(meth, 1023) } # For Windows
    assert_raise(RuntimeError) { IO.__send__(meth, 1 << 26) }
  end
end

#assert_iterator(exp, obj, meth) ⇒ Object



119
120
121
122
123
# File 'ext/enterprise_script_service/mruby/test/t/hash.rb', line 119

def assert_iterator(exp, obj, meth)
  params = []
  obj.__send__(meth) {|param| params << param}
  assert_equal(exp, params)
end

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

Fails unless obj is a kind of cls.



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

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.



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

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



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

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



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

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



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

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

#assert_not_match(*args) ⇒ Object



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

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

#assert_not_nil(obj, msg = nil) ⇒ Object



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

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



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

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

#assert_not_predicate(*args) ⇒ Object



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

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

#assert_not_same(*args) ⇒ Object



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

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

#assert_nothing_crashed(&block) ⇒ Object



125
126
127
128
# File 'ext/enterprise_script_service/mruby/test/t/hash.rb', line 125

def assert_nothing_crashed(&block)
  block.call rescue nil
  pass
end

#assert_nothing_raised(msg = nil) ⇒ Object



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

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



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

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



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

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

#assert_raise(*exc) ⇒ Object



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

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



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

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

#assert_raise_with_message_pattern(*args, &block) ⇒ Object



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

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



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

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



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

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



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

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
70
71
# 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?
  if Object.const_defined?(:GEMNAME)
    msg += " (#{GEMNAME == 'mruby-test' ? 'core' : "mrbgems: #{GEMNAME}"})"
  end
  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 && !bt.empty?
  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)
  path = s == "mrbc" ? ENV['MRBCFILE'] : "#{ENV['BUILD_DIR']}/bin/#{s}"
  path = path.sub(/\.exe\z/, "")
  if /mswin(?!ce)|mingw|bccwin/ =~ RbConfig::CONFIG['host_os']
    path = "#{path}.exe".tr("/", "\\")
  end
  path
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



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

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

#ht_entriesObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'ext/enterprise_script_service/mruby/test/t/hash.rb', line 76

def ht_entries
  ar_entries.dup.push(
    ["id", 32],
    [:date, "2020-05-02"],
    [200, "OK"],
    ["modifiers", ["left_shift", "control"]],
    [:banana, :yellow],
    ["JSON", "JavaScript Object Notation"],
    [:size, :large],
    ["key_code", "h"],
    ["h", 0x04],
    [[3, 2, 1], "three, two, one"],
    [:auto, true],
    [HashKey[12], "December"],
    [:path, "/path/to/file"],
    [:name, "Ruby"],
  )
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

#install_D(src, dst) ⇒ Object



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

def install_D(src, dst)
  _pp "INSTALL", src.relative_path, dst.relative_path
  rm_f dst
  mkdir_p File.dirname(dst)
  cp src, dst
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

#merge_entries!(entries1, entries2) ⇒ Object



95
96
97
98
99
100
101
# File 'ext/enterprise_script_service/mruby/test/t/hash.rb', line 95

def merge_entries!(entries1, entries2)
  entries2.each do |k2, v2|
    entry1 = entries1.find{|k1, _| k1.eql?(k2)}
    entry1 ? (entry1[1] = v2) : (entries1 << [k2, v2])
  end
  entries1
end

#mruby_engine_gembox_pathObject



5
6
7
8
9
10
11
12
13
# File 'ext/enterprise_script_service/mruby_config.rb', line 5

def mruby_engine_gembox_path
  if ENV["MRUBY_ENGINE_GEMBOX_PATH"] && File.exist?(ENV["MRUBY_ENGINE_GEMBOX_PATH"])
    raise "`#{ENV['MRUBY_ENGINE_GEMBOX_PATH']}` require `.gembox` extension" unless ENV["MRUBY_ENGINE_GEMBOX_PATH"].end_with?(".gembox")

    Pathname.new ENV["MRUBY_ENGINE_GEMBOX_PATH"][0..-8]
  else
    Pathname.new(__FILE__).dirname.join("mruby_engine")
  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



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

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

#product(*arrays, &block) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'ext/enterprise_script_service/mruby/test/t/hash.rb', line 103

def product(*arrays, &block)
  sizes = Array.new(arrays.size+1, 1)
  (arrays.size-1).downto(0){|i| sizes[i] = arrays[i].size * sizes[i+1]}
  size = sizes[0]
  results = Array.new(size){[]}
  arrays.each_with_index do |array, arrays_i|
    results_i = -1
    (size / sizes[arrays_i]).times do
      array.each do |v|
        sizes[arrays_i+1].times{results[results_i+=1] << v}
      end
    end
  end
  results.each{block.(_1)}
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.



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

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

#setup_option(conf) ⇒ Object



3
4
5
6
7
# File 'ext/enterprise_script_service/mruby/build_config/ci/msvc.rb', line 3

def setup_option(conf)
  conf.cc.compile_options.sub!(%r{/Zi }, "") unless ENV['CFLAGS']
  conf.cxx.compile_options.sub!(%r{/Zi }, "") unless ENV['CFLAGS'] || ENV['CXXFLAGS']
  conf.linker.flags << "/DEBUG:NONE" unless ENV['LDFLAGS']
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:



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

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