summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorKOBAYASHI Shuji <[email protected]>2019-08-02 17:15:34 +0900
committerKOBAYASHI Shuji <[email protected]>2019-08-02 19:22:08 +0900
commitd1817e77910a2747d2bc602964a5f51a1490a252 (patch)
treec28a69d2f764d4026d38b0b168652d4a8fc57646 /test
parent3bacc302a3b3dd875de87d895cb9b532b522a4f0 (diff)
downloadmruby-d1817e77910a2747d2bc602964a5f51a1490a252.tar.gz
mruby-d1817e77910a2747d2bc602964a5f51a1490a252.zip
Change the `mrb_vformat` specifier `%d` for `int`
It potentially breaks, for example, in the case of `mrb_int` is 64-bit and more smaller type is passed by `%d`. In fact, the problem could become apparent when I used `%d` to `backtrace_location::lineno` in `src/backtrace.c:mrb_unpack_backtrace()` on AppVeyor. Therefore, change `%d` for `int` (not `mrb_int`) so that it can be used mostly without casting.
Diffstat (limited to 'test')
-rw-r--r--test/t/vformat.rb42
1 files changed, 22 insertions, 20 deletions
diff --git a/test/t/vformat.rb b/test/t/vformat.rb
index 2270d6490..d124e92b2 100644
--- a/test/t/vformat.rb
+++ b/test/t/vformat.rb
@@ -30,24 +30,26 @@ assert('mrb_vformat') do
n = TestVFormat::Native
assert_format '', ['']
assert_format 'No specifier!', ['No specifier!']
- assert_format '`c`: C', ['`c`: %c', n[?C]]
- assert_format '`d`: 123', ['`d`: %d', n[123]]
- assert_format '`i`: -83', ['`i`: %i', n[-83]]
- assert_format '`f`: 0.0125', ['`f`: %f', n[0.0125]]
+ assert_format '`c`: C', ['`c`: %c', n.c(?C)]
+ assert_format '`d`: 123', ['`d`: %d', n.d(123)]
+ assert_format '`d`: -79', ['`d`: %d', n.d(-79)]
+ assert_format '`i`: 514', ['`i`: %i', n.i(514)]
+ assert_format '`i`: -83', ['`i`: %i', n.i(-83)]
+ assert_format '`f`: 0.0125', ['`f`: %f', n.f(0.0125)]
assert_format '`t`: NilClass', ['`t`: %t', nil]
assert_format '`t`: FalseClass', ['`t`: %t', false]
assert_format '`t`: TrueClass', ['`t`: %t', true]
assert_format '`t`: Fixnum', ['`t`: %t', 0]
assert_format '`t`: Hash', ['`t`: %t', k: "value"]
assert_format_pattern '#<Class:#<Class:#<Hash:0x*>>>', ['%t', sclass({})]
- assert_format '-Infinity', ['%f', n[-Float::INFINITY]]
- assert_format 'NaN: Not a Number', ['%f: Not a Number', n[Float::NAN]]
- assert_format 'string and length', ['string %l length', n['andante'], n[3]]
- assert_format '`n`: sym', ['`n`: %n', n[:sym]]
- assert_format '%C文字列%', ['%s', n['%C文字列%']]
- assert_format '`C`: Kernel module', ['`C`: %C module', n[Kernel]]
- assert_format '`C`: NilClass', ['`C`: %C', n[nil.class]]
- assert_format_pattern '#<Class:#<String:0x*>>', ['%C', n[sclass("")]]
+ assert_format '-Infinity', ['%f', n.f(-Float::INFINITY)]
+ assert_format 'NaN: Not a Number', ['%f: Not a Number', n.f(Float::NAN)]
+ assert_format 'string and length', ['string %l length', n.s('andante'), n.i(3)]
+ assert_format '`n`: sym', ['`n`: %n', n.n(:sym)]
+ assert_format '%C文字列%', ['%s', n.s('%C文字列%')]
+ assert_format '`C`: Kernel module', ['`C`: %C module', n.C(Kernel)]
+ assert_format '`C`: NilClass', ['`C`: %C', n.C(nil.class)]
+ assert_format_pattern '#<Class:#<String:0x*>>', ['%C', n.C(sclass(""))]
assert_format '`T`: NilClass', ['`T`: %T', nil]
assert_format '`T`: FalseClass', ['`T`: %T', false]
assert_format '`T`: TrueClass', ['`T`: %T', true]
@@ -64,18 +66,18 @@ assert('mrb_vformat') do
assert_format '`v`: 1...3', ['`v`: %v', 1...3]
assert_format '`S`: {:a=>1, "b"=>"c"}', ['`S`: %S', a: 1, "b" => ?c]
assert_format 'percent: %', ['percent: %%']
- assert_format '"I": inspect char', ['%!c: inspect char', n[?I]]
- assert_format '709: inspect mrb_int', ['%!d: inspect mrb_int', n[709]]
- assert_format '"a\x00b\xff"', ['%!l', n["a\000b\xFFc\000d"], n[4]]
- assert_format ':"&.": inspect symbol', ['%!n: inspect symbol', n['&.'.to_sym]]
+ assert_format '"I": inspect char', ['%!c: inspect char', n.c(?I)]
+ assert_format '709: inspect mrb_int', ['%!d: inspect mrb_int', n.i(709)]
+ assert_format '"a\x00b\xff"', ['%!l', n.s("a\000b\xFFc\000d"), n.i(4)]
+ assert_format ':"&.": inspect symbol', ['%!n: inspect symbol', n.n(:'&.')]
assert_format 'inspect "String"', ['inspect %!v', 'String']
assert_format 'inspect Array: [1, :x, {}]', ['inspect Array: %!v', [1,:x,{}]]
- assert_format_pattern '`!C`: #<Class:0x*>', ['`!C`: %!C', n[Class.new]]
- assert_format 'to_s -> to_s: ab,cd', ['to_s -> to_s: %n,%v', n[:ab], 'cd']
+ assert_format_pattern '`!C`: #<Class:0x*>', ['`!C`: %!C', n.C(Class.new)]
+ assert_format 'to_s -> to_s: ab,cd', ['to_s -> to_s: %n,%v', n.n(:ab), 'cd']
assert_format 'to_s -> inspect: x:y', ['to_s -> inspect: %v%!v', 'x', :y]
- assert_format 'inspect -> to_s: "a"b', ['inspect -> to_s: %!v%n', 'a', n[:b]]
+ assert_format 'inspect -> to_s: "a"b', ['inspect -> to_s: %!v%n', 'a', n.n(:b)]
assert_format 'Y -> to_s: nile', ['Y -> to_s: %Y%v', nil, "e"]
- assert_format '"abc":Z', ['%!s%!n', n['abc'], n[:Z]]
+ assert_format '"abc":Z', ['%!s%!n', n.s('abc'), n.n('Z'.to_sym)]
assert_format 'escape: \\%a,b,c,d', ['escape: \\\\\%a,b,\c%v', ',d']
assert_implementation_dependent 'unknown specifier: %^',