source: EcnlProtoTool/trunk/mruby-2.1.1/mrbgems/mruby-symbol-ext/test/symbol.rb@ 439

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

mrubyを2.1.1に更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby;charset=UTF-8
File size: 1.4 KB
Line 
1# coding: utf-8
2##
3# Symbol(Ext) Test
4
5if Symbol.respond_to?(:all_symbols)
6 assert('Symbol.all_symbols') do
7 foo = [:__symbol_test_1, :__symbol_test_2, :__symbol_test_3].sort
8 symbols = Symbol.all_symbols.select{|sym|sym.to_s.include? '__symbol_test'}.sort
9 assert_equal foo, symbols
10 end
11end
12
13%w[size length].each do |n|
14 assert("Symbol##{n}") do
15 assert_equal 5, :hello.__send__(n)
16 assert_equal 4, :"aA\0b".__send__(n)
17 if __ENCODING__ == "UTF-8"
18 assert_equal 8, :"こんにちは世界!".__send__(n)
19 assert_equal 4, :"aあ\0b".__send__(n)
20 else
21 assert_equal 22, :"こんにちは世界!".__send__(n)
22 assert_equal 6, :"aあ\0b".__send__(n)
23 end
24 end
25end
26
27assert("Symbol#capitalize") do
28 assert_equal :Hello, :hello.capitalize
29 assert_equal :Hello, :HELLO.capitalize
30 assert_equal :Hello, :Hello.capitalize
31end
32
33assert("Symbol#downcase") do
34 assert_equal :hello, :hEllO.downcase
35 assert_equal :hello, :hello.downcase
36end
37
38assert("Symbol#upcase") do
39 assert_equal :HELLO, :hEllO.upcase
40 assert_equal :HELLO, :HELLO.upcase
41end
42
43assert("Symbol#casecmp") do
44 assert_equal 0, :HELLO.casecmp(:hEllO)
45 assert_equal 1, :HELLO.casecmp(:hEllN)
46 assert_equal(-1, :HELLO.casecmp(:hEllP))
47 assert_nil :HELLO.casecmp("hEllO")
48end
49
50assert("Symbol#empty?") do
51 assert_true :''.empty?
52end
53
54assert('Symbol#intern') do
55 assert_equal :test, :test.intern
56end
Note: See TracBrowser for help on using the repository browser.