source: EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-object-ext/test/object.rb@ 331

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

prototoolに関連するプロジェクトをnewlibからmuslを使うよう変更・更新
ntshellをnewlibの下位の実装から、muslのsyscallの実装に変更・更新
以下のOSSをアップデート
・mruby-1.3.0
・musl-1.1.18
・onigmo-6.1.3
・tcc-0.9.27
以下のOSSを追加
・openssl-1.1.0e
・curl-7.57.0
・zlib-1.2.11
以下のmrbgemsを追加
・iij/mruby-digest
・iij/mruby-env
・iij/mruby-errno
・iij/mruby-iijson
・iij/mruby-ipaddr
・iij/mruby-mock
・iij/mruby-require
・iij/mruby-tls-openssl

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby;charset=UTF-8
File size: 1.1 KB
Line 
1assert('Object#instance_exec') do
2 class KlassWithSecret
3 def initialize
4 @secret = 99
5 end
6 end
7 k = KlassWithSecret.new
8 assert_equal 104, k.instance_exec(5) {|x| @secret+x }
9end
10
11assert('Object#tap') do
12 ret = []
13 (1..10) .tap {|x| ret << "original: #{x.inspect}"}
14 .to_a .tap {|x| ret << "array: #{x.inspect}"}
15 .select {|x| x%2==0} .tap {|x| ret << "evens: #{x.inspect}"}
16 .map { |x| x*x } .tap {|x| ret << "squares: #{x.inspect}"}
17
18 assert_equal [
19 "original: 1..10",
20 "array: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]",
21 "evens: [2, 4, 6, 8, 10]",
22 "squares: [4, 16, 36, 64, 100]"
23 ], ret
24 assert_equal(:tap_ok, Class.new {def m; tap{return :tap_ok}; end}.new.m)
25end
26
27assert('instance_exec on primitives with class and module definition') do
28 begin
29 class A
30 1.instance_exec do
31 class B
32 end
33 end
34 end
35
36 assert_kind_of Class, A::B
37 ensure
38 Object.remove_const :A
39 end
40
41 begin
42 class A
43 1.instance_exec do
44 module B
45 end
46 end
47 end
48
49 assert_kind_of Module, A::B
50 ensure
51 Object.remove_const :A
52 end
53end
Note: See TracBrowser for help on using the repository browser.