diff options
| author | Yukihiro Matz Matsumoto <[email protected]> | 2013-03-01 21:38:02 +0900 |
|---|---|---|
| committer | Yukihiro Matz Matsumoto <[email protected]> | 2013-03-01 21:38:02 +0900 |
| commit | 8d2880bbfe229b7c8df327be2d046820cce07838 (patch) | |
| tree | e0a3d61fd34cfd01fd6db13468d10be5dd9dcfc9 /mrbgems/mruby-struct/test | |
| parent | c0e1fc935c301dd86705d754bcf8493c5200eaf9 (diff) | |
| parent | 99a6de063cc4c4964074b27ad21553043b468368 (diff) | |
| download | mruby-8d2880bbfe229b7c8df327be2d046820cce07838.tar.gz mruby-8d2880bbfe229b7c8df327be2d046820cce07838.zip | |
Merge branch 'pluggable_struct' of https://github.com/mattn/mruby into mattn-pluggable_struct
Diffstat (limited to 'mrbgems/mruby-struct/test')
| -rw-r--r-- | mrbgems/mruby-struct/test/struct.rb | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/mrbgems/mruby-struct/test/struct.rb b/mrbgems/mruby-struct/test/struct.rb new file mode 100644 index 000000000..d79b30c0e --- /dev/null +++ b/mrbgems/mruby-struct/test/struct.rb @@ -0,0 +1,77 @@ +## +# Struct ISO Test + +if Object.const_defined?(:Struct) + assert('Struct', '15.2.18') do + Struct.class == Class + end + + assert('Struct superclass', '15.2.18.2') do + Struct.superclass == Object + end + + assert('Struct.new', '15.2.18.3.1') do + c = Struct.new(:m1, :m2) + c.superclass == Struct and + c.members == [:m1,:m2] + end + + # Check crash bug with Struc.new and no params. + assert('Struct.new', '15.2.18.3.1') do + c = Struct.new() + c.superclass == Struct and c.members == [] + end + + assert('Struct#==', '15.2.18.4.1') do + c = Struct.new(:m1, :m2) + cc1 = c.new(1,2) + cc2 = c.new(1,2) + cc1 == cc2 + end + + assert('Struct#[]', '15.2.18.4.2') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + cc[:m1] == 1 and cc["m2"] == 2 + end + + assert('Struct#[]=', '15.2.18.4.3') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + cc[:m1] = 3 + cc[:m1] == 3 + end + + assert('Struct#each', '15.2.18.4.4') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + a = [] + cc.each{|x| + a << x + } + a[0] == 1 and a[1] == 2 + end + + assert('Struct#each_pair', '15.2.18.4.5') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + a = [] + cc.each_pair{|k,v| + a << [k,v] + } + a[0] == [:m1, 1] and a[1] == [:m2, 2] + end + + assert('Struct#members', '15.2.18.4.6') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + cc.members == [:m1,:m2] + end + + assert('Struct#select', '15.2.18.4.7') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + cc.select{|v| v % 2 == 0} == [2] + end +end + |
