source: EcnlProtoTool/trunk/mruby-2.1.1/test/t/vformat.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: 2.8 KB
Line 
1# coding: utf-8-emacs
2def sclass(v)
3 class << v
4 self
5 end
6end
7
8assert('mrb_vformat') do
9 vf = TestVFormat
10 assert_equal '', vf.z('')
11 assert_equal 'No specifier!', vf.z('No specifier!')
12 assert_equal '`c`: C', vf.c('`c`: %c', ?C)
13 assert_equal '`d`: 123', vf.d('`d`: %d', 123)
14 assert_equal '`d`: -79', vf.d('`d`: %d', -79)
15 assert_equal '`i`: 514', vf.i('`i`: %i', 514)
16 assert_equal '`i`: -83', vf.i('`i`: %i', -83)
17 assert_equal '`t`: NilClass', vf.v('`t`: %t', nil)
18 assert_equal '`t`: FalseClass', vf.v('`t`: %t', false)
19 assert_equal '`t`: TrueClass', vf.v('`t`: %t', true)
20 assert_equal '`t`: Fixnum', vf.v('`t`: %t', 0)
21 assert_equal '`t`: Hash', vf.v('`t`: %t', {k: "value"})
22 assert_match '#<Class:#<Class:#<Hash:0x*>>>', vf.v('%t', sclass({}))
23 assert_equal 'string and length', vf.l('string %l length', 'andante', 3)
24 assert_equal '`n`: sym', vf.n('`n`: %n', :sym)
25 assert_equal '%C文字列õ€•º%', vf.s('%s', '%C文字列õ€•º%')
26 assert_equal '`C`: Kernel module', vf.C('`C`: %C module', Kernel)
27 assert_equal '`C`: NilClass', vf.C('`C`: %C', nil.class)
28 assert_match '#<Class:#<String:0x*>>', vf.C('%C', sclass(""))
29 assert_equal '`T`: NilClass', vf.v('`T`: %T', nil)
30 assert_equal '`T`: FalseClass', vf.v('`T`: %T', false)
31 assert_equal '`T`: TrueClass', vf.v('`T`: %T', true)
32 assert_equal '`T`: Fixnum', vf.v('`T`: %T', 0)
33 assert_equal '`T`: Hash', vf.v('`T`: %T', {k: "value"})
34 assert_match 'Class', vf.v('%T', sclass({}))
35 assert_equal '`Y`: nil', vf.v('`Y`: %Y', nil)
36 assert_equal '`Y`: false', vf.v('`Y`: %Y', false)
37 assert_equal '`Y`: true', vf.v('`Y`: %Y', true)
38 assert_equal '`Y`: Fixnum', vf.v('`Y`: %Y', 0)
39 assert_equal '`Y`: Hash', vf.v('`Y`: %Y', {k: "value"})
40 assert_equal 'Class', vf.v('%Y', sclass({}))
41 assert_match '#<Class:#<String:0x*>>', vf.v('%v', sclass(""))
42 assert_equal '`v`: 1...3', vf.v('`v`: %v', 1...3)
43 assert_equal '`S`: {:a=>1, "b"=>"c"}', vf.v('`S`: %S', {a: 1, "b" => ?c})
44 assert_equal 'percent: %', vf.z('percent: %%')
45 assert_equal '"I": inspect char', vf.c('%!c: inspect char', ?I)
46 assert_equal '709: inspect mrb_int', vf.i('%!d: inspect mrb_int', 709)
47 assert_equal '"a\x00b\xff"', vf.l('%!l', "a\000b\xFFc\000d", 4)
48 assert_equal ':"&.": inspect symbol', vf.n('%!n: inspect symbol', :'&.')
49 assert_equal 'inspect "String"', vf.v('inspect %!v', 'String')
50 assert_equal 'inspect Array: [1, :x, {}]', vf.v('inspect Array: %!v', [1,:x,{}])
51 assert_match '`!C`: #<Class:0x*>', vf.C('`!C`: %!C', Class.new)
52 assert_equal 'escape: \\%a,b,c,d', vf.v('escape: \\\\\%a,b,\c%v', ',d')
53
54 skip unless Object.const_defined?(:Float)
55 assert_equal '`f`: 0.0125', vf.f('`f`: %f', 0.0125)
56 assert_equal '-Infinity', vf.f('%f', -Float::INFINITY)
57 assert_equal 'NaN: Not a Number', vf.f('%f: Not a Number', Float::NAN)
58end
Note: See TracBrowser for help on using the repository browser.