mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
hash.c (mrb_hash_to_s): put spaces around =>
CRuby 3.4 puts spaces around `=>` since for example `{:a!=>2}` can be
confusing where to separate tokens. mruby should follow the behavior.
Many tests in `test/t` directory assumed no spaces around `=>`, so we
needed to fix them too.
This commit is contained in:
@@ -433,11 +433,11 @@ SRC
|
||||
tc << {:cmd=>"s"}
|
||||
|
||||
tc << {:cmd=>'p {}', :exp=>'$1 = {}'}
|
||||
tc << {:cmd=>'p {"one"=>1,"two"=>2}', :exp=>'$2 = {"one"=>1, "two"=>2}'}
|
||||
tc << {:cmd=>'p {:eins=>"1", :zwei=>"2", }', :exp=>'$3 = {:eins=>"1", :zwei=>"2"}'}
|
||||
tc << {:cmd=>'p {uno:"one", dos: 2}', :exp=>'$4 = {:uno=>"one", :dos=>2}'}
|
||||
tc << {:cmd=>'p {"one"=>1, :zwei=>2, tres:3}', :exp=>'$5 = {"one"=>1, :zwei=>2, :tres=>3}'}
|
||||
tc << {:cmd=>'p {:foo=>"#{foo}",:bar=>"#{bar}"}', :exp=>'$6 = {:foo=>"foo", :bar=>"bar"}'}
|
||||
tc << {:cmd=>'p {"one"=>1,"two"=>2}', :exp=>'$2 = {"one" => 1, "two" => 2}'}
|
||||
tc << {:cmd=>'p {:eins=>"1", :zwei=>"2",}', :exp=>'$3 = {:eins => "1", :zwei => "2"}'}
|
||||
tc << {:cmd=>'p {uno:"one", dos: 2}', :exp=>'$4 = {:uno => "one", :dos => 2}'}
|
||||
tc << {:cmd=>'p {"one"=>1, :zwei=>2, tres:3}', :exp=>'$5 = {"one" => 1, :zwei => 2, :tres => 3}'}
|
||||
tc << {:cmd=>'p {:foo=>"#{foo}",:bar=>"#{bar}"}', :exp=>'$6 = {:foo => "foo", :bar => "bar"}'}
|
||||
|
||||
BinTest_MrubyBinDebugger.test(src, tc)
|
||||
end
|
||||
|
||||
+1
-1
@@ -1843,7 +1843,7 @@ mrb_hash_to_s(mrb_state *mrb, mrb_value self)
|
||||
mrb_str_cat_str(mrb, ret, mrb_inspect(mrb, entry->key));
|
||||
});
|
||||
mrb_gc_arena_restore(mrb, ai);
|
||||
mrb_str_cat_lit(mrb, ret, "=>");
|
||||
mrb_str_cat_lit(mrb, ret, " => ");
|
||||
h_check_modified(mrb, h, {
|
||||
mrb_str_cat_str(mrb, ret, mrb_inspect(mrb, entry->val));
|
||||
});
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ assert('Array#*', '15.2.12.5.2') do
|
||||
assert_equal([1, 1, 1], [1].*(3))
|
||||
assert_equal([], [1].*(0))
|
||||
assert_equal('abc', ['a', 'b', 'c'].*(''))
|
||||
assert_equal('0, 0, 1, {:foo=>0}', [0, [0, 1], {foo: 0}].*(', '))
|
||||
assert_equal('0, 0, 1, {:foo => 0}', [0, [0, 1], {foo: 0}].*(', '))
|
||||
end
|
||||
|
||||
assert('Array#<<', '15.2.12.5.3') do
|
||||
|
||||
+5
-5
@@ -860,13 +860,13 @@ end
|
||||
h1 = {:s => 0, :a => [1,2], 37 => :b, :d => "del", "c" => nil}
|
||||
h1.shift
|
||||
h1.delete(:d)
|
||||
s1 = ':a=>[1, 2], 37=>:b, "c"=>nil'
|
||||
s1 = ':a => [1, 2], 37 => :b, "c" => nil'
|
||||
h2 = Hash.new(100)
|
||||
|
||||
(1..14).each{h2[_1] = _1 * 2}
|
||||
h2 = {**h2, **h1}
|
||||
s2 = "1=>2, 2=>4, 3=>6, 4=>8, 5=>10, 6=>12, 7=>14, 8=>16, " \
|
||||
"9=>18, 10=>20, 11=>22, 12=>24, 13=>26, 14=>28, #{s1}"
|
||||
s2 = "1 => 2, 2 => 4, 3 => 6, 4 => 8, 5 => 10, 6 => 12, 7 => 14, 8 => 16, " \
|
||||
"9 => 18, 10 => 20, 11 => 22, 12 => 24, 13 => 26, 14 => 28, #{s1}"
|
||||
|
||||
[[h1, s1], [h2, s2]].each do |h, s|
|
||||
assert_equal("{#{s}}", h.__send__(meth))
|
||||
@@ -874,11 +874,11 @@ end
|
||||
hh = {}
|
||||
hh[:recur] = hh
|
||||
h.each{|k, v| hh[k] = v}
|
||||
assert_equal("{:recur=>{...}, #{s}}", hh.__send__(meth))
|
||||
assert_equal("{:recur => {...}, #{s}}", hh.__send__(meth))
|
||||
|
||||
hh = h.dup
|
||||
hh[hh] = :recur
|
||||
assert_equal("{#{s}, {...}=>:recur}", hh.__send__(meth))
|
||||
assert_equal("{#{s}, {...} => :recur}", hh.__send__(meth))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
+1
-1
@@ -233,7 +233,7 @@ ZZZ
|
||||
assert_equal " iii\n", i
|
||||
assert_equal [" j1j\n", " j2j\n", " j\#{3}j\n"], j
|
||||
assert_equal 123, k
|
||||
assert_equal ["x{:x=>\"mm3\\n\"}y\nmm1\n", "mm2\n"], m
|
||||
assert_equal ["x{:x => \"mm3\\n\"}y\nmm1\n", "mm2\n"], m
|
||||
assert_equal ({:x=>"mm3\n"}), m2
|
||||
assert_equal [1, "nn1\n", 3, 4], n
|
||||
assert_equal "a $ q\n $ c $ d", q1
|
||||
|
||||
+2
-3
@@ -1,4 +1,3 @@
|
||||
# coding: utf-8-emacs
|
||||
def sclass(v)
|
||||
class << v
|
||||
self
|
||||
@@ -22,7 +21,7 @@ assert('mrb_vformat') do
|
||||
assert_match '#<Class:#<Class:#<Hash:0x*>>>', vf.v('%t', sclass({}))
|
||||
assert_equal 'string and length', vf.l('string %l length', 'andante', 3)
|
||||
assert_equal '`n`: sym', vf.n('`n`: %n', :sym)
|
||||
assert_equal '%C文字列����%', vf.s('%s', '%C文字列����%')
|
||||
assert_equal '%Cʸ»úÎó¯÷%', vf.s('%s', '%Cʸ»úÎó¯÷%')
|
||||
assert_equal '`C`: Kernel module', vf.C('`C`: %C module', Kernel)
|
||||
assert_equal '`C`: NilClass', vf.C('`C`: %C', nil.class)
|
||||
assert_match '#<Class:#<String:0x*>>', vf.C('%C', sclass(""))
|
||||
@@ -40,7 +39,7 @@ assert('mrb_vformat') do
|
||||
assert_equal 'Class', vf.v('%Y', sclass({}))
|
||||
assert_match '#<Class:#<String:0x*>>', vf.v('%v', sclass(""))
|
||||
assert_equal '`v`: 1...3', vf.v('`v`: %v', 1...3)
|
||||
assert_equal '`S`: {:a=>1, "b"=>"c"}', vf.v('`S`: %S', {a: 1, "b" => ?c})
|
||||
assert_equal '`S`: {:a => 1, "b" => "c"}', vf.v('`S`: %S', {a: 1, "b" => ?c})
|
||||
assert_equal 'percent: %', vf.z('percent: %%')
|
||||
assert_equal '"I": inspect char', vf.c('%!c: inspect char', ?I)
|
||||
assert_equal '709: inspect mrb_int', vf.i('%!d: inspect mrb_int', 709)
|
||||
|
||||
Reference in New Issue
Block a user