diff options
author | Abinoam P. Marques Jr <abinoam@gmail.com> | 2017-07-05 07:59:41 -0300 |
---|---|---|
committer | Abinoam P. Marques Jr <abinoam@gmail.com> | 2017-07-07 05:31:45 -0300 |
commit | c61eb2098f60a4c631125bd970421de22314c313 (patch) | |
tree | e84d6721c081675469131cc777d3a344c87d17b7 | |
parent | fd5de3951ad12a60da529f6e20250a2627023003 (diff) | |
download | highline-c61eb2098f60a4c631125bd970421de22314c313.tar.gz |
Enforce double quotes on strings
31 files changed, 164 insertions, 159 deletions
diff --git a/.rubocop.yml b/.rubocop.yml index ec7ab64..73faa87 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,7 +12,8 @@ Layout/DotPosition: - leading - trailing -# Enabling! +# Enabling +# -------- Style/CollectionMethods: Description: 'Preferred collection methods.' @@ -23,9 +24,13 @@ Style/StringMethods: Description: 'Checks if configured preferred methods are used over non-preferred.' Enabled: true -# Disabling! +# Disabling +# --------- +# Modifying +# --------- + +# Check quotes usage according to lint rule below. Style/StringLiterals: - Description: 'Checks if uses of quotes match the configured preference.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#consistent-string-literals' - Enabled: false + Enabled: true + EnforcedStyle: double_quotes @@ -17,15 +17,15 @@ platform :ruby do end group :development do - gem 'pronto' - gem 'pronto-poper', require: false - gem 'pronto-reek', require: false - gem 'pronto-rubocop', require: false + gem "pronto" + gem "pronto-poper", require: false + gem "pronto-reek", require: false + gem "pronto-rubocop", require: false # Using strict versions of flay and pronto-flay while # PR https://github.com/mmozuras/pronto-flay/pull/11/files # is not merged - gem 'flay', '2.7.0' - gem 'flog' - gem 'pronto-flay', '0.6.1', require: false + gem "flay", "2.7.0" + gem "flog" + gem "pronto-flay", "0.6.1", require: false end @@ -11,7 +11,7 @@ Rake::TestTask.new do |test| test.libs = %w[lib test] test.verbose = true test.warning = true - test.test_files = FileList['test/test*.rb'] + test.test_files = FileList["test/test*.rb"] end Gem::PackageTask.new(SPEC) do |package| diff --git a/examples/color_scheme.rb b/examples/color_scheme.rb index 1889483..5c00c9a 100644 --- a/examples/color_scheme.rb +++ b/examples/color_scheme.rb @@ -5,8 +5,8 @@ # Created by Jeremy Hinegardner on 2007-01-24 # Copyright 2007 Jeremy Hinegardner. All rights reserved -require 'rubygems' -require 'highline/import' +require "rubygems" +require "highline/import" # Create a color scheme, naming color patterns with symbol names. ft = HighLine::ColorScheme.new do |cs| diff --git a/examples/overwrite.rb b/examples/overwrite.rb index cd02090..22e0544 100644 --- a/examples/overwrite.rb +++ b/examples/overwrite.rb @@ -5,8 +5,8 @@ # Created by Jeremy Hinegardner on 2007-01-24 # Copyright 2007 Jeremy Hinegardner. All rights reserved -require 'rubygems' -require 'highline/import' +require "rubygems" +require "highline/import" puts "Using: #{HighLine.default_instance.terminal.class}" puts diff --git a/examples/repeat_entry.rb b/examples/repeat_entry.rb index 35cdbbd..2052ef9 100644 --- a/examples/repeat_entry.rb +++ b/examples/repeat_entry.rb @@ -16,10 +16,10 @@ end puts "Ok, you did it." pass = ask("<%= key %>: ") do |q| - q.echo = '*' + q.echo = "*" q.verify_match = true - q.gather = { "Enter a password" => '', - "Please type it again for verification" => '' } + q.gather = { "Enter a password" => "", + "Please type it again for verification" => "" } end puts "Your password is now #{pass}!" diff --git a/highline.gemspec b/highline.gemspec index 95b6c60..b0d6009 100644 --- a/highline.gemspec +++ b/highline.gemspec @@ -1,8 +1,8 @@ # coding: utf-8 -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path("../lib", __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'highline/version' +require "highline/version" GEM_VERSION = HighLine::VERSION @@ -14,10 +14,10 @@ SPEC = Gem::Specification.new do |spec| spec.files = `git ls-files`.split("\n") spec.test_files = `git ls-files -- test/*.rb`.split("\n") - spec.has_rdoc = 'yard' + spec.has_rdoc = "yard" spec.extra_rdoc_files = %w[README.md TODO Changelog.md LICENSE] - spec.require_path = 'lib' + spec.require_path = "lib" spec.author = "James Edward Gray II" spec.email = "james@graysoftinc.com" @@ -32,5 +32,5 @@ minutes of work. END_DESC spec.add_development_dependency "code_statistics" - spec.required_ruby_version = '>= 1.9.3' + spec.required_ruby_version = ">= 1.9.3" end diff --git a/lib/highline.rb b/lib/highline.rb index 336949f..4dcdd00 100755 --- a/lib/highline.rb +++ b/lib/highline.rb @@ -191,7 +191,7 @@ class HighLine # 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| + ask(yes_or_no_question, ->(yn) { yn.downcase[0] == "y" }) do |q| q.validate = /\A(?:y(?:es)?|no?)\Z/i q.responses[:not_valid] = 'Please enter "yes" or "no".' q.responses[:ask_on_error] = :question @@ -407,7 +407,7 @@ class HighLine # Outputs indentation with current settings # def indentation - ' ' * @indent_size * @indent_level + " " * @indent_size * @indent_level end # diff --git a/lib/highline/builtin_styles.rb b/lib/highline/builtin_styles.rb index acd06b2..71c2429 100644 --- a/lib/highline/builtin_styles.rb +++ b/lib/highline/builtin_styles.rb @@ -74,11 +74,11 @@ class HighLine BASIC_COLORS.each do |color| bright_color = "BRIGHT_#{color}" colors << bright_color - const_set bright_color + '_STYLE', const_get(color + '_STYLE').bright + const_set bright_color + "_STYLE", const_get(color + "_STYLE").bright light_color = "LIGHT_#{color}" colors << light_color - const_set light_color + '_STYLE', const_get(color + '_STYLE').light + const_set light_color + "_STYLE", const_get(color + "_STYLE").light end # The builtin styles' colors like LIGHT_RED and BRIGHT_BLUE. @@ -115,7 +115,7 @@ class HighLine name.to_s end - style_name = code_name + '_STYLE' + style_name = code_name + "_STYLE" style = Style.rgb(Regexp.last_match(3)) style = style.on if on diff --git a/lib/highline/list_renderer.rb b/lib/highline/list_renderer.rb index be1aa95..8e2d677 100644 --- a/lib/highline/list_renderer.rb +++ b/lib/highline/list_renderer.rb @@ -1,8 +1,8 @@ # coding: utf-8 -require 'highline/template_renderer' -require 'highline/wrapper' -require 'highline/list' +require "highline/template_renderer" +require "highline/wrapper" +require "highline/list" # # This class is a utility for quickly and easily laying out lists diff --git a/lib/highline/menu.rb b/lib/highline/menu.rb index dc8ec93..b1205d8 100644 --- a/lib/highline/menu.rb +++ b/lib/highline/menu.rb @@ -463,7 +463,7 @@ class HighLine elsif selections.is_a?(Hash) value_for_hash_selections(items, selections, details) else - raise ArgumentError, 'selections must be either Array or Hash' + raise ArgumentError, "selections must be either Array or Hash" end end diff --git a/lib/highline/question.rb b/lib/highline/question.rb index b630ef9..f6cccfb 100755 --- a/lib/highline/question.rb +++ b/lib/highline/question.rb @@ -272,10 +272,10 @@ class HighLine # @return [Hash] responses hash def build_responses_new_hash(message_source) { ambiguous_completion: "Ambiguous choice. Please choose one of " + - choice_error_str(message_source) + '.', + choice_error_str(message_source) + ".", invalid_type: "You must enter a valid #{message_source}.", no_completion: "You must choose one of " + - choice_error_str(message_source) + '.', + choice_error_str(message_source) + ".", not_in_range: "Your answer isn't within the expected range " \ "(#{expected_range}).", not_valid: "Your answer isn't valid (must match " \ @@ -608,7 +608,7 @@ class HighLine def choice_error_str(message_source) if message_source.is_a? Array - '[' + message_source.join(', ') + ']' + "[" + message_source.join(", ") + "]" else message_source.inspect end diff --git a/lib/highline/question/answer_converter.rb b/lib/highline/question/answer_converter.rb index 0bd0a78..76558ae 100644 --- a/lib/highline/question/answer_converter.rb +++ b/lib/highline/question/answer_converter.rb @@ -1,6 +1,6 @@ # coding: utf-8 -require 'forwardable' +require "forwardable" class HighLine class Question diff --git a/lib/highline/statement.rb b/lib/highline/statement.rb index 85035e4..35d7961 100644 --- a/lib/highline/statement.rb +++ b/lib/highline/statement.rb @@ -1,8 +1,8 @@ # coding: utf-8 -require 'highline/wrapper' -require 'highline/paginator' -require 'highline/template_renderer' +require "highline/wrapper" +require "highline/paginator" +require "highline/template_renderer" class HighLine # This class handles proper formatting based diff --git a/lib/highline/string_extensions.rb b/lib/highline/string_extensions.rb index 5c50977..1ff56ce 100644 --- a/lib/highline/string_extensions.rb +++ b/lib/highline/string_extensions.rb @@ -35,7 +35,7 @@ class HighLine undef :on if method_defined? :on def on(arg) - color(('on_' + arg.to_s).to_sym) + color(("on_" + arg.to_s).to_sym) end undef :uncolor if method_defined? :uncolor @@ -71,7 +71,7 @@ class HighLine def setup_color_code(*colors) color_code = colors.map do |color| if color.is_a?(Numeric) - format('%02x', color) + format("%02x", color) else color.to_s end diff --git a/lib/highline/style.rb b/lib/highline/style.rb index aaa0385..aeecf4b 100755 --- a/lib/highline/style.rb +++ b/lib/highline/style.rb @@ -106,7 +106,7 @@ class HighLine # HighLine::Style.rgb_hex(9, 10, "11") # => "090a11" def self.rgb_hex(*colors) colors.map do |color| - color.is_a?(Numeric) ? format('%02x', color) : color.to_s + color.is_a?(Numeric) ? format("%02x", color) : color.to_s end.join end @@ -132,7 +132,7 @@ class HighLine # def self.rgb(*colors) hex = rgb_hex(*colors) - name = ('rgb_' + hex).to_sym + name = ("rgb_" + hex).to_sym style = list[name] return style if style @@ -159,7 +159,7 @@ class HighLine (16..231).cover?(ansi_number) parts = (ansi_number - 16). to_s(6). - rjust(3, '0'). + rjust(3, "0"). scan(/./). map { |d| (d.to_i * 255.0 / 6.0).ceil } @@ -180,7 +180,7 @@ class HighLine # @param string [String] # @return [String] def self.uncolor(string) - string.gsub(/\e\[\d+(;\d+)*m/, '') + string.gsub(/\e\[\d+(;\d+)*m/, "") end # Style name @@ -210,7 +210,7 @@ class HighLine @builtin = defn[:builtin] if @rgb hex = self.class.rgb_hex(@rgb) - @name ||= 'rgb_' + hex + @name ||= "rgb_" + hex elsif @list @name ||= @list end @@ -288,7 +288,7 @@ class HighLine # Uses the color as background and return a new style. # @return [Style] def on - new_name = ('on_' + @name.to_s).to_sym + new_name = ("on_" + @name.to_s).to_sym self.class.list[new_name] ||= variant(new_name, increment: 10) end diff --git a/lib/highline/template_renderer.rb b/lib/highline/template_renderer.rb index e77f51a..e948c06 100644 --- a/lib/highline/template_renderer.rb +++ b/lib/highline/template_renderer.rb @@ -1,6 +1,6 @@ # coding: utf-8 -require 'forwardable' +require "forwardable" class HighLine # Renders an erb template taking a {Question} and a {HighLine} instance diff --git a/lib/highline/terminal.rb b/lib/highline/terminal.rb index 5217983..bd8eda1 100755 --- a/lib/highline/terminal.rb +++ b/lib/highline/terminal.rb @@ -32,7 +32,7 @@ class HighLine # Fall back to UnixStty unless terminal - require 'highline/terminal/unix_stty' + require "highline/terminal/unix_stty" terminal = HighLine::Terminal::UnixStty.new(input, output) end @@ -152,12 +152,12 @@ class HighLine # Running on JRuby? def jruby? - defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' + defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby" end # Running on Rubinius? def rubinius? - defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx' + defined?(RUBY_ENGINE) && RUBY_ENGINE == "rbx" end # Running on Windows? diff --git a/lib/highline/terminal/ncurses.rb b/lib/highline/terminal/ncurses.rb index b2e206d..72ffac8 100644 --- a/lib/highline/terminal/ncurses.rb +++ b/lib/highline/terminal/ncurses.rb @@ -6,7 +6,7 @@ class HighLine # @note Code migrated +UNTESTED+ from the old code base to the new # terminal api. class NCurses < Terminal - require 'ffi-ncurses' + require "ffi-ncurses" # (see Terminal#raw_no_echo_mode) def raw_no_echo_mode diff --git a/test/acceptance/acceptance.rb b/test/acceptance/acceptance.rb index 2aa299f..f9eecf6 100644 --- a/test/acceptance/acceptance.rb +++ b/test/acceptance/acceptance.rb @@ -56,10 +56,10 @@ EOF puts report -timestamp = Time.now.strftime('%Y%m%d%H%M%S') +timestamp = Time.now.strftime("%Y%m%d%H%M%S") filename = "highlinetests-#{timestamp}.log" -File.open filename.to_s, 'w+' do |f| +File.open filename.to_s, "w+" do |f| f.puts report end diff --git a/test/acceptance/acceptance_test.rb b/test/acceptance/acceptance_test.rb index be050dd..bc2ef94 100644 --- a/test/acceptance/acceptance_test.rb +++ b/test/acceptance/acceptance_test.rb @@ -1,6 +1,6 @@ # coding: utf-8 -require 'highline/import' +require "highline/import" class HighLine::AcceptanceTest @answers ||= {} diff --git a/test/acceptance/at_color_output_using_erb_templates.rb b/test/acceptance/at_color_output_using_erb_templates.rb index 0af103b..e17df87 100644 --- a/test/acceptance/at_color_output_using_erb_templates.rb +++ b/test/acceptance/at_color_output_using_erb_templates.rb @@ -1,6 +1,6 @@ # coding: utf-8 -require_relative 'acceptance_test' +require_relative "acceptance_test" HighLine::AcceptanceTest.check do |t| t.desc = diff --git a/test/acceptance/at_echo_false.rb b/test/acceptance/at_echo_false.rb index 3df28fd..282ec16 100644 --- a/test/acceptance/at_echo_false.rb +++ b/test/acceptance/at_echo_false.rb @@ -1,6 +1,6 @@ # coding: utf-8 -require_relative 'acceptance_test' +require_relative "acceptance_test" HighLine::AcceptanceTest.check do |t| t.desc = diff --git a/test/acceptance/at_readline.rb b/test/acceptance/at_readline.rb index 93fd652..5167394 100644 --- a/test/acceptance/at_readline.rb +++ b/test/acceptance/at_readline.rb @@ -1,6 +1,6 @@ # coding: utf-8 -require_relative 'acceptance_test' +require_relative "acceptance_test" HighLine::AcceptanceTest.check do |t| t.desc = diff --git a/test/io_console_compatible.rb b/test/io_console_compatible.rb index 83817f3..7ff06f5 100644 --- a/test/io_console_compatible.rb +++ b/test/io_console_compatible.rb @@ -1,7 +1,7 @@ # coding: utf-8 -require 'stringio' -require 'tempfile' +require "stringio" +require "tempfile" # # On tests, we try to simulate input output with diff --git a/test/string_methods.rb b/test/string_methods.rb index 90f92e7..b99d53a 100644 --- a/test/string_methods.rb +++ b/test/string_methods.rb @@ -17,13 +17,13 @@ module StringMethods assert_equal("\e[36mstring\e[0m", @string.cyan) assert_equal("\e[41m\e[5mstring\e[0m\e[0m", @string.blink.on_red) assert_equal("\e[38;5;137mstring\e[0m", @string.color(:rgb_906030)) - assert_equal("\e[38;5;101mstring\e[0m", @string.rgb('606030')) - assert_equal("\e[38;5;107mstring\e[0m", @string.rgb('60', '90', '30')) + assert_equal("\e[38;5;101mstring\e[0m", @string.rgb("606030")) + assert_equal("\e[38;5;107mstring\e[0m", @string.rgb("60", "90", "30")) assert_equal("\e[38;5;107mstring\e[0m", @string.rgb(96, 144, 48)) assert_equal("\e[38;5;173mstring\e[0m", @string.rgb_c06030) assert_equal("\e[48;5;137mstring\e[0m", @string.color(:on_rgb_906030)) - assert_equal("\e[48;5;101mstring\e[0m", @string.on_rgb('606030')) - assert_equal("\e[48;5;107mstring\e[0m", @string.on_rgb('60', '90', '30')) + assert_equal("\e[48;5;101mstring\e[0m", @string.on_rgb("606030")) + assert_equal("\e[48;5;107mstring\e[0m", @string.on_rgb("60", "90", "30")) assert_equal("\e[48;5;107mstring\e[0m", @string.on_rgb(96, 144, 48)) assert_equal("\e[48;5;173mstring\e[0m", @string.on_rgb_c06030) end diff --git a/test/test_helper.rb b/test/test_helper.rb index 79fa1fb..0273900 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,13 +4,13 @@ require "English" # Run code coverage only for mri -require 'simplecov' if RUBY_ENGINE == 'ruby' +require "simplecov" if RUBY_ENGINE == "ruby" # Compatibility module for StringIO, File # and Tempfile. Necessary for some tests. require "io_console_compatible" -require 'highline' +require "highline" debug_message = "Tests will be run under:\n" debug_message << " - #{HighLine.new.terminal.class}\n" debug_message << " - HighLine::VERSION #{HighLine::VERSION}\n" diff --git a/test/test_highline.rb b/test/test_highline.rb index a7b9525..8e9de38 100755 --- a/test/test_highline.rb +++ b/test/test_highline.rb @@ -142,18 +142,18 @@ class TestHighLine < Minitest::Test text = "Testing...\n" @terminal.indent_level = 1 @terminal.say(text) - assert_equal(' ' * 3 + text, @output.string) + assert_equal(" " * 3 + text, @output.string) @output.truncate(@output.rewind) @terminal.indent_level = 3 @terminal.say(text) - assert_equal(' ' * 9 + text, @output.string) + assert_equal(" " * 9 + text, @output.string) @output.truncate(@output.rewind) @terminal.indent_level = 0 @terminal.indent_size = 5 @terminal.indent(2, text) - assert_equal(' ' * 10 + text, @output.string) + assert_equal(" " * 10 + text, @output.string) @output.truncate(@output.rewind) @terminal.indent_level = 0 @@ -161,14 +161,14 @@ class TestHighLine < Minitest::Test @terminal.indent do @terminal.say(text) end - assert_equal(' ' * 4 + text, @output.string) + assert_equal(" " * 4 + text, @output.string) @output.truncate(@output.rewind) @terminal.indent_size = 2 @terminal.indent(3) do |t| t.say(text) end - assert_equal(' ' * 6 + text, @output.string) + assert_equal(" " * 6 + text, @output.string) @output.truncate(@output.rewind) @terminal.indent do |t| @@ -180,10 +180,10 @@ class TestHighLine < Minitest::Test end end end - assert_equal(' ' * 8 + text, @output.string) + assert_equal(" " * 8 + text, @output.string) text = "Multi\nLine\nIndentation\n" - indent = ' ' * 4 + indent = " " * 4 @terminal.indent_level = 2 @output.truncate(@output.rewind) @terminal.say(text) @@ -368,8 +368,8 @@ class TestHighLine < Minitest::Test temp_stdin = Tempfile.new "temp_stdin" temp_stdout = Tempfile.new "temp_stdout" - Readline.input = @input = File.open(temp_stdin.path, 'w+') - Readline.output = @output = File.open(temp_stdout.path, 'w+') + Readline.input = @input = File.open(temp_stdin.path, "w+") + Readline.output = @output = File.open(temp_stdout.path, "w+") @terminal = HighLine.new(@input, @output) @@ -396,8 +396,8 @@ class TestHighLine < Minitest::Test temp_stdin = Tempfile.new "temp_stdin" temp_stdout = Tempfile.new "temp_stdout" - Readline.input = @input = File.open(temp_stdin.path, 'w+') - Readline.output = @output = File.open(temp_stdout.path, 'w+') + Readline.input = @input = File.open(temp_stdin.path, "w+") + Readline.output = @output = File.open(temp_stdout.path, "w+") @terminal = HighLine.new(@input, @output) @@ -445,7 +445,7 @@ class TestHighLine < Minitest::Test end def test_frozen_statement - @terminal.say('This is a frozen statement'.freeze) + @terminal.say("This is a frozen statement".freeze) assert_equal("This is a frozen statement\n", @output.string) end @@ -525,7 +525,7 @@ class TestHighLine < Minitest::Test end def test_color_setting_per_instance - require 'highline/import' + require "highline/import" old_glob_instance = HighLine.default_instance old_setting = HighLine.use_color? @@ -719,7 +719,7 @@ class TestHighLine < Minitest::Test @input.rewind @output.truncate(@output.rewind) - scoped_variable = { "junk.txt" => '20mb' } + scoped_variable = { "junk.txt" => "20mb" } answer = @terminal.ask("Enter a filename: ") do |q| q.confirm = proc do |answer| "Are you sure you want to overwrite #{answer} with size " \ @@ -953,8 +953,8 @@ class TestHighLine < Minitest::Test answer = @terminal.ask("How are things going? ") do |q| q.gather = 3 q.verify_match = true - q.responses[:mismatch] = 'Typing mismatch!' - q.responses[:ask_on_error] = '' + q.responses[:mismatch] = "Typing mismatch!" + q.responses[:ask_on_error] = "" end assert_equal("all work and no play makes jack a dull boy", answer) @@ -967,7 +967,7 @@ class TestHighLine < Minitest::Test answer = @terminal.ask("<%= key %>: ") do |q| q.verify_match = true - q.gather = { "Enter a password" => '', "Please type it again" => '' } + q.gather = { "Enter a password" => "", "Please type it again" => "" } end assert_equal("Password", answer) @@ -978,9 +978,9 @@ class TestHighLine < Minitest::Test answer = @terminal.ask("<%= key %>: ") do |q| q.verify_match = true - q.responses[:mismatch] = 'Typing mismatch!' - q.responses[:ask_on_error] = '' - q.gather = { "Enter a password" => '', "Please type it again" => '' } + q.responses[:mismatch] = "Typing mismatch!" + q.responses[:ask_on_error] = "" + q.gather = { "Enter a password" => "", "Please type it again" => "" } end assert_equal("Password", answer) @@ -1109,7 +1109,7 @@ class TestHighLine < Minitest::Test end def test_lists_with_one_item - items = ['Zero'] + items = ["Zero"] modes = { nil => "Zero\n", :rows => "Zero\n", :inline => "Zero", @@ -1640,7 +1640,7 @@ class TestHighLine < Minitest::Test HighLine.default_instance = HighLine.new(StringIO.new, StringIO.new) HighLine.track_eof = false begin - require 'highline/import' + require "highline/import" # this will still blow up, nothing available ask("And now? ") rescue diff --git a/test/test_menu.rb b/test/test_menu.rb index 0f91785..bdd8fe7 100644 --- a/test/test_menu.rb +++ b/test/test_menu.rb @@ -373,7 +373,7 @@ class TestMenu < Minitest::Test @output.truncate(@output.rewind) @terminal.choose(:load, :save, :quit) do |menu| - menu.layout = '<%= list(menu) %>File Menu: ' + menu.layout = "<%= list(menu) %>File Menu: " end assert_equal("1. load\n2. save\n3. quit\nFile Menu: ", @output.string) end @@ -449,7 +449,7 @@ class TestMenu < Minitest::Test menu.character = :getc end assert_equal(:Save, answer) - assert_equal('a', @input.getc) + assert_equal("a", @input.getc) end def test_select_by @@ -600,7 +600,7 @@ class TestMenu < Minitest::Test assert_equal(selected, 3) # Make sure paging message appeared - assert(@output.string.index('press enter/return to continue or q to stop'), + assert(@output.string.index("press enter/return to continue or q to stop"), "Paging message did not appear.") # Make sure it only appeared once diff --git a/test/test_string_extension.rb b/test/test_string_extension.rb index c14383b..8f97dbe 100644 --- a/test/test_string_extension.rb +++ b/test/test_string_extension.rb @@ -34,7 +34,7 @@ class TestStringExtension < Minitest::Test include StringMethods def test_Highline_String_is_yaml_serializable - require 'yaml' + 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") diff --git a/test/test_style.rb b/test/test_style.rb index a610d9f..f8babbd 100755 --- a/test/test_style.rb +++ b/test/test_style.rb @@ -104,7 +104,7 @@ class TestStyle < Minitest::Test # See below for color scheme tests # Create style from a Hash - s = HighLine.Style(name: :han, code: "blah", rgb: 'phooey') + s = HighLine.Style(name: :han, code: "blah", rgb: "phooey") assert_instance_of HighLine::Style, s assert_equal :han, s.name assert_equal "blah", s.code @@ -158,7 +158,7 @@ class TestStyle < Minitest::Test def test_builtin_foreground_colors_defined HighLine::COLORS.each do |color| - style = HighLine.const_get(color + '_STYLE') + style = HighLine.const_get(color + "_STYLE") assert_instance_of HighLine::Style, style assert_equal color.downcase.to_sym, style.name assert style.builtin @@ -169,18 +169,18 @@ class TestStyle < Minitest::Test def test_builtin_background_colors_defined HighLine::COLORS.each do |color| - style = HighLine.const_get('ON_' + color + '_STYLE') + style = HighLine.const_get("ON_" + color + "_STYLE") assert_instance_of HighLine::Style, style assert_equal "ON_#{color}".downcase.to_sym, style.name assert style.builtin - code = HighLine.const_get('ON_' + color) + code = HighLine.const_get("ON_" + color) assert_instance_of String, code, "Bad code for ON_#{color}" end end def test_builtin_styles_defined HighLine::STYLES.each do |style_constant| - style = HighLine.const_get(style_constant + '_STYLE') + style = HighLine.const_get(style_constant + "_STYLE") assert_instance_of HighLine::Style, style assert_equal style_constant.downcase.to_sym, style.name assert style.builtin @@ -192,41 +192,41 @@ class TestStyle < Minitest::Test def test_index # Add a Style with a new name and code assert_nil HighLine::Style.list[:s1] - assert_nil HighLine::Style.code_index['foo'] - s1 = HighLine::Style.new(name: :s1, code: 'foo') + assert_nil HighLine::Style.code_index["foo"] + s1 = HighLine::Style.new(name: :s1, code: "foo") refute_nil HighLine::Style.list[:s1] assert_same s1, HighLine::Style.list[:s1] assert_equal :s1, HighLine::Style.list[:s1].name - assert_equal 'foo', HighLine::Style.list[:s1].code + assert_equal "foo", HighLine::Style.list[:s1].code styles = HighLine::Style.list.size codes = HighLine::Style.code_index.size - assert_instance_of Array, HighLine::Style.code_index['foo'] - assert_equal 1, HighLine::Style.code_index['foo'].size - assert_same s1, HighLine::Style.code_index['foo'].last - assert_equal :s1, HighLine::Style.code_index['foo'].last.name - assert_equal 'foo', HighLine::Style.code_index['foo'].last.code + assert_instance_of Array, HighLine::Style.code_index["foo"] + assert_equal 1, HighLine::Style.code_index["foo"].size + assert_same s1, HighLine::Style.code_index["foo"].last + assert_equal :s1, HighLine::Style.code_index["foo"].last.name + assert_equal "foo", HighLine::Style.code_index["foo"].last.code # Add another Style with a new name and code assert_nil HighLine::Style.list[:s2] - assert_nil HighLine::Style.code_index['bar'] - s2 = HighLine::Style.new(name: :s2, code: 'bar') + assert_nil HighLine::Style.code_index["bar"] + s2 = HighLine::Style.new(name: :s2, code: "bar") assert_equal styles + 1, HighLine::Style.list.size assert_equal codes + 1, HighLine::Style.code_index.size refute_nil HighLine::Style.list[:s2] assert_same s2, HighLine::Style.list[:s2] assert_equal :s2, HighLine::Style.list[:s2].name - assert_equal 'bar', HighLine::Style.list[:s2].code - assert_instance_of Array, HighLine::Style.code_index['bar'] - assert_equal 1, HighLine::Style.code_index['bar'].size - assert_same s2, HighLine::Style.code_index['bar'].last - assert_equal :s2, HighLine::Style.code_index['bar'].last.name - assert_equal 'bar', HighLine::Style.code_index['bar'].last.code + assert_equal "bar", HighLine::Style.list[:s2].code + assert_instance_of Array, HighLine::Style.code_index["bar"] + assert_equal 1, HighLine::Style.code_index["bar"].size + assert_same s2, HighLine::Style.code_index["bar"].last + assert_equal :s2, HighLine::Style.code_index["bar"].last.name + assert_equal "bar", HighLine::Style.code_index["bar"].last.code # Add a Style with an existing name s3_before = HighLine::Style.list[:s2] refute_nil HighLine::Style.list[:s2] - assert_nil HighLine::Style.code_index['baz'] - s3 = HighLine::Style.new(name: :s2, code: 'baz') + assert_nil HighLine::Style.code_index["baz"] + s3 = HighLine::Style.new(name: :s2, code: "baz") refute_same s2, s3 refute_same s3_before, s3 assert_equal styles + 1, HighLine::Style.list.size @@ -235,32 +235,32 @@ class TestStyle < Minitest::Test assert_same s3, HighLine::Style.list[:s2] refute_same s2, HighLine::Style.list[:s2] assert_equal :s2, HighLine::Style.list[:s2].name - assert_equal 'baz', HighLine::Style.list[:s2].code - assert_instance_of Array, HighLine::Style.code_index['baz'] - assert_equal 1, HighLine::Style.code_index['baz'].size - assert_same s3, HighLine::Style.code_index['baz'].last - assert_equal :s2, HighLine::Style.code_index['baz'].last.name - assert_equal 'baz', HighLine::Style.code_index['baz'].last.code + assert_equal "baz", HighLine::Style.list[:s2].code + assert_instance_of Array, HighLine::Style.code_index["baz"] + assert_equal 1, HighLine::Style.code_index["baz"].size + assert_same s3, HighLine::Style.code_index["baz"].last + assert_equal :s2, HighLine::Style.code_index["baz"].last.name + assert_equal "baz", HighLine::Style.code_index["baz"].last.code # Add a Style with an existing code - assert_equal 1, HighLine::Style.code_index['baz'].size - s4 = HighLine::Style.new(name: :s4, code: 'baz') + assert_equal 1, HighLine::Style.code_index["baz"].size + s4 = HighLine::Style.new(name: :s4, code: "baz") assert_equal styles + 2, HighLine::Style.list.size assert_equal codes + 2, HighLine::Style.code_index.size refute_nil HighLine::Style.list[:s4] assert_same s4, HighLine::Style.list[:s4] 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_equal "baz", HighLine::Style.list[:s4].code + assert_equal 2, HighLine::Style.code_index["baz"].size # 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 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 + 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 end def test_rgb_hex @@ -392,62 +392,62 @@ class TestStyle < Minitest::Test list_size = HighLine::Style.list.size # Add a Style with a new name and code assert_nil HighLine::Style.list[:s5] - s5 = HighLine::Style.new(name: :s5, code: 'foo') + s5 = HighLine::Style.new(name: :s5, code: "foo") refute_nil HighLine::Style.list[:s5] assert_equal list_size + 1, HighLine::Style.list.size refute_nil HighLine::Style.list[:s5] assert_same s5, HighLine::Style.list[:s5] assert_equal :s5, HighLine::Style.list[:s5].name - assert_equal 'foo', HighLine::Style.list[:s5].code + assert_equal "foo", HighLine::Style.list[:s5].code # Add another Style with a new name and code assert_nil HighLine::Style.list[:s6] - s6 = HighLine::Style.new(name: :s6, code: 'bar') + s6 = HighLine::Style.new(name: :s6, code: "bar") assert_equal list_size + 2, HighLine::Style.list.size refute_nil HighLine::Style.list[:s6] assert_same s6, HighLine::Style.list[:s6] assert_equal :s6, HighLine::Style.list[:s6].name - assert_equal 'bar', HighLine::Style.list[:s6].code + assert_equal "bar", HighLine::Style.list[:s6].code # Add a Style with an existing name - s7 = HighLine::Style.new(name: :s6, code: 'baz') + s7 = HighLine::Style.new(name: :s6, code: "baz") # 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] assert_equal :s6, HighLine::Style.list[:s6].name - assert_equal 'baz', HighLine::Style.list[:s6].code + assert_equal "baz", HighLine::Style.list[:s6].code end def test_code_index list_size = HighLine::Style.code_index.size # Add a Style with a new name and code - assert_nil HighLine::Style.code_index['chewie'] - HighLine::Style.new(name: :s8, code: 'chewie') + assert_nil HighLine::Style.code_index["chewie"] + HighLine::Style.new(name: :s8, code: "chewie") assert_equal list_size + 1, HighLine::Style.code_index.size - assert_instance_of Array, HighLine::Style.code_index['chewie'] - assert_equal 1, HighLine::Style.code_index['chewie'].size - assert_equal :s8, HighLine::Style.code_index['chewie'].last.name - assert_equal 'chewie', HighLine::Style.code_index['chewie'].last.code + assert_instance_of Array, HighLine::Style.code_index["chewie"] + assert_equal 1, HighLine::Style.code_index["chewie"].size + assert_equal :s8, HighLine::Style.code_index["chewie"].last.name + assert_equal "chewie", HighLine::Style.code_index["chewie"].last.code # Add another Style with a new name and code - assert_nil HighLine::Style.code_index['c3po'] - HighLine::Style.new(name: :s9, code: 'c3po') + assert_nil HighLine::Style.code_index["c3po"] + HighLine::Style.new(name: :s9, code: "c3po") assert_equal list_size + 2, HighLine::Style.code_index.size - assert_instance_of Array, HighLine::Style.code_index['c3po'] - assert_equal 1, HighLine::Style.code_index['c3po'].size - assert_equal :s9, HighLine::Style.code_index['c3po'].last.name - assert_equal 'c3po', HighLine::Style.code_index['c3po'].last.code + assert_instance_of Array, HighLine::Style.code_index["c3po"] + assert_equal 1, HighLine::Style.code_index["c3po"].size + assert_equal :s9, HighLine::Style.code_index["c3po"].last.name + assert_equal "c3po", HighLine::Style.code_index["c3po"].last.code # Add a Style with an existing code - assert_equal 1, HighLine::Style.code_index['c3po'].size - HighLine::Style.new(name: :s10, code: 'c3po') + assert_equal 1, HighLine::Style.code_index["c3po"].size + HighLine::Style.new(name: :s10, code: "c3po") assert_equal list_size + 2, HighLine::Style.code_index.size - assert_equal 2, HighLine::Style.code_index['c3po'].size - assert_equal :s10, HighLine::Style.code_index['c3po'].last.name - assert_equal 'c3po', HighLine::Style.code_index['c3po'].last.code + assert_equal 2, HighLine::Style.code_index["c3po"].size + assert_equal :s10, HighLine::Style.code_index["c3po"].last.name + assert_equal "c3po", HighLine::Style.code_index["c3po"].last.code end def test_uncolor @@ -510,11 +510,11 @@ class TestStyle < Minitest::Test style1_code = @style1.code style1_rgb = @style1.rgb - s1 = @style1.variant(:new_foo1, code: 'abracadabra') + s1 = @style1.variant(:new_foo1, code: "abracadabra") assert_instance_of HighLine::Style, s1 refute_same @style1, s1 # This is a copy assert_equal :new_foo1, s1.name # Changed - assert_equal 'abracadabra', s1.code # Changed + assert_equal "abracadabra", s1.code # Changed assert_equal [1, 2, 3], s1.rgb # Unchanged s2 = @style1.variant(:new_foo2, increment: -15) @@ -536,7 +536,7 @@ class TestStyle < Minitest::Test refute_same @style1, s4 # This is a copy assert_equal :new_foo4, s4.name # Changed assert_equal "\e[70m", s4.code # 99 (new code) + 15 - assert_equal 'blah', s4.rgb # Changed + assert_equal "blah", s4.rgb # Changed s5 = @style1.variant(:new_foo5) assert_instance_of HighLine::Style, s5 |