File: argumenterror.rb

package info (click to toggle)
mruby 3.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,584 kB
  • sloc: ansic: 51,933; ruby: 29,510; yacc: 7,077; cpp: 517; makefile: 51; sh: 42
file content (37 lines) | stat: -rw-r--r-- 1,058 bytes parent folder | download | duplicates (5)
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
##
# ArgumentError ISO Test

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('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

assert("'wrong number of arguments' from mrb_get_args") do
  assert_argnum_error(0, "1+"){__send__}
  assert_argnum_error(0, 1..2){Object.const_defined?}
  assert_argnum_error(3, 1..2){Object.const_defined?(:A, true, 2)}
  assert_argnum_error(2, 0..1){{}.default(1, 2)}
  assert_argnum_error(1, 2){Object.const_set(:B)}
  assert_argnum_error(3, 2){Object.const_set(:C, 1, 2)}
end

assert('Call to MRB_ARGS_NONE method') do
  assert_raise(ArgumentError) { nil.__id__ 1 }
  assert_raise(ArgumentError) { nil.__id__ opts: 1 }
end