source: EcnlProtoTool/trunk/mruby-1.2.0/test/t/methods.rb@ 270

Last change on this file since 270 was 270, checked in by coas-nagasima, 7 years ago

mruby版ECNLプロトタイピング・ツールを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby
File size: 2.8 KB
Line 
1##
2# Chapter 13.3 "Methods" ISO Test
3
4assert('The alias statement', '13.3.6 a) 4)') do
5 # check aliasing in all possible ways
6
7 def alias_test_method_original; true; end
8
9 alias alias_test_method_a alias_test_method_original
10 alias :alias_test_method_b :alias_test_method_original
11
12 assert_true(alias_test_method_original)
13 assert_true(alias_test_method_a)
14 assert_true(alias_test_method_b)
15end
16
17assert('The alias statement (overwrite original)', '13.3.6 a) 4)') do
18 # check that an aliased method can be overwritten
19 # without side effect
20
21 def alias_test_method_original; true; end
22
23 alias alias_test_method_a alias_test_method_original
24 alias :alias_test_method_b :alias_test_method_original
25
26 assert_true(alias_test_method_original)
27
28 def alias_test_method_original; false; end
29
30 assert_false(alias_test_method_original)
31 assert_true(alias_test_method_a)
32 assert_true(alias_test_method_b)
33end
34
35assert('The alias statement', '13.3.6 a) 5)') do
36 # check that alias is raising NameError if
37 # non-existing method should be undefined
38
39 assert_raise(NameError) do
40 alias new_name_a non_existing_method
41 end
42
43 assert_raise(NameError) do
44 alias :new_name_b :non_existing_method
45 end
46end
47
48assert('The undef statement', '13.3.7 a) 4)') do
49 # check that undef is undefining method
50 # based on the method name
51
52 def existing_method_a; true; end
53 def existing_method_b; true; end
54 def existing_method_c; true; end
55 def existing_method_d; true; end
56 def existing_method_e; true; end
57 def existing_method_f; true; end
58
59 # check that methods are defined
60
61 assert_true(existing_method_a, 'Method should be defined')
62 assert_true(existing_method_b, 'Method should be defined')
63 assert_true(existing_method_c, 'Method should be defined')
64 assert_true(existing_method_d, 'Method should be defined')
65 assert_true(existing_method_e, 'Method should be defined')
66 assert_true(existing_method_f, 'Method should be defined')
67
68 # undefine in all possible ways and check that method
69 # is undefined
70
71 undef existing_method_a
72 assert_raise(NoMethodError) do
73 existing_method_a
74 end
75
76 undef :existing_method_b
77 assert_raise(NoMethodError) do
78 existing_method_b
79 end
80
81 undef existing_method_c, existing_method_d
82 assert_raise(NoMethodError) do
83 existing_method_c
84 end
85 assert_raise(NoMethodError) do
86 existing_method_d
87 end
88
89 undef :existing_method_e, :existing_method_f
90 assert_raise(NoMethodError) do
91 existing_method_e
92 end
93 assert_raise(NoMethodError) do
94 existing_method_f
95 end
96end
97
98assert('The undef statement (method undefined)', '13.3.7 a) 5)') do
99 # check that undef is raising NameError if
100 # non-existing method should be undefined
101
102 assert_raise(NameError) do
103 undef non_existing_method
104 end
105
106 assert_raise(NameError) do
107 undef :non_existing_method
108 end
109end
Note: See TracBrowser for help on using the repository browser.