Update ruby test for colon-style hash inspect

This commit is contained in:
tompng 2024-06-08 00:23:12 +09:00 committed by Yusuke Endoh
parent f4e548924e
commit 7237af75d2
Notes: git 2024-10-03 09:47:29 +00:00
7 changed files with 27 additions and 27 deletions

View File

@ -649,9 +649,9 @@ class TestCoverage < Test::Unit::TestCase
end end
exp = [ exp = [
"{:lines=>[1, 0, 0, nil, 0, nil, nil]}", { lines: [1, 0, 0, nil, 0, nil, nil] }.inspect,
"{:lines=>[0, 1, 1, nil, 0, nil, nil]}", { lines: [0, 1, 1, nil, 0, nil, nil] }.inspect,
"{:lines=>[0, 1, 0, nil, 1, nil, nil]}", { lines: [0, 1, 0, nil, 1, nil, nil] }.inspect,
] ]
assert_in_out_err(ARGV, <<-"end;", exp, []) assert_in_out_err(ARGV, <<-"end;", exp, [])
Coverage.start(lines: true) Coverage.start(lines: true)
@ -682,10 +682,10 @@ class TestCoverage < Test::Unit::TestCase
end end
exp = [ exp = [
"{:branches=>{[:if, 0, 2, 2, 6, 5]=>{[:then, 1, 3, 4, 3, 8]=>0, [:else, 2, 5, 4, 5, 12]=>0}}}", { branches: { [:if, 0, 2, 2, 6, 5] => { [:then, 1, 3, 4, 3, 8] => 0, [:else, 2, 5, 4, 5, 12] => 0 } } }.inspect,
"{:branches=>{[:if, 0, 2, 2, 6, 5]=>{[:then, 1, 3, 4, 3, 8]=>1, [:else, 2, 5, 4, 5, 12]=>0}}}", { branches: { [:if, 0, 2, 2, 6, 5] => { [:then, 1, 3, 4, 3, 8] => 1, [:else, 2, 5, 4, 5, 12] => 0 } } }.inspect,
"{:branches=>{[:if, 0, 2, 2, 6, 5]=>{[:then, 1, 3, 4, 3, 8]=>0, [:else, 2, 5, 4, 5, 12]=>1}}}", { branches: { [:if, 0, 2, 2, 6, 5] => { [:then, 1, 3, 4, 3, 8] => 0, [:else, 2, 5, 4, 5, 12] => 1 } } }.inspect,
"{:branches=>{[:if, 0, 2, 2, 6, 5]=>{[:then, 1, 3, 4, 3, 8]=>0, [:else, 2, 5, 4, 5, 12]=>1}}}", { branches: { [:if, 0, 2, 2, 6, 5] => { [:then, 1, 3, 4, 3, 8] => 0, [:else, 2, 5, 4, 5, 12] => 1 } } }.inspect,
] ]
assert_in_out_err(ARGV, <<-"end;", exp, []) assert_in_out_err(ARGV, <<-"end;", exp, [])
Coverage.start(branches: true) Coverage.start(branches: true)
@ -718,10 +718,10 @@ class TestCoverage < Test::Unit::TestCase
end end
exp = [ exp = [
"{:methods=>{[Object, :foo, 1, 0, 7, 3]=>0}}", { methods: { [Object, :foo, 1, 0, 7, 3] => 0 } }.inspect,
"{:methods=>{[Object, :foo, 1, 0, 7, 3]=>1}}", { methods: { [Object, :foo, 1, 0, 7, 3] => 1 } }.inspect,
"{:methods=>{[Object, :foo, 1, 0, 7, 3]=>1}}", { methods: { [Object, :foo, 1, 0, 7, 3] => 1 } }.inspect,
"{:methods=>{[Object, :foo, 1, 0, 7, 3]=>1}}" { methods: { [Object, :foo, 1, 0, 7, 3] => 1 } }.inspect
] ]
assert_in_out_err(ARGV, <<-"end;", exp, []) assert_in_out_err(ARGV, <<-"end;", exp, [])
Coverage.start(methods: true) Coverage.start(methods: true)
@ -754,10 +754,10 @@ class TestCoverage < Test::Unit::TestCase
end end
exp = [ exp = [
"{:oneshot_lines=>[1]}", { oneshot_lines: [1] }.inspect,
"{:oneshot_lines=>[2, 3]}", { oneshot_lines: [2, 3] }.inspect,
"{:oneshot_lines=>[5]}", { oneshot_lines: [5] }.inspect,
"{:oneshot_lines=>[]}", { oneshot_lines: [] }.inspect,
] ]
assert_in_out_err(ARGV, <<-"end;", exp, []) assert_in_out_err(ARGV, <<-"end;", exp, [])
Coverage.start(oneshot_lines: true) Coverage.start(oneshot_lines: true)

View File

@ -803,7 +803,7 @@ dummy
"puts RubyVM::AbstractSyntaxTree.of(->{ 1 + 2 }, keep_script_lines: true).script_lines", "puts RubyVM::AbstractSyntaxTree.of(->{ 1 + 2 }, keep_script_lines: true).script_lines",
"p SCRIPT_LINES__" "p SCRIPT_LINES__"
] ]
test_stdout = lines + ['{"-e"=>[]}'] test_stdout = lines + ['{"-e" => []}']
assert_in_out_err(["-e", lines.join("\n")], "", test_stdout, []) assert_in_out_err(["-e", lines.join("\n")], "", test_stdout, [])
end end

View File

@ -1128,11 +1128,11 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status|
assert_raise(ArgumentError) {warn("test warning", uplevel: -1)} assert_raise(ArgumentError) {warn("test warning", uplevel: -1)}
assert_in_out_err(["-e", "warn 'ok', uplevel: 1"], '', [], /warning:/) assert_in_out_err(["-e", "warn 'ok', uplevel: 1"], '', [], /warning:/)
warning = capture_warning_warn {warn("test warning", {uplevel: 0})} warning = capture_warning_warn {warn("test warning", {uplevel: 0})}
assert_match(/test warning.*{:uplevel=>0}/m, warning[0]) assert_match(/test warning.*{uplevel: 0}/m, warning[0])
warning = capture_warning_warn {warn("test warning", **{uplevel: 0})} warning = capture_warning_warn {warn("test warning", **{uplevel: 0})}
assert_equal("#{__FILE__}:#{__LINE__-1}: warning: test warning\n", warning[0]) assert_equal("#{__FILE__}:#{__LINE__-1}: warning: test warning\n", warning[0])
warning = capture_warning_warn {warn("test warning", {uplevel: 0}, **{})} warning = capture_warning_warn {warn("test warning", {uplevel: 0}, **{})}
assert_equal("test warning\n{:uplevel=>0}\n", warning[0]) assert_equal("test warning\n{uplevel: 0}\n", warning[0])
assert_raise(ArgumentError) {warn("test warning", foo: 1)} assert_raise(ArgumentError) {warn("test warning", foo: 1)}
end end

View File

@ -2295,7 +2295,7 @@ class TestHashOnly < Test::Unit::TestCase
h = obj.h h = obj.h
h[obj] = true h[obj] = true
assert_equal '{0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5, 6=>6, 7=>7, 8=>8, 9=>9, test=>true}', h.inspect assert_equal '{0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, test => true}', h.inspect
end end
def test_ar2st_delete def test_ar2st_delete
@ -2309,7 +2309,7 @@ class TestHashOnly < Test::Unit::TestCase
h[obj2] = true h[obj2] = true
h.delete obj h.delete obj
assert_equal '{0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5, 6=>6, 7=>7, 8=>8, 9=>9}', h.inspect assert_equal '{0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9}', h.inspect
end end
def test_ar2st_lookup def test_ar2st_lookup

View File

@ -2863,7 +2863,7 @@ class TestKeywordArguments < Test::Unit::TestCase
end end
def test_top_ruby2_keywords def test_top_ruby2_keywords
assert_in_out_err([], <<-INPUT, ["[1, 2, 3]", "{:k=>1}"], []) assert_in_out_err([], <<-INPUT, ["[1, 2, 3]", "{k: 1}"], [])
def bar(*a, **kw) def bar(*a, **kw)
p a, kw p a, kw
end end

View File

@ -1664,7 +1664,7 @@ END
raise a # suppress "unused variable: a" warning raise a # suppress "unused variable: a" warning
end end
assert_raise_with_message(NoMatchingPatternKeyError, "{:a=>0}: key not found: :aa") do assert_raise_with_message(NoMatchingPatternKeyError, "{a: 0}: key not found: :aa") do
{a: 0} => {aa:} {a: 0} => {aa:}
raise aa # suppress "unused variable: aa" warning raise aa # suppress "unused variable: aa" warning
rescue NoMatchingPatternKeyError => e rescue NoMatchingPatternKeyError => e
@ -1673,7 +1673,7 @@ END
raise e raise e
end end
assert_raise_with_message(NoMatchingPatternKeyError, "{:a=>{:b=>0}}: key not found: :bb") do assert_raise_with_message(NoMatchingPatternKeyError, "{a: {b: 0}}: key not found: :bb") do
{a: {b: 0}} => {a: {bb:}} {a: {b: 0}} => {a: {bb:}}
raise bb # suppress "unused variable: bb" warning raise bb # suppress "unused variable: bb" warning
rescue NoMatchingPatternKeyError => e rescue NoMatchingPatternKeyError => e
@ -1682,15 +1682,15 @@ END
raise e raise e
end end
assert_raise_with_message(NoMatchingPatternError, "{:a=>0}: 1 === 0 does not return true") do assert_raise_with_message(NoMatchingPatternError, "{a: 0}: 1 === 0 does not return true") do
{a: 0} => {a: 1} {a: 0} => {a: 1}
end end
assert_raise_with_message(NoMatchingPatternError, "{:a=>0}: {:a=>0} is not empty") do assert_raise_with_message(NoMatchingPatternError, "{a: 0}: {a: 0} is not empty") do
{a: 0} => {} {a: 0} => {}
end end
assert_raise_with_message(NoMatchingPatternError, "[{:a=>0}]: rest of {:a=>0} is not empty") do assert_raise_with_message(NoMatchingPatternError, "[{a: 0}]: rest of {a: 0} is not empty") do
[{a: 0}] => [{**nil}] [{a: 0}] => [{**nil}]
end end
end end

View File

@ -235,7 +235,7 @@ class TestSprintf < Test::Unit::TestCase
def test_hash def test_hash
options = {:capture=>/\d+/} options = {:capture=>/\d+/}
assert_equal("with options {:capture=>/\\d+/}", sprintf("with options %p" % options)) assert_equal("with options #{options.inspect}", sprintf("with options %p" % options))
end end
def test_inspect def test_inspect