ruby-changes:65964
From: Nobuyoshi <ko1@a...>
Date: Mon, 26 Apr 2021 21:14:41 +0900 (JST)
Subject: [ruby-changes:65964] 6ddaad606e (master): [ruby/irb] Added assert_equal_with_term
https://git.ruby-lang.org/ruby.git/commit/?id=6ddaad606e From 6ddaad606e99aab254288ef14fffbd34a2e54e16 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Thu, 8 Apr 2021 00:09:30 +0900 Subject: [ruby/irb] Added assert_equal_with_term https://github.com/ruby/irb/commit/b690da96d8 --- test/irb/test_color.rb | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb index a28ae06..b652552 100644 --- a/test/irb/test_color.rb +++ b/test/irb/test_color.rb @@ -105,14 +105,10 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L105 tests.each do |code, result| if colorize_code_supported? - actual = with_term { IRB::Color.colorize_code(code, complete: true) } - assert_equal(result, actual, "Case: IRB::Color.colorize_code(#{code.dump}, complete: true)\nResult: #{humanized_literal(actual)}") - - actual = with_term { IRB::Color.colorize_code(code, complete: false) } - assert_equal(result, actual, "Case: IRB::Color.colorize_code(#{code.dump}, complete: false)\nResult: #{humanized_literal(actual)}") + assert_equal_with_term(result, code, complete: true) + assert_equal_with_term(result, code, complete: false) else - actual = with_term { IRB::Color.colorize_code(code) } - assert_equal(code, actual) + assert_equal_with_term(code, code) end end end @@ -127,8 +123,7 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L123 "'foo' + 'bar" => "#{RED}#{BOLD}'#{CLEAR}#{RED}foo#{CLEAR}#{RED}#{BOLD}'#{CLEAR} + #{RED}#{BOLD}'#{CLEAR}#{RED}#{REVERSE}bar#{CLEAR}", "('foo" => "(#{RED}#{BOLD}'#{CLEAR}#{RED}#{REVERSE}foo#{CLEAR}", }.each do |code, result| - actual = with_term { IRB::Color.colorize_code(code, complete: true) } - assert_equal(result, actual, "Case: colorize_code(#{code.dump}, complete: true)\nResult: #{humanized_literal(actual)}") + assert_equal_with_term(result, code, complete: true) end end @@ -139,16 +134,13 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L134 "('foo" => "(#{RED}#{BOLD}'#{CLEAR}#{RED}foo#{CLEAR}", }.each do |code, result| if colorize_code_supported? - actual = with_term { IRB::Color.colorize_code(code, complete: false) } - assert_equal(result, actual, "Case: colorize_code(#{code.dump}, complete: false)\nResult: #{humanized_literal(actual)}") + assert_equal_with_term(result, code, complete: false) unless complete_option_supported? - actual = with_term { IRB::Color.colorize_code(code, complete: true) } - assert_equal(result, actual, "Case: colorize_code(#{code.dump}, complete: false)\nResult: #{humanized_literal(actual)}") + assert_equal_with_term(result, code, complete: true) end else - actual = with_term { IRB::Color.colorize_code(code) } - assert_equal(code, actual) + assert_equal_with_term(code, code) end end end @@ -200,6 +192,16 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L192 ENV.replace(env) if env end + def assert_equal_with_term(result, code, **opts) + actual = with_term { IRB::Color.colorize_code(code, **opts) } + message = -> { + args = [code.dump] + opts.each {|kwd, val| args << "#{kwd}: #{val}"} + "Case: colorize_code(#{args.join(', ')})\nResult: #{humanized_literal(actual)}" + } + assert_equal(result, actual, message) + end + def humanized_literal(str) str .gsub(CLEAR, '@@@{CLEAR}') -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/