From 399734ee944c2c2fc527f3ea1bb91869848f0329 Mon Sep 17 00:00:00 2001 From: "Abinoam P. Marques Jr" Date: Tue, 4 Jul 2017 23:29:13 -0300 Subject: Fix LineLength warnings from Rubocop --- lib/highline.rb | 25 +++++---- lib/highline/style.rb | 6 ++- test/acceptance/at_echo_false.rb | 3 +- test/test_color_scheme.rb | 18 ++++--- test/test_highline.rb | 82 +++++++++++++++++++++-------- test/test_menu.rb | 10 +++- test/test_string_extension.rb | 9 ++-- test/test_style.rb | 111 +++++++++++++++++++++++---------------- 8 files changed, 173 insertions(+), 91 deletions(-) diff --git a/lib/highline.rb b/lib/highline.rb index be5adda..336949f 100755 --- a/lib/highline.rb +++ b/lib/highline.rb @@ -30,11 +30,11 @@ require "highline/builtin_styles" # # A HighLine object is a "high-level line oriented" shell over an input and an # output stream. HighLine simplifies common console interaction, effectively -# replacing {Kernel#puts} and {Kernel#gets}. User code can simply specify the question to ask -# and any details about user interaction, then leave the rest of the work to -# HighLine. When {HighLine#ask} returns, you'll have the answer you requested, -# even if HighLine had to ask many times, validate results, perform range -# checking, convert types, etc. +# replacing {Kernel#puts} and {Kernel#gets}. User code can simply specify the +# question to ask and any details about user interaction, then leave the rest +# of the work to HighLine. When {HighLine#ask} returns, you'll have the answer +# you requested, even if HighLine had to ask many times, validate results, +# perform range checking, convert types, etc. # # @example Basic usage # cli = HighLine.new @@ -76,7 +76,8 @@ class HighLine end # For checking if the current version of HighLine supports RGB colors - # Usage: HighLine.supports_rgb_color? rescue false # rescue for compatibility with older versions + # Usage: HighLine.supports_rgb_color? rescue false + # using rescue for compatibility with older versions # Note: color usage also depends on HighLine.use_color being set # TODO: Discuss removing this method def supports_rgb_color? @@ -99,7 +100,8 @@ class HighLine # @param indent_size [Integer] indentation size in spaces. # @param indent_level [Integer] how deep is indentated. def initialize(input = $stdin, output = $stdout, - wrap_at = nil, page_at = nil, indent_size = 3, indent_level = 0) + wrap_at = nil, page_at = nil, + indent_size = 3, indent_level = 0) @input = input @output = output @@ -183,8 +185,10 @@ class HighLine # # Raises EOFError if input is exhausted. # - # @param yes_or_no_question [String] a question that accepts yes and no as answers - # @param character [Boolean, :getc] character mode to be passed to Question#character + # @param yes_or_no_question [String] a question that accepts yes and no as + # answers + # @param character [Boolean, :getc] character mode to be passed to + # Question#character # @see Question#character def agree(yes_or_no_question, character = nil) ask(yes_or_no_question, ->(yn) { yn.downcase[0] == 'y' }) do |q| @@ -469,7 +473,8 @@ class HighLine # Creates a new HighLine instance with the same options # def new_scope - self.class.new(@input, @output, @wrap_at, @page_at, @indent_size, @indent_level) + self.class.new(@input, @output, @wrap_at, + @page_at, @indent_size, @indent_level) end private diff --git a/lib/highline/style.rb b/lib/highline/style.rb index 7930f21..aaa0385 100755 --- a/lib/highline/style.rb +++ b/lib/highline/style.rb @@ -155,7 +155,8 @@ class HighLine # @param ansi_number [Integer] ANSI escape code # @return [String] all color codes joined as {.rgb_hex} def self.ansi_rgb_to_hex(ansi_number) - raise "Invalid ANSI rgb code #{ansi_number}" unless (16..231).cover?(ansi_number) + raise "Invalid ANSI rgb code #{ansi_number}" unless + (16..231).cover?(ansi_number) parts = (ansi_number - 16). to_s(6). rjust(3, '0'). @@ -304,7 +305,8 @@ class HighLine private def create_bright_variant(variant_name) - raise "Cannot create a #{name} variant of a style list (#{inspect})" if @list + raise "Cannot create a #{name} variant of a style list (#{inspect})" if + @list new_name = ("#{variant_name}_" + @name.to_s).to_sym new_rgb = if @rgb == [0, 0, 0] diff --git a/test/acceptance/at_echo_false.rb b/test/acceptance/at_echo_false.rb index 0f0226c..3df28fd 100644 --- a/test/acceptance/at_echo_false.rb +++ b/test/acceptance/at_echo_false.rb @@ -19,5 +19,6 @@ HighLine::AcceptanceTest.check do |t| puts "You've entered -> #{answer} <-" end - t.question = "Were the characters adequately hidden when you typed them (y/n)? " + t.question = "Were the characters adequately hidden " \ + "when you typed them (y/n)? " end diff --git a/test/test_color_scheme.rb b/test/test_color_scheme.rb index b4b898a..d29d863 100644 --- a/test/test_color_scheme.rb +++ b/test/test_color_scheme.rb @@ -32,22 +32,27 @@ class TestColorScheme < Minitest::Test HighLine.color_scheme = HighLine::SampleColorScheme.new @terminal.say("This should be <%= color('warning yellow', :warning) %>.") - assert_equal("This should be \e[1m\e[33mwarning yellow\e[0m.\n", @output.string) + assert_equal("This should be \e[1m\e[33mwarning yellow\e[0m.\n", + @output.string) @output.rewind @terminal.say("This should be <%= color('warning yellow', 'warning') %>.") - assert_equal("This should be \e[1m\e[33mwarning yellow\e[0m.\n", @output.string) + assert_equal("This should be \e[1m\e[33mwarning yellow\e[0m.\n", + @output.string) @output.rewind @terminal.say("This should be <%= color('warning yellow', 'WarNing') %>.") - assert_equal("This should be \e[1m\e[33mwarning yellow\e[0m.\n", @output.string) + assert_equal("This should be \e[1m\e[33mwarning yellow\e[0m.\n", + @output.string) @output.rewind # Check that keys are available, and as expected - assert_equal %w[critical error warning notice info debug row_even row_odd].sort, + assert_equal %w[critical error warning notice + info debug row_even row_odd].sort, HighLine.color_scheme.keys.sort - # Color scheme doesn't care if we use symbols or strings, and is case-insensitive + # Color scheme doesn't care if we use symbols or strings. + # And it isn't case-sensitive warning1 = HighLine.color_scheme[:warning] warning2 = HighLine.color_scheme["warning"] warning3 = HighLine.color_scheme[:wArning] @@ -80,7 +85,8 @@ class TestColorScheme < Minitest::Test color_scheme_hash = HighLine.color_scheme.to_hash assert_instance_of Hash, color_scheme_hash - assert_equal %w[critical error warning notice info debug row_even row_odd].sort, + assert_equal %w[critical error warning notice + info debug row_even row_odd].sort, color_scheme_hash.keys.sort assert_instance_of Array, HighLine.color_scheme.definition(:warning) assert_equal %i[bold yellow], HighLine.color_scheme.definition(:warning) diff --git a/test/test_highline.rb b/test/test_highline.rb index fedb54d..a7b9525 100755 --- a/test/test_highline.rb +++ b/test/test_highline.rb @@ -66,14 +66,16 @@ class TestHighLine < Minitest::Test invalid_answers = ["ye", "yuk", "nope", "Oh yes", "Oh no", "Hell no!"] invalid_answers.each do |user_input| - # Each invalid answer, should be followed by a 'y' (as the question is reasked) + # Each invalid answer, should be followed by a 'y' + # (as the question is reasked) @input << "#{user_input}\ny\n" @input.rewind assert_equal true, @terminal.agree("Yes or no? ") # It reasks the question if the answer is invalid - assert_equal "Yes or no? Please enter \"yes\" or \"no\".\nYes or no? ", @output.string + assert_equal "Yes or no? Please enter \"yes\" or \"no\".\nYes or no? ", + @output.string @input.truncate(@input.rewind) @output.truncate(@output.rewind) @@ -131,7 +133,9 @@ class TestHighLine < Minitest::Test assert_instance_of HighLine::String, answer - assert_raises(EOFError) { @terminal.ask("Any input left? ", HighLine::String) } + assert_raises(EOFError) do + @terminal.ask("Any input left? ", HighLine::String) + end end def test_indent @@ -183,7 +187,8 @@ class TestHighLine < Minitest::Test @terminal.indent_level = 2 @output.truncate(@output.rewind) @terminal.say(text) - assert_equal("#{indent}Multi\n#{indent}Line\n#{indent}Indentation\n", @output.string) + assert_equal("#{indent}Multi\n#{indent}Line\n#{indent}Indentation\n", + @output.string) @output.truncate(@output.rewind) @terminal.multi_indent = false @@ -192,7 +197,8 @@ class TestHighLine < Minitest::Test @output.truncate(@output.rewind) @terminal.indent(0, text, true) - assert_equal("#{indent}Multi\n#{indent}Line\n#{indent}Indentation\n", @output.string) + assert_equal("#{indent}Multi\n#{indent}Line\n#{indent}Indentation\n", + @output.string) end def test_newline @@ -423,7 +429,8 @@ class TestHighLine < Minitest::Test q.echo = "*" end assert_equal("you can't see me", answer) - assert_equal("Please enter some hidden text: ****************\n", @output.string) + assert_equal("Please enter some hidden text: ****************\n", + @output.string) end def test_character_reading @@ -473,12 +480,16 @@ class TestHighLine < Minitest::Test @output.truncate(@output.rewind) @terminal.say("This should be <%= RGB_906030 %>rgb_906030<%= CLEAR %>!") - assert_equal("This should be \e[38;5;137mrgb_906030\e[0m!\n", @output.string) + assert_equal("This should be \e[38;5;137mrgb_906030\e[0m!\n", + @output.string) @output.truncate(@output.rewind) - @terminal.say("This should be <%= ON_RGB_C06030 %>on_rgb_c06030<%= CLEAR %>!") - assert_equal("This should be \e[48;5;173mon_rgb_c06030\e[0m!\n", @output.string) + @terminal.say( + "This should be <%= ON_RGB_C06030 %>on_rgb_c06030<%= CLEAR %>!" + ) + assert_equal("This should be \e[48;5;173mon_rgb_c06030\e[0m!\n", + @output.string) # Relying on const_missing assert_instance_of HighLine::Style, HighLine::ON_RGB_C06031_STYLE @@ -491,9 +502,15 @@ class TestHighLine < Minitest::Test @output.truncate(@output.rewind) # Does class method work, too? - @terminal.say("This should be <%= HighLine.color('reverse underlined magenta', :reverse, :underline, :magenta) %>!") - assert_equal("This should be \e[7m\e[4m\e[35mreverse underlined magenta\e[0m!\n", - @output.string) + @terminal.say( + "This should be <%= HighLine.color('reverse underlined magenta', " \ + ":reverse, :underline, :magenta) %>!" + ) + + assert_equal( + "This should be \e[7m\e[4m\e[35mreverse underlined magenta\e[0m!\n", + @output.string + ) @output.truncate(@output.rewind) @@ -617,20 +634,32 @@ class TestHighLine < Minitest::Test def test_uncolor # instance method - assert_equal("This should be reverse underlined magenta!\n", - @terminal.uncolor("This should be \e[7m\e[4m\e[35mreverse underlined magenta\e[0m!\n")) + assert_equal( + "This should be reverse underlined magenta!\n", + @terminal.uncolor( + "This should be \e[7m\e[4m\e[35mreverse underlined magenta\e[0m!\n" + ) + ) @output.truncate(@output.rewind) # class method - assert_equal("This should be reverse underlined magenta!\n", - HighLine.uncolor("This should be \e[7m\e[4m\e[35mreverse underlined magenta\e[0m!\n")) + assert_equal( + "This should be reverse underlined magenta!\n", + HighLine.uncolor( + "This should be \e[7m\e[4m\e[35mreverse underlined magenta\e[0m!\n" + ) + ) @output.truncate(@output.rewind) # RGB color - assert_equal("This should be rgb_906030!\n", - @terminal.uncolor("This should be \e[38;5;137mrgb_906030\e[0m!\n")) + assert_equal( + "This should be rgb_906030!\n", + @terminal.uncolor( + "This should be \e[38;5;137mrgb_906030\e[0m!\n" + ) + ) end def test_grey_is_the_same_of_gray @@ -1122,8 +1151,15 @@ class TestHighLine < Minitest::Test end def test_mode - assert(%w[HighLine::Terminal::IOConsole HighLine::Terminal::NCurses HighLine::Terminal::UnixStty].include?(@terminal.terminal.character_mode), - "#{@terminal.terminal.character_mode} not in list") + main_char_modes = + %w[ HighLine::Terminal::IOConsole + HighLine::Terminal::NCurses + HighLine::Terminal::UnixStty ] + + assert( + main_char_modes.include?(@terminal.terminal.character_mode), + "#{@terminal.terminal.character_mode} not in list" + ) end class NameClass @@ -1605,9 +1641,11 @@ class TestHighLine < Minitest::Test HighLine.track_eof = false begin require 'highline/import' - ask("And now? ") # this will still blow up, nothing available + # this will still blow up, nothing available + ask("And now? ") rescue - refute_equal(EOFError, $ERROR_INFO.class) # but HighLine's safe guards are off + # but HighLine's safe guards are off + refute_equal(EOFError, $ERROR_INFO.class) end HighLine.default_instance = old_instance end diff --git a/test/test_menu.rb b/test/test_menu.rb index 00dfb38..0f91785 100644 --- a/test/test_menu.rb +++ b/test/test_menu.rb @@ -90,7 +90,11 @@ class TestMenu < Minitest::Test # Default: menu.flow = :rows menu.choice "Unicode right single quotation mark: ’" end - assert_equal("1. Unicode right single quotation mark: ’\n? ".encode(@output.external_encoding, undef: :replace), @output.string) + assert_equal( + "1. Unicode right single quotation mark: ’\n? ". + encode(@output.external_encoding, undef: :replace), + @output.string + ) end def test_text_override_index_selects_name @@ -637,7 +641,9 @@ class TestMenu < Minitest::Test prompt = "> " first_asking = "1. exit\n" error_message = "You must choose one of [1, exit].\n" - complete_interaction = first_asking + prompt + error_message + prompt # Same prompt when repeating question + + # Same prompt when repeating question + complete_interaction = first_asking + prompt + error_message + prompt assert_equal complete_interaction, @output.string end diff --git a/test/test_string_extension.rb b/test/test_string_extension.rb index 1460e93..c14383b 100644 --- a/test/test_string_extension.rb +++ b/test/test_string_extension.rb @@ -36,11 +36,14 @@ class TestStringExtension < Minitest::Test def test_Highline_String_is_yaml_serializable require 'yaml' unless Gem::Version.new(YAML::VERSION) < Gem::Version.new("2.0.2") - highline_string = HighLine::String.new("Yaml didn't messed with HighLine::String") + highline_string = + HighLine::String.new("Yaml didn't messed with HighLine::String") yaml_highline_string = highline_string.to_yaml - yaml_loaded_string = YAML.safe_load(yaml_highline_string, [HighLine::String]) + yaml_loaded_string = + YAML.safe_load(yaml_highline_string, [HighLine::String]) - assert_equal "Yaml didn't messed with HighLine::String", yaml_loaded_string + assert_equal "Yaml didn't messed with HighLine::String", + yaml_loaded_string assert_equal highline_string, yaml_loaded_string assert_instance_of HighLine::String, yaml_loaded_string end diff --git a/test/test_style.rb b/test/test_style.rb index a73a35b..a610d9f 100755 --- a/test/test_style.rb +++ b/test/test_style.rb @@ -38,13 +38,16 @@ class TestStyle < Minitest::Test def test_clear_index_reset_code_index_to_builtin code_index = HighLine::Style.code_index - code_index_array = code_index.map { |_code, style_array| style_array }.flatten - expected_code_index_array_size = code_index_array.size - @added_codes_to_index + code_index_array = + code_index.map { |_code, style_array| style_array }.flatten + expected_code_index_array_size = + code_index_array.size - @added_codes_to_index HighLine::Style.clear_index cleared_code_index = HighLine::Style.code_index - cleared_code_index_array = cleared_code_index.map { |_code, style_array| style_array }.flatten + cleared_code_index_array = + cleared_code_index.map { |_code, style_array| style_array }.flatten assert_equal expected_code_index_array_size, cleared_code_index_array.size end @@ -54,7 +57,9 @@ class TestStyle < Minitest::Test new_style = @style1.dup # This will replace @style1 in the indexes s = HighLine.Style(@style1) assert_instance_of HighLine::Style, s - assert_same new_style, s # i.e. s===the latest style created, but not the one searched for + + # i.e. s===the latest style created, but not the one searched for + assert_same new_style, s # Retrieve a style from a new Style (no new Style created) s2 = HighLine::Style.new(name: :bar, code: "\e[97m") @@ -247,9 +252,12 @@ class TestStyle < Minitest::Test assert_equal :s4, HighLine::Style.list[:s4].name assert_equal 'baz', HighLine::Style.list[:s4].code assert_equal 2, HighLine::Style.code_index['baz'].size - assert_same s3, HighLine::Style.code_index['baz'].first # Unchanged from last time - assert_equal :s2, HighLine::Style.code_index['baz'].first.name # Unchanged from last time - assert_equal 'baz', HighLine::Style.code_index['baz'].first.code # Unchanged from last time + + # Unchanged from last time + assert_same s3, HighLine::Style.code_index['baz'].first + assert_equal :s2, HighLine::Style.code_index['baz'].first.name + assert_equal 'baz', HighLine::Style.code_index['baz'].first.code + assert_same s4, HighLine::Style.code_index['baz'].last assert_equal :s4, HighLine::Style.code_index['baz'].last.name assert_equal 'baz', HighLine::Style.code_index['baz'].last.code @@ -333,48 +341,51 @@ class TestStyle < Minitest::Test assert_equal 16 + 1 * 36 + 1 * 6 + 0, HighLine::Style.rgb_number(43, 43, 42) assert_equal 16 + 1 * 36 + 1 * 6 + 1, HighLine::Style.rgb_number(43, 43, 43) - assert_equal 16 + 5 * 36 + 5 * 6 + 5, HighLine::Style.rgb_number(255, 255, 255) + assert_equal 16 + 5 * 36 + 5 * 6 + 5, + HighLine::Style.rgb_number(255, 255, 255) end def test_ansi_rgb_to_hex - assert_equal "000000", HighLine::Style.ansi_rgb_to_hex(16 + 0 * 36 + 0 * 6 + 0) - assert_equal "000000", HighLine::Style.ansi_rgb_to_hex(16 + 0 * 36 + 0 * 6 + 0) - assert_equal "00002b", HighLine::Style.ansi_rgb_to_hex(16 + 0 * 36 + 0 * 6 + 1) + ansi_rgb_to_hex = ->(rgb) { HighLine::Style.ansi_rgb_to_hex(rgb) } - assert_equal "000000", HighLine::Style.ansi_rgb_to_hex(16 + 0 * 36 + 0 * 6 + 0) - assert_equal "000000", HighLine::Style.ansi_rgb_to_hex(16 + 0 * 36 + 0 * 6 + 0) - assert_equal "00002b", HighLine::Style.ansi_rgb_to_hex(16 + 0 * 36 + 0 * 6 + 1) + assert_equal "000000", ansi_rgb_to_hex.call(16 + 0 * 36 + 0 * 6 + 0) + assert_equal "000000", ansi_rgb_to_hex.call(16 + 0 * 36 + 0 * 6 + 0) + assert_equal "00002b", ansi_rgb_to_hex.call(16 + 0 * 36 + 0 * 6 + 1) - assert_equal "002b00", HighLine::Style.ansi_rgb_to_hex(16 + 0 * 36 + 1 * 6 + 0) - assert_equal "002b00", HighLine::Style.ansi_rgb_to_hex(16 + 0 * 36 + 1 * 6 + 0) - assert_equal "002b2b", HighLine::Style.ansi_rgb_to_hex(16 + 0 * 36 + 1 * 6 + 1) + assert_equal "000000", ansi_rgb_to_hex.call(16 + 0 * 36 + 0 * 6 + 0) + assert_equal "000000", ansi_rgb_to_hex.call(16 + 0 * 36 + 0 * 6 + 0) + assert_equal "00002b", ansi_rgb_to_hex.call(16 + 0 * 36 + 0 * 6 + 1) - assert_equal "000000", HighLine::Style.ansi_rgb_to_hex(16 + 0 * 36 + 0 * 6 + 0) - assert_equal "000000", HighLine::Style.ansi_rgb_to_hex(16 + 0 * 36 + 0 * 6 + 0) - assert_equal "00002b", HighLine::Style.ansi_rgb_to_hex(16 + 0 * 36 + 0 * 6 + 1) + assert_equal "002b00", ansi_rgb_to_hex.call(16 + 0 * 36 + 1 * 6 + 0) + assert_equal "002b00", ansi_rgb_to_hex.call(16 + 0 * 36 + 1 * 6 + 0) + assert_equal "002b2b", ansi_rgb_to_hex.call(16 + 0 * 36 + 1 * 6 + 1) - assert_equal "000000", HighLine::Style.ansi_rgb_to_hex(16 + 0 * 36 + 0 * 6 + 0) - assert_equal "000000", HighLine::Style.ansi_rgb_to_hex(16 + 0 * 36 + 0 * 6 + 0) - assert_equal "00002b", HighLine::Style.ansi_rgb_to_hex(16 + 0 * 36 + 0 * 6 + 1) + assert_equal "000000", ansi_rgb_to_hex.call(16 + 0 * 36 + 0 * 6 + 0) + assert_equal "000000", ansi_rgb_to_hex.call(16 + 0 * 36 + 0 * 6 + 0) + assert_equal "00002b", ansi_rgb_to_hex.call(16 + 0 * 36 + 0 * 6 + 1) - assert_equal "002b00", HighLine::Style.ansi_rgb_to_hex(16 + 0 * 36 + 1 * 6 + 0) - assert_equal "002b00", HighLine::Style.ansi_rgb_to_hex(16 + 0 * 36 + 1 * 6 + 0) - assert_equal "002b2b", HighLine::Style.ansi_rgb_to_hex(16 + 0 * 36 + 1 * 6 + 1) + assert_equal "000000", ansi_rgb_to_hex.call(16 + 0 * 36 + 0 * 6 + 0) + assert_equal "000000", ansi_rgb_to_hex.call(16 + 0 * 36 + 0 * 6 + 0) + assert_equal "00002b", ansi_rgb_to_hex.call(16 + 0 * 36 + 0 * 6 + 1) - assert_equal "2b0000", HighLine::Style.ansi_rgb_to_hex(16 + 1 * 36 + 0 * 6 + 0) - assert_equal "2b0000", HighLine::Style.ansi_rgb_to_hex(16 + 1 * 36 + 0 * 6 + 0) - assert_equal "2b002b", HighLine::Style.ansi_rgb_to_hex(16 + 1 * 36 + 0 * 6 + 1) + assert_equal "002b00", ansi_rgb_to_hex.call(16 + 0 * 36 + 1 * 6 + 0) + assert_equal "002b00", ansi_rgb_to_hex.call(16 + 0 * 36 + 1 * 6 + 0) + assert_equal "002b2b", ansi_rgb_to_hex.call(16 + 0 * 36 + 1 * 6 + 1) - assert_equal "2b0000", HighLine::Style.ansi_rgb_to_hex(16 + 1 * 36 + 0 * 6 + 0) - assert_equal "2b0000", HighLine::Style.ansi_rgb_to_hex(16 + 1 * 36 + 0 * 6 + 0) - assert_equal "2b002b", HighLine::Style.ansi_rgb_to_hex(16 + 1 * 36 + 0 * 6 + 1) + assert_equal "2b0000", ansi_rgb_to_hex.call(16 + 1 * 36 + 0 * 6 + 0) + assert_equal "2b0000", ansi_rgb_to_hex.call(16 + 1 * 36 + 0 * 6 + 0) + assert_equal "2b002b", ansi_rgb_to_hex.call(16 + 1 * 36 + 0 * 6 + 1) - assert_equal "2b2b00", HighLine::Style.ansi_rgb_to_hex(16 + 1 * 36 + 1 * 6 + 0) - assert_equal "2b2b00", HighLine::Style.ansi_rgb_to_hex(16 + 1 * 36 + 1 * 6 + 0) - assert_equal "2b2b2b", HighLine::Style.ansi_rgb_to_hex(16 + 1 * 36 + 1 * 6 + 1) + assert_equal "2b0000", ansi_rgb_to_hex.call(16 + 1 * 36 + 0 * 6 + 0) + assert_equal "2b0000", ansi_rgb_to_hex.call(16 + 1 * 36 + 0 * 6 + 0) + assert_equal "2b002b", ansi_rgb_to_hex.call(16 + 1 * 36 + 0 * 6 + 1) + + assert_equal "2b2b00", ansi_rgb_to_hex.call(16 + 1 * 36 + 1 * 6 + 0) + assert_equal "2b2b00", ansi_rgb_to_hex.call(16 + 1 * 36 + 1 * 6 + 0) + assert_equal "2b2b2b", ansi_rgb_to_hex.call(16 + 1 * 36 + 1 * 6 + 1) # 0xd5 is the smallest number where n/255.0*6.0 > 5 - assert_equal "d5d5d5", HighLine::Style.ansi_rgb_to_hex(16 + 5 * 36 + 5 * 6 + 5) + assert_equal "d5d5d5", ansi_rgb_to_hex.call(16 + 5 * 36 + 5 * 6 + 5) end def test_list @@ -400,7 +411,8 @@ class TestStyle < Minitest::Test # Add a Style with an existing name s7 = HighLine::Style.new(name: :s6, code: 'baz') - assert_equal list_size + 2, HighLine::Style.list.size # No net addition to list + # No net addition to list + assert_equal list_size + 2, HighLine::Style.list.size refute_nil HighLine::Style.list[:s6] assert_same s7, HighLine::Style.list[:s6] # New one replaces old one refute_same s6, HighLine::Style.list[:s6] @@ -440,12 +452,18 @@ class TestStyle < Minitest::Test def test_uncolor # Normal color - assert_equal "This should be reverse underlined magenta!\n", - HighLine::Style.uncolor("This should be \e[7m\e[4m\e[35mreverse underlined magenta\e[0m!\n") + assert_equal( + "This should be reverse underlined magenta!\n", + HighLine::Style.uncolor( + "This should be \e[7m\e[4m\e[35mreverse underlined magenta\e[0m!\n" + ) + ) # RGB color - assert_equal "This should be rgb_906030!\n", - HighLine::Style.uncolor("This should be \e[38;5;137mrgb_906030\e[0m!\n") + assert_equal( + "This should be rgb_906030!\n", + HighLine::Style.uncolor("This should be \e[38;5;137mrgb_906030\e[0m!\n") + ) end def test_color @@ -462,7 +480,7 @@ class TestStyle < Minitest::Test assert_equal 0x65, @style4.red assert_equal 0, HighLine::Style(:none).red # Probably reliable assert_equal 0, HighLine::Style(:black).red # Probably reliable - assert_equal 255, HighLine::Style(:bright_magenta).red # Seems to be reliable + assert_equal 255, HighLine::Style(:bright_magenta).red # Seems reliable assert_equal 255, HighLine::Style(:on_none).red # Probably reliable end @@ -532,7 +550,8 @@ class TestStyle < Minitest::Test assert_equal style1_code, @style1.code assert_equal style1_rgb, @style1.rgb - assert_raises(::RuntimeError) { @style3.variant(:new_foo6) } # Can't create a variant of a list style + # Can't create a variant of a list style + assert_raises(::RuntimeError) { @style3.variant(:new_foo6) } end def test_on @@ -552,7 +571,8 @@ class TestStyle < Minitest::Test assert_equal style1_code, @style1.code assert_equal style1_rgb, @style1.rgb - assert_raises(::RuntimeError) { @style3.on } # Can't create a variant of a list style + # Can't create a variant of a list style + assert_raises(::RuntimeError) { @style3.on } end def test_bright @@ -596,7 +616,8 @@ class TestStyle < Minitest::Test assert_equal "\e[154m", s4.code # Changed assert_equal [128, 128, 128], s4.rgb # Changed; special case - assert_raises(::RuntimeError) { @style3.bright } # Can't create a variant of a list style + # Can't create a variant of a list style + assert_raises(::RuntimeError) { @style3.bright } end def test_light_do_the_same_as_bright -- cgit v1.2.1