Debian Codegraph @

vendor/mruby-source/mrbgems/mruby-symbol-ext/test/symbol.rb

raw
1 ##
2 # Symbol(Ext) Test
3
4 if Symbol.respond_to?(:all_symbols)
5 assert('Symbol.all_symbols') do
6 foo = [:__symbol_test_1, :__symbol_test_2, :__symbol_test_3].sort
7 symbols = Symbol.all_symbols.select{|sym|sym.to_s.include? '__symbol_test'}.sort
8 assert_equal foo, symbols
9 end
10 end
11
12 %w[size length].each do |n|
13 assert("Symbol##{n}") do
14 assert_equal 5, :hello.__send__(n)
15 assert_equal 4, :"aA\0b".__send__(n)
16 if __ENCODING__ == "UTF-8"
17 assert_equal 8, :"こんにちは世界!".__send__(n)
18 assert_equal 4, :"aあ\0b".__send__(n)
19 else
20 assert_equal 22, :"こんにちは世界!".__send__(n)
21 assert_equal 6, :"aあ\0b".__send__(n)
22 end
23 end
24 end
25
26 assert("Symbol#capitalize") do
27 assert_equal :Hello, :hello.capitalize
28 assert_equal :Hello, :HELLO.capitalize
29 assert_equal :Hello, :Hello.capitalize
30 end
31
32 assert("Symbol#downcase") do
33 assert_equal :hello, :hEllO.downcase
34 assert_equal :hello, :hello.downcase
35 end
36
37 assert("Symbol#upcase") do
38 assert_equal :HELLO, :hEllO.upcase
39 assert_equal :HELLO, :HELLO.upcase
40 end
41
42 assert("Symbol#casecmp") do
43 assert_equal 0, :HELLO.casecmp(:hEllO)
44 assert_equal 1, :HELLO.casecmp(:hEllN)
45 assert_equal(-1, :HELLO.casecmp(:hEllP))
46 assert_nil :HELLO.casecmp("hEllO")
47 end
48
49 assert("Symbol#empty?") do
50 assert_false :'a'.empty?
51 end
52
53 assert('Symbol#intern') do
54 assert_equal :test, :test.intern
55 end