diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 11:19:16 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 12:07:37 +0000 |
commit | b485aab7e71c1625cfc27e0f92c9509f42378458 (patch) | |
tree | ae9abe108601079d1679194de237c9a435ae5b55 /src/web/server/h2o/libh2o/deps/mruby/mrbgems/mruby-object-ext/test | |
parent | Adding upstream version 1.44.3. (diff) | |
download | netdata-b485aab7e71c1625cfc27e0f92c9509f42378458.tar.xz netdata-b485aab7e71c1625cfc27e0f92c9509f42378458.zip |
Adding upstream version 1.45.3+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/web/server/h2o/libh2o/deps/mruby/mrbgems/mruby-object-ext/test')
-rw-r--r-- | src/web/server/h2o/libh2o/deps/mruby/mrbgems/mruby-object-ext/test/nil.rb | 11 | ||||
-rw-r--r-- | src/web/server/h2o/libh2o/deps/mruby/mrbgems/mruby-object-ext/test/object.rb | 53 |
2 files changed, 64 insertions, 0 deletions
diff --git a/src/web/server/h2o/libh2o/deps/mruby/mrbgems/mruby-object-ext/test/nil.rb b/src/web/server/h2o/libh2o/deps/mruby/mrbgems/mruby-object-ext/test/nil.rb new file mode 100644 index 000000000..5cd1cf4ed --- /dev/null +++ b/src/web/server/h2o/libh2o/deps/mruby/mrbgems/mruby-object-ext/test/nil.rb @@ -0,0 +1,11 @@ +assert('NilClass#to_a') do + assert_equal [], nil.to_a +end + +assert('NilClass#to_f') do + assert_equal 0.0, nil.to_f +end + +assert('NilClass#to_i') do + assert_equal 0, nil.to_i +end diff --git a/src/web/server/h2o/libh2o/deps/mruby/mrbgems/mruby-object-ext/test/object.rb b/src/web/server/h2o/libh2o/deps/mruby/mrbgems/mruby-object-ext/test/object.rb new file mode 100644 index 000000000..f0742f8ce --- /dev/null +++ b/src/web/server/h2o/libh2o/deps/mruby/mrbgems/mruby-object-ext/test/object.rb @@ -0,0 +1,53 @@ +assert('Object#instance_exec') do + class KlassWithSecret + def initialize + @secret = 99 + end + end + k = KlassWithSecret.new + assert_equal 104, k.instance_exec(5) {|x| @secret+x } +end + +assert('Object#tap') do + ret = [] + (1..10) .tap {|x| ret << "original: #{x.inspect}"} + .to_a .tap {|x| ret << "array: #{x.inspect}"} + .select {|x| x%2==0} .tap {|x| ret << "evens: #{x.inspect}"} + .map { |x| x*x } .tap {|x| ret << "squares: #{x.inspect}"} + + assert_equal [ + "original: 1..10", + "array: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]", + "evens: [2, 4, 6, 8, 10]", + "squares: [4, 16, 36, 64, 100]" + ], ret + assert_equal(:tap_ok, Class.new {def m; tap{return :tap_ok}; end}.new.m) +end + +assert('instance_exec on primitives with class and module definition') do + begin + class A + 1.instance_exec do + class B + end + end + end + + assert_kind_of Class, A::B + ensure + Object.remove_const :A + end + + begin + class A + 1.instance_exec do + module B + end + end + end + + assert_kind_of Module, A::B + ensure + Object.remove_const :A + end +end |