summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAbinoam P. Marques Jr <abinoam@gmail.com>2017-06-30 23:53:15 -0300
committerAbinoam P. Marques Jr <abinoam@gmail.com>2017-06-30 23:53:15 -0300
commit97888f5f91f9675ef2f7809fe1cb423abf6099c8 (patch)
treed26f2898b93308ba8a3e12b5fd3b363a46a0ef59 /test
parent7a63996d6eaccbe403c724f40a771e4a48c7ea34 (diff)
downloadhighline-97888f5f91f9675ef2f7809fe1cb423abf6099c8.tar.gz
Rubocop automatic corrections
Diffstat (limited to 'test')
-rw-r--r--test/acceptance/acceptance.rb14
-rw-r--r--test/acceptance/acceptance_test.rb2
-rw-r--r--test/acceptance/at_color_output_using_erb_templates.rb2
-rw-r--r--test/acceptance/at_echo_false.rb2
-rw-r--r--test/acceptance/at_readline.rb8
-rw-r--r--test/io_console_compatible.rb2
-rw-r--r--test/string_methods.rb14
-rw-r--r--test/test_answer_converter.rb6
-rw-r--r--test/test_color_scheme.rb42
-rw-r--r--test/test_helper.rb4
-rwxr-xr-xtest/test_highline.rb623
-rw-r--r--test/test_import.rb14
-rw-r--r--test/test_list.rb36
-rw-r--r--test/test_menu.rb174
-rw-r--r--test/test_paginator.rb12
-rw-r--r--test/test_simulator.rb2
-rw-r--r--test/test_string_extension.rb5
-rw-r--r--test/test_string_highline.rb6
-rwxr-xr-xtest/test_style.rb391
-rw-r--r--test/test_wrapper.rb26
20 files changed, 693 insertions, 692 deletions
diff --git a/test/acceptance/acceptance.rb b/test/acceptance/acceptance.rb
index 5ba6784..2aa299f 100644
--- a/test/acceptance/acceptance.rb
+++ b/test/acceptance/acceptance.rb
@@ -36,8 +36,16 @@ james@grayproductions.net
Date: #{Time.now.utc}
HighLine::VERSION: #{HighLine::VERSION}
Terminal: #{HighLine.default_instance.terminal.class}
-RUBY_DESCRIPTION: #{RUBY_DESCRIPTION rescue 'not available'}
-Readline::VERSION: #{Readline::VERSION rescue 'not availabe'}
+RUBY_DESCRIPTION: #{begin
+ RUBY_DESCRIPTION
+ rescue
+ 'not available'
+ end}
+Readline::VERSION: #{begin
+ Readline::VERSION
+ rescue
+ 'not availabe'
+ end}
ENV['SHELL']: #{ENV['SHELL']}
ENV['TERM']: #{ENV['TERM']}
ENV['TERM_PROGRAM']: #{ENV['TERM_PROGRAM']}
@@ -51,7 +59,7 @@ puts report
timestamp = Time.now.strftime('%Y%m%d%H%M%S')
filename = "highlinetests-#{timestamp}.log"
-File.open "#{filename}", '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 19f6dea..30aceaa 100644
--- a/test/acceptance/acceptance_test.rb
+++ b/test/acceptance/acceptance_test.rb
@@ -5,7 +5,7 @@ require 'highline/import'
class HighLine::AcceptanceTest
@@answers ||= {}
- def self.check(&block)
+ def self.check
caller_file = File.basename(caller[0].split(":")[-3])
test = new
diff --git a/test/acceptance/at_color_output_using_erb_templates.rb b/test/acceptance/at_color_output_using_erb_templates.rb
index c45f264..0af103b 100644
--- a/test/acceptance/at_color_output_using_erb_templates.rb
+++ b/test/acceptance/at_color_output_using_erb_templates.rb
@@ -9,7 +9,7 @@ HighLine::AcceptanceTest.check do |t|
"You should see the word _grass_ " \
"colored in green color"
- t.action = Proc.new do
+ t.action = proc do
say "The <%= color('grass', :green) %> should be green!"
end
diff --git a/test/acceptance/at_echo_false.rb b/test/acceptance/at_echo_false.rb
index 2466b8d..0f0226c 100644
--- a/test/acceptance/at_echo_false.rb
+++ b/test/acceptance/at_echo_false.rb
@@ -12,7 +12,7 @@ HighLine::AcceptanceTest.check do |t|
"When typing the characters you should not " \
"see any of them on the screen."
- t.action = Proc.new do
+ t.action = proc do
answer = ask "Enter some characters and press <enter>: " do |q|
q.echo = false
end
diff --git a/test/acceptance/at_readline.rb b/test/acceptance/at_readline.rb
index 8a66f09..93fd652 100644
--- a/test/acceptance/at_readline.rb
+++ b/test/acceptance/at_readline.rb
@@ -22,12 +22,12 @@ HighLine::AcceptanceTest.check do |t|
"When ready, just type 'exit' and the loop will finish.\n\n" \
"Don't forget to answer 'y' (yes) or 'n' (no) to the question at the end."
- t.action = Proc.new do
+ t.action = proc do
loop do
cmd =
- ask "Enter command: ", %w{ save sample exec exit load } do |q|
- q.readline = true
- end
+ ask "Enter command: ", %w[save sample exec exit load] do |q|
+ q.readline = true
+ end
say("Executing \"#{cmd}\"...")
break if cmd == "exit"
end
diff --git a/test/io_console_compatible.rb b/test/io_console_compatible.rb
index c8e2e70..83817f3 100644
--- a/test/io_console_compatible.rb
+++ b/test/io_console_compatible.rb
@@ -34,4 +34,4 @@ end
class StringIO
include IOConsoleCompatible
-end \ No newline at end of file
+end
diff --git a/test/string_methods.rb b/test/string_methods.rb
index 9c61359..90f92e7 100644
--- a/test/string_methods.rb
+++ b/test/string_methods.rb
@@ -9,25 +9,25 @@
#
# String class convenience methods
-module StringMethods
+module StringMethods
def test_color
assert_equal("\e[34mstring\e[0m", @string.color(:blue))
- assert_equal("\e[1m\e[47mstring\e[0m", @string.color(:bold,:on_white))
+ assert_equal("\e[1m\e[47mstring\e[0m", @string.color(:bold, :on_white))
assert_equal("\e[45mstring\e[0m", @string.on(:magenta))
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;107mstring\e[0m", @string.rgb(96,144,48))
+ 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;107mstring\e[0m", @string.on_rgb(96,144,48))
+ 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
-
+
def test_uncolor
colored_string = HighLine::String("\e[38;5;137mstring\e[0m")
assert_equal "string", colored_string.uncolor
diff --git a/test/test_answer_converter.rb b/test/test_answer_converter.rb
index 5a4497d..47bf33c 100644
--- a/test/test_answer_converter.rb
+++ b/test/test_answer_converter.rb
@@ -12,7 +12,7 @@ class TestAnswerConverter < Minitest::Test
answer_converter = HighLine::Question::AnswerConverter.new(question)
refute_equal "18", answer_converter.convert
- assert_equal 18, answer_converter.convert
+ assert_equal 18, answer_converter.convert
end
def test_float_convertion
@@ -21,6 +21,6 @@ class TestAnswerConverter < Minitest::Test
answer_converter = HighLine::Question::AnswerConverter.new(question)
refute_equal "3.14159", answer_converter.convert
- assert_equal 3.14159, answer_converter.convert
+ assert_equal 3.14159, answer_converter.convert
end
-end \ No newline at end of file
+end
diff --git a/test/test_color_scheme.rb b/test/test_color_scheme.rb
index 9b4d61b..b4b898a 100644
--- a/test/test_color_scheme.rb
+++ b/test/test_color_scheme.rb
@@ -3,7 +3,7 @@
# tc_color_scheme.rb
#
-# Created by Jeremy Hinegardner on 2007-01-24.
+# Created by Jeremy Hinegardner on 2007-01-24.
# Copyright 2007 Jeremy Hinegardner. All rights reserved.
#
# This is Free Software. See LICENSE and COPYING for details.
@@ -22,31 +22,31 @@ class TestColorScheme < Minitest::Test
end
def test_using_color_scheme
- assert_equal(false,HighLine.using_color_scheme?)
+ assert_equal(false, HighLine.using_color_scheme?)
HighLine.color_scheme = HighLine::ColorScheme.new
- assert_equal(true,HighLine.using_color_scheme?)
+ assert_equal(true, HighLine.using_color_scheme?)
end
def test_scheme
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 ["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
warning1 = HighLine.color_scheme[:warning]
warning2 = HighLine.color_scheme["warning"]
@@ -62,7 +62,7 @@ class TestColorScheme < Minitest::Test
# Nonexistent keys return nil
assert_nil HighLine.color_scheme[:nonexistent]
-
+
# Same as above, for definitions
defn1 = HighLine.color_scheme.definition(:warning)
defn2 = HighLine.color_scheme.definition("warning")
@@ -72,23 +72,23 @@ class TestColorScheme < Minitest::Test
assert_instance_of Array, defn2
assert_instance_of Array, defn3
assert_instance_of Array, defn4
- assert_equal [:bold, :yellow], defn1
- assert_equal [:bold, :yellow], defn2
- assert_equal [:bold, :yellow], defn3
- assert_equal [:bold, :yellow], defn4
+ assert_equal %i[bold yellow], defn1
+ assert_equal %i[bold yellow], defn2
+ assert_equal %i[bold yellow], defn3
+ assert_equal %i[bold yellow], defn4
assert_nil HighLine.color_scheme.definition(:nonexistent)
-
+
color_scheme_hash = HighLine.color_scheme.to_hash
assert_instance_of Hash, color_scheme_hash
- assert_equal ["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 [:bold, :yellow], HighLine.color_scheme.definition(:warning)
+ assert_equal %i[bold yellow], HighLine.color_scheme.definition(:warning)
# turn it back off, should raise an exception
HighLine.color_scheme = nil
- assert_raises(NameError) {
+ assert_raises(NameError) do
@terminal.say("This should be <%= color('nothing at all', :error) %>.")
- }
+ end
end
-end
+end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 65c7646..48c0ff0 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -13,9 +13,7 @@ debug_message = "Tests will be run under:\n"
debug_message << " - #{HighLine.new.terminal.class}\n"
debug_message << " - HighLine::VERSION #{HighLine::VERSION}\n"
-if defined? RUBY_DESCRIPTION
- debug_message << " - #{RUBY_DESCRIPTION}\n"
-end
+debug_message << " - #{RUBY_DESCRIPTION}\n" if defined? RUBY_DESCRIPTION
puts debug_message
diff --git a/test/test_highline.rb b/test/test_highline.rb
index 76ed572..a58d412 100755
--- a/test/test_highline.rb
+++ b/test/test_highline.rb
@@ -15,27 +15,25 @@ require "stringio"
require "readline"
require "tempfile"
-=begin
-if HighLine::CHARACTER_MODE == "Win32API"
- class HighLine
- # Override Windows' character reading so it's not tied to STDIN.
- def get_character( input = STDIN )
- input.getc
- end
- end
-end
-=end
+# if HighLine::CHARACTER_MODE == "Win32API"
+# class HighLine
+# # Override Windows' character reading so it's not tied to STDIN.
+# def get_character( input = STDIN )
+# input.getc
+# end
+# end
+# end
class TestHighLine < Minitest::Test
def setup
HighLine.reset
@input = StringIO.new
@output = StringIO.new
- @terminal = HighLine.new(@input, @output)
+ @terminal = HighLine.new(@input, @output)
end
-
+
def test_agree_valid_yes_answers
- valid_yes_answers = %w{ y yes Y YES }
+ valid_yes_answers = %w[y yes Y YES]
valid_yes_answers.each do |user_input|
@input << "#{user_input}\n"
@@ -50,7 +48,7 @@ class TestHighLine < Minitest::Test
end
def test_agree_valid_no_answers
- valid_no_answers = %w{ n no N NO }
+ valid_no_answers = %w[n no N NO]
valid_no_answers.each do |user_input|
@input << "#{user_input}\n"
@@ -65,7 +63,7 @@ class TestHighLine < Minitest::Test
end
def test_agree_invalid_answers
- invalid_answers = [ "ye", "yuk", "nope", "Oh yes", "Oh no", "Hell no!"]
+ 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)
@@ -89,7 +87,7 @@ class TestHighLine < Minitest::Test
assert_equal(true, @terminal.agree("Yes or no? ", :getc))
end
-
+
def test_agree_with_block
@input << "\n\n"
@input.rewind
@@ -97,17 +95,17 @@ class TestHighLine < Minitest::Test
assert_equal(true, @terminal.agree("Yes or no? ") { |q| q.default = "y" })
assert_equal(false, @terminal.agree("Yes or no? ") { |q| q.default = "n" })
end
-
+
def test_ask
name = "James Edward Gray II"
@input << name << "\n"
@input.rewind
assert_equal(name, @terminal.ask("What is your name? "))
-
+
assert_raises(EOFError) { @terminal.ask("Any input left? ") }
end
-
+
def test_ask_string
name = "James Edward Gray II"
@input << name << "\n"
@@ -138,51 +136,51 @@ class TestHighLine < Minitest::Test
def test_indent
text = "Testing...\n"
- @terminal.indent_level=1
+ @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.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_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
- @terminal.indent_size=4
- @terminal.indent {
+ @terminal.indent_level = 0
+ @terminal.indent_size = 4
+ @terminal.indent do
@terminal.say(text)
- }
- assert_equal(' '*4+text, @output.string)
+ end
+ assert_equal(' ' * 4 + text, @output.string)
@output.truncate(@output.rewind)
- @terminal.indent_size=2
- @terminal.indent(3) { |t|
+ @terminal.indent_size = 2
+ @terminal.indent(3) do |t|
t.say(text)
- }
- assert_equal(' '*6+text, @output.string)
+ end
+ assert_equal(' ' * 6 + text, @output.string)
@output.truncate(@output.rewind)
- @terminal.indent { |t|
- t.indent {
- t.indent {
- t.indent { |tt|
+ @terminal.indent do |t|
+ t.indent do
+ t.indent do
+ t.indent do |tt|
tt.say(text)
- }
- }
- }
- }
- assert_equal(' '*8+text, @output.string)
+ end
+ end
+ end
+ end
+ assert_equal(' ' * 8 + text, @output.string)
text = "Multi\nLine\nIndentation\n"
- indent = ' '*4
- @terminal.indent_level=2
+ indent = ' ' * 4
+ @terminal.indent_level = 2
@output.truncate(@output.rewind)
@terminal.say(text)
assert_equal("#{indent}Multi\n#{indent}Line\n#{indent}Indentation\n", @output.string)
@@ -196,7 +194,7 @@ class TestHighLine < Minitest::Test
@terminal.indent(0, text, true)
assert_equal("#{indent}Multi\n#{indent}Line\n#{indent}Indentation\n", @output.string)
end
-
+
def test_newline
@terminal.newline
@terminal.newline
@@ -208,37 +206,37 @@ class TestHighLine < Minitest::Test
@input << "ruby\nRuby\n"
@input.rewind
- languages = [:Perl, :Python, :Ruby]
- answer = @terminal.ask( "What is your favorite programming language? ",
- languages )
+ languages = %i[Perl Python Ruby]
+ answer = @terminal.ask("What is your favorite programming language? ",
+ languages)
assert_equal(languages.last, answer)
@input.truncate(@input.rewind)
@input << "ruby\n"
@input.rewind
- answer = @terminal.ask( "What is your favorite programming language? ",
- languages ) do |q|
+ answer = @terminal.ask("What is your favorite programming language? ",
+ languages) do |q|
q.case = :capitalize
end
assert_equal(languages.last, answer)
-
+
# poor auto-complete error message
@input.truncate(@input.rewind)
@input << "lisp\nruby\n"
@input.rewind
@output.truncate(@output.rewind)
- answer = @terminal.ask( "What is your favorite programming language? ",
- languages ) do |q|
+ answer = @terminal.ask("What is your favorite programming language? ",
+ languages) do |q|
q.case = :capitalize
end
assert_equal(languages.last, answer)
- assert_equal( "What is your favorite programming language? " +
- "You must choose one of [Perl, Python, Ruby].\n" +
- "? ", @output.string )
+ assert_equal("What is your favorite programming language? " \
+ "You must choose one of [Perl, Python, Ruby].\n" \
+ "? ", @output.string)
end
-
+
def test_case_changes
@input << "jeg2\n"
@input.rewind
@@ -302,8 +300,8 @@ class TestHighLine < Minitest::Test
@input.rewind
@output.truncate(@output.rewind)
- answer = @terminal.ask( "Select an option (1, 2 or 3): ",
- Integer ) do |q|
+ answer = @terminal.ask("Select an option (1, 2 or 3): ",
+ Integer) do |q|
q.echo = "*"
q.character = true
end
@@ -312,33 +310,33 @@ class TestHighLine < Minitest::Test
end
def test_backspace_does_not_enter_prompt
- @input << "\b\b"
- @input.rewind
- answer = @terminal.ask("Please enter your password: ") do |q|
- q.echo = "*"
- end
- assert_equal("", answer)
- assert_equal("Please enter your password: \n", @output.string)
+ @input << "\b\b"
+ @input.rewind
+ answer = @terminal.ask("Please enter your password: ") do |q|
+ q.echo = "*"
+ end
+ assert_equal("", answer)
+ assert_equal("Please enter your password: \n", @output.string)
end
def test_after_some_chars_backspace_does_not_enter_prompt_when_ascii
- @input << "apple\b\b\b\b\b\b\b\b\b\b"
- @input.rewind
- answer = @terminal.ask("Please enter your password: ") do |q|
- q.echo = "*"
- end
- assert_equal("", answer)
- assert_equal("apple".size, @output.string.count("\b"))
+ @input << "apple\b\b\b\b\b\b\b\b\b\b"
+ @input.rewind
+ answer = @terminal.ask("Please enter your password: ") do |q|
+ q.echo = "*"
+ end
+ assert_equal("", answer)
+ assert_equal("apple".size, @output.string.count("\b"))
end
def test_after_some_chars_backspace_does_not_enter_prompt_when_utf8
- @input << "maçã\b\b\b\b\b\b\b\b"
- @input.rewind
- answer = @terminal.ask("Please enter your password: ") do |q|
- q.echo = "*"
- end
- assert_equal("", answer)
- assert_equal("maçã".size, @output.string.count("\b"))
+ @input << "maçã\b\b\b\b\b\b\b\b"
+ @input.rewind
+ answer = @terminal.ask("Please enter your password: ") do |q|
+ q.echo = "*"
+ end
+ assert_equal("", answer)
+ assert_equal("maçã".size, @output.string.count("\b"))
end
def test_readline_mode
@@ -353,7 +351,7 @@ class TestHighLine < Minitest::Test
terminal = @terminal.terminal
- if terminal.jruby? or terminal.rubinius? or terminal.windows?
+ if terminal.jruby? || terminal.rubinius? || terminal.windows?
skip "We can't test Readline on JRuby, Rubinius and Windows yet"
end
@@ -427,7 +425,7 @@ class TestHighLine < Minitest::Test
assert_equal("you can't see me", answer)
assert_equal("Please enter some hidden text: ****************\n", @output.string)
end
-
+
def test_character_reading
# WARNING: This method does NOT cover Unix and Windows savvy testing!
@input << "12345"
@@ -450,10 +448,10 @@ class TestHighLine < Minitest::Test
@output.truncate(@output.rewind)
- @terminal.say( "This should be " +
- "<%= BOLD + ON_WHITE %>bold on white<%= CLEAR %>!" )
- assert_equal( "This should be \e[1m\e[47mbold on white\e[0m!\n",
- @output.string )
+ @terminal.say("This should be " \
+ "<%= BOLD + ON_WHITE %>bold on white<%= CLEAR %>!")
+ assert_equal("This should be \e[1m\e[47mbold on white\e[0m!\n",
+ @output.string)
@output.truncate(@output.rewind)
@@ -462,10 +460,10 @@ class TestHighLine < Minitest::Test
@output.truncate(@output.rewind)
- @terminal.say( "This should be " +
- "<%= color('blinking on red', :blink, :on_red) %>!" )
- assert_equal( "This should be \e[5m\e[41mblinking on red\e[0m!\n",
- @output.string )
+ @terminal.say("This should be " \
+ "<%= color('blinking on red', :blink, :on_red) %>!")
+ assert_equal("This should be \e[5m\e[41mblinking on red\e[0m!\n",
+ @output.string)
@output.truncate(@output.rewind)
@@ -484,18 +482,18 @@ class TestHighLine < Minitest::Test
# Relying on const_missing
assert_instance_of HighLine::Style, HighLine::ON_RGB_C06031_STYLE
- assert_instance_of String , HighLine::ON_RGB_C06032
- assert_raises(NameError) { HighLine::ON_RGB_ZZZZZZ }
+ assert_instance_of String, HighLine::ON_RGB_C06032
+ assert_raises(NameError) { HighLine::ON_RGB_ZZZZZZ }
# Retrieving color_code from a style
assert_equal "\e[41m", @terminal.color_code([HighLine::ON_RED_STYLE])
@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 )
+ assert_equal("This should be \e[7m\e[4m\e[35mreverse underlined magenta\e[0m!\n",
+ @output.string)
@output.truncate(@output.rewind)
@@ -592,7 +590,7 @@ class TestHighLine < Minitest::Test
assert_equal("This should be \e[36mcyan\e[0m!\n", @output.string)
cli.say("This should be <%= color('cyan', CYAN) %>!")
- assert_equal("This should be cyan!\n", cli_output.string )
+ assert_equal("This should be cyan!\n", cli_output.string)
gterm_output.truncate(gterm_output.rewind)
@output.truncate(@output.rewind)
@@ -619,23 +617,20 @@ 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
@@ -661,7 +656,7 @@ class TestHighLine < Minitest::Test
assert_equal bright_blue_code, light_blue_code
end
-
+
def test_confirm
@input << "junk.txt\nno\nsave.txt\ny\n"
@input.rewind
@@ -671,11 +666,11 @@ class TestHighLine < Minitest::Test
q.responses[:ask_on_error] = :question
end
assert_equal("save.txt", answer)
- assert_equal( "Enter a filename: " +
- "Are you sure you want to overwrite junk.txt? " +
- "Enter a filename: " +
+ assert_equal("Enter a filename: " \
+ "Are you sure you want to overwrite junk.txt? " \
+ "Enter a filename: " \
"Are you sure you want to overwrite save.txt? ",
- @output.string )
+ @output.string)
@input.truncate(@input.rewind)
@input << "junk.txt\nyes\nsave.txt\nn\n"
@@ -686,9 +681,9 @@ class TestHighLine < Minitest::Test
q.confirm = "Are you sure you want to overwrite <%= answer %>? "
end
assert_equal("junk.txt", answer)
- assert_equal( "Enter a filename: " +
+ assert_equal("Enter a filename: " \
"Are you sure you want to overwrite junk.txt? ",
- @output.string )
+ @output.string)
@input.truncate(@input.rewind)
@input << "junk.txt\nyes\nsave.txt\nn\n"
@@ -697,18 +692,18 @@ class TestHighLine < Minitest::Test
scoped_variable = { "junk.txt" => '20mb' }
answer = @terminal.ask("Enter a filename: ") do |q|
- q.confirm = Proc.new do |answer|
- "Are you sure you want to overwrite #{answer} with size " +
- "of #{scoped_variable[answer]}? "
+ q.confirm = proc do |answer|
+ "Are you sure you want to overwrite #{answer} with size " \
+ "of #{scoped_variable[answer]}? "
end
end
assert_equal("junk.txt", answer)
- assert_equal( "Enter a filename: " +
- "Are you sure you want to overwrite junk.txt " +
+ assert_equal("Enter a filename: " \
+ "Are you sure you want to overwrite junk.txt " \
"with size of 20mb? ",
- @output.string )
+ @output.string)
end
-
+
def test_generic_confirm_with_true
@input << "junk.txt\nno\nsave.txt\ny\n"
@input.rewind
@@ -718,11 +713,11 @@ class TestHighLine < Minitest::Test
q.responses[:ask_on_error] = :question
end
assert_equal("save.txt", answer)
- assert_equal( "Enter a filename: " +
- "Are you sure? " +
- "Enter a filename: " +
+ assert_equal("Enter a filename: " \
+ "Are you sure? " \
+ "Enter a filename: " \
"Are you sure? ",
- @output.string )
+ @output.string)
@input.truncate(@input.rewind)
@input << "junk.txt\nyes\nsave.txt\nn\n"
@@ -733,9 +728,9 @@ class TestHighLine < Minitest::Test
q.confirm = true
end
assert_equal("junk.txt", answer)
- assert_equal( "Enter a filename: " +
+ assert_equal("Enter a filename: " \
"Are you sure? ",
- @output.string )
+ @output.string)
end
def test_defaults
@@ -757,8 +752,8 @@ class TestHighLine < Minitest::Test
q.validate = /\Ay(?:es)?|no?|no comment\Z/i
end
assert_equal("No Comment", answer)
- assert_equal( "Are you sexually active? |No Comment| ",
- @output.string )
+ assert_equal("Are you sexually active? |No Comment| ",
+ @output.string)
end
def test_default_with_String
@@ -828,24 +823,24 @@ class TestHighLine < Minitest::Test
end
assert_equal("yes", answer)
end
-
+
def test_erb
- @terminal.say( "The integers from 1 to 10 are:\n" +
- "% (1...10).each do |n|\n" +
- "\t<%= n %>,\n" +
- "% end\n" +
- "\tand 10" )
- assert_equal( "The integers from 1 to 10 are:\n" +
- "\t1,\n\t2,\n\t3,\n\t4,\n\t5,\n" +
+ @terminal.say("The integers from 1 to 10 are:\n" \
+ "% (1...10).each do |n|\n" \
+ "\t<%= n %>,\n" \
+ "% end\n" \
+ "\tand 10")
+ assert_equal("The integers from 1 to 10 are:\n" \
+ "\t1,\n\t2,\n\t3,\n\t4,\n\t5,\n" \
"\t6,\n\t7,\n\t8,\n\t9,\n\tand 10\n",
- @output.string )
+ @output.string)
end
-
+
def test_files
@input << "#{File.basename(__FILE__)[0, 7]}\n"
@input.rewind
-
- assert_equal "test_hi\n",@input.read
+
+ assert_equal "test_hi\n", @input.read
@input.rewind
file = @terminal.ask("Select a file: ", File) do |q|
@@ -865,7 +860,7 @@ class TestHighLine < Minitest::Test
assert_instance_of(Pathname, pathname)
assert_equal(File.size(__FILE__), pathname.size)
end
-
+
def test_gather_with_integer
@input << "James\nDana\nStorm\nGypsy\n\n"
@input.rewind
@@ -873,7 +868,7 @@ class TestHighLine < Minitest::Test
answers = @terminal.ask("Enter four names:") do |q|
q.gather = 4
end
- assert_equal(%w{James Dana Storm Gypsy}, answers)
+ assert_equal(%w[James Dana Storm Gypsy], answers)
assert_equal("\n", @input.gets)
assert_equal("Enter four names:\n", @output.string)
end
@@ -885,7 +880,7 @@ class TestHighLine < Minitest::Test
answers = @terminal.ask("Enter four names:") do |q|
q.gather = ""
end
- assert_equal(%w{James Dana Storm Gypsy}, answers)
+ assert_equal(%w[James Dana Storm Gypsy], answers)
end
def test_gather_with_regexp
@@ -895,7 +890,7 @@ class TestHighLine < Minitest::Test
answers = @terminal.ask("Enter four names:") do |q|
q.gather = /^\s*$/
end
- assert_equal(%w{James Dana Storm Gypsy}, answers)
+ assert_equal(%w[James Dana Storm Gypsy], answers)
end
def test_gather_with_hash
@@ -903,10 +898,10 @@ class TestHighLine < Minitest::Test
@input.rewind
answers = @terminal.ask("<%= key %>: ", Integer) do |q|
- q.gather = { "Age" => 0, "Wife's Age" => 0, "Father's Age" => 0}
+ q.gather = { "Age" => 0, "Wife's Age" => 0, "Father's Age" => 0 }
end
- assert_equal( { "Age" => 29, "Wife's Age" => 30, "Father's Age" => 49},
- answers )
+ assert_equal({ "Age" => 29, "Wife's Age" => 30, "Father's Age" => 49 },
+ answers)
assert_equal("Age: Father's Age: Wife's Age: ", @output.string)
end
@@ -943,7 +938,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)
@@ -956,19 +951,19 @@ class TestHighLine < Minitest::Test
q.verify_match = true
q.responses[:mismatch] = 'Typing mismatch!'
q.responses[:ask_on_error] = ''
- q.gather = {"Enter a password" => '', "Please type it again" => ''}
+ q.gather = { "Enter a password" => '', "Please type it again" => '' }
end
assert_equal("Password", answer)
- assert_equal( "Enter a password: " +
- "Please type it again: " +
- "Typing mismatch!\n" +
- "Enter a password: " +
- "Please type it again: ", @output.string )
+ assert_equal("Enter a password: " \
+ "Please type it again: " \
+ "Typing mismatch!\n" \
+ "Enter a password: " \
+ "Please type it again: ", @output.string)
end
def test_lists
- digits = %w{Zero One Two Three Four Five Six Seven Eight Nine}
+ digits = %w[Zero One Two Three Four Five Six Seven Eight Nine]
erb_digits = digits.dup
erb_digits[erb_digits.index("Five")] = "<%= color('Five', :blue) %%>"
@@ -978,96 +973,96 @@ class TestHighLine < Minitest::Test
@output.truncate(@output.rewind)
@terminal.say("<%= list(#{digits.inspect}, :inline) %>")
- assert_equal( digits[0..-2].join(", ") + " or #{digits.last}\n",
- @output.string )
+ assert_equal(digits[0..-2].join(", ") + " or #{digits.last}\n",
+ @output.string)
@output.truncate(@output.rewind)
@terminal.say("<%= list(#{digits.inspect}, :inline, ' and ') %>")
- assert_equal( digits[0..-2].join(", ") + " and #{digits.last}\n",
- @output.string )
+ assert_equal(digits[0..-2].join(", ") + " and #{digits.last}\n",
+ @output.string)
@output.truncate(@output.rewind)
@terminal.say("<%= list(#{digits.inspect}, :columns_down, 3) %>")
- assert_equal( "Zero Four Eight\n" +
- "One Five Nine \n" +
- "Two Six \n" +
+ assert_equal("Zero Four Eight\n" \
+ "One Five Nine \n" \
+ "Two Six \n" \
"Three Seven\n",
- @output.string )
+ @output.string)
@output.truncate(@output.rewind)
@terminal.say("<%= list(#{erb_digits.inspect}, :columns_down, 3) %>")
- assert_equal( "Zero Four Eight\n" +
- "One \e[34mFive\e[0m Nine \n" +
- "Two Six \n" +
+ assert_equal("Zero Four Eight\n" \
+ "One \e[34mFive\e[0m Nine \n" \
+ "Two Six \n" \
"Three Seven\n",
- @output.string )
+ @output.string)
colums_of_twenty = ["12345678901234567890"] * 5
-
+
@output.truncate(@output.rewind)
@terminal.say("<%= list(#{colums_of_twenty.inspect}, :columns_down) %>")
- assert_equal( "12345678901234567890 12345678901234567890 " +
- "12345678901234567890\n" +
+ assert_equal("12345678901234567890 12345678901234567890 " \
+ "12345678901234567890\n" \
"12345678901234567890 12345678901234567890\n",
- @output.string )
+ @output.string)
@output.truncate(@output.rewind)
@terminal.say("<%= list(#{digits.inspect}, :columns_across, 3) %>")
- assert_equal( "Zero One Two \n" +
- "Three Four Five \n" +
- "Six Seven Eight\n" +
+ assert_equal("Zero One Two \n" \
+ "Three Four Five \n" \
+ "Six Seven Eight\n" \
"Nine \n",
- @output.string )
-
+ @output.string)
+
colums_of_twenty.pop
@output.truncate(@output.rewind)
@terminal.say("<%= list( #{colums_of_twenty.inspect}, :columns_across ) %>")
- assert_equal( "12345678901234567890 12345678901234567890 " +
- "12345678901234567890\n" +
+ assert_equal("12345678901234567890 12345678901234567890 " \
+ "12345678901234567890\n" \
"12345678901234567890\n",
- @output.string )
+ @output.string)
@output.truncate(@output.rewind)
-
+
wide = %w[0123456789 a b c d e f g h i j k l m n o p q r s t u v w x y z]
@terminal.say("<%= list( #{wide.inspect}, :uneven_columns_across ) %>")
- assert_equal( "0123456789 a b c d e f g h i j k l m n o " +
- "p q r s t u v w\n" +
+ assert_equal("0123456789 a b c d e f g h i j k l m n o " \
+ "p q r s t u v w\n" \
"x y z\n",
- @output.string )
+ @output.string)
@output.truncate(@output.rewind)
@terminal.say("<%= list( #{wide.inspect}, :uneven_columns_across, 10 ) %>")
- assert_equal( "0123456789 a b c d e f g h i\n" +
- "j k l m n o p q r s\n" +
+ assert_equal("0123456789 a b c d e f g h i\n" \
+ "j k l m n o p q r s\n" \
"t u v w x y z\n",
- @output.string )
+ @output.string)
@output.truncate(@output.rewind)
@terminal.say("<%= list( #{wide.inspect}, :uneven_columns_down ) %>")
- assert_equal( "0123456789 b d f h j l n p r t v x z\n" +
+ assert_equal("0123456789 b d f h j l n p r t v x z\n" \
"a c e g i k m o q s u w y\n",
- @output.string )
+ @output.string)
@output.truncate(@output.rewind)
@terminal.say("<%= list( #{wide.inspect}, :uneven_columns_down, 10 ) %>")
- assert_equal( "0123456789 c f i l o r u x\n" +
- "a d g j m p s v y\n" +
+ assert_equal("0123456789 c f i l o r u x\n" \
+ "a d g j m p s v y\n" \
"b e h k n q t w z\n",
- @output.string )
+ @output.string)
end
-
+
def test_lists_with_zero_items
modes = [nil, :rows, :inline, :columns_across, :columns_down]
modes.each do |mode|
@@ -1083,70 +1078,72 @@ class TestHighLine < Minitest::Test
assert_equal("\n", result)
end
end
-
+
def test_lists_with_one_item
items = ['Zero']
- modes = { nil => "Zero\n",
- :rows => "Zero\n",
- :inline => "Zero",
- :columns_across => "Zero\n",
- :columns_down => "Zero\n" }
-
+ modes = { nil => "Zero\n",
+ :rows => "Zero\n",
+ :inline => "Zero",
+ :columns_across => "Zero\n",
+ :columns_down => "Zero\n" }
+
modes.each do |mode, expected|
result = @terminal.list(items, mode)
assert_equal(expected, result)
end
end
-
+
def test_lists_with_two_items
- items = ['Zero', 'One']
- modes = { nil => "Zero\nOne\n",
- :rows => "Zero\nOne\n",
- :inline => "Zero or One",
- :columns_across => "Zero One \n",
- :columns_down => "Zero One \n" }
-
+ items = %w[Zero One]
+ modes = { nil => "Zero\nOne\n",
+ :rows => "Zero\nOne\n",
+ :inline => "Zero or One",
+ :columns_across => "Zero One \n",
+ :columns_down => "Zero One \n" }
+
modes.each do |mode, expected|
result = @terminal.list(items, mode)
assert_equal(expected, result)
end
end
-
+
def test_lists_with_three_items
- items = ['Zero', 'One', 'Two']
- modes = { nil => "Zero\nOne\nTwo\n",
- :rows => "Zero\nOne\nTwo\n",
- :inline => "Zero, One or Two",
- :columns_across => "Zero One Two \n",
- :columns_down => "Zero One Two \n" }
+ items = %w[Zero One Two]
+ modes = { nil => "Zero\nOne\nTwo\n",
+ :rows => "Zero\nOne\nTwo\n",
+ :inline => "Zero, One or Two",
+ :columns_across => "Zero One Two \n",
+ :columns_down => "Zero One Two \n" }
modes.each do |mode, expected|
result = @terminal.list(items, mode)
assert_equal(expected, result)
end
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")
end
-
+
class NameClass
- def self.parse( string )
+ def self.parse(string)
if string =~ /^\s*(\w+),\s*(\w+)\s+(\w+)\s*$/
- self.new($2, $3, $1)
+ new(Regexp.last_match(2), Regexp.last_match(3), Regexp.last_match(1))
else
raise ArgumentError, "Invalid name format."
end
end
def initialize(first, middle, last)
- @first, @middle, @last = first, middle, last
+ @first = first
+ @middle = middle
+ @last = last
end
-
+
attr_reader :first, :middle, :last
end
-
+
def test_my_class_conversion
@input << "Gray, James Edward\n"
@input.rewind
@@ -1164,7 +1161,7 @@ class TestHighLine < Minitest::Test
assert_equal("James", answer.first)
assert_equal("Edward", answer.middle)
end
-
+
def test_no_echo
@input << "password\r"
@input.rewind
@@ -1177,7 +1174,7 @@ class TestHighLine < Minitest::Test
@input.rewind
@output.truncate(@output.rewind)
-
+
answer = @terminal.ask("Pick a letter or number: ") do |q|
q.character = true
q.echo = false
@@ -1186,7 +1183,7 @@ class TestHighLine < Minitest::Test
assert_equal("a", @input.getc.chr)
assert_equal("Pick a letter or number: \n", @output.string)
end
-
+
def test_correct_string_encoding_when_echo_false
@input << "ação\r" # An UTF-8 portuguese word for 'action'
@input.rewind
@@ -1234,7 +1231,7 @@ class TestHighLine < Minitest::Test
assert_equal("Type: ****\n", @output.string)
assert_equal("maçã", answer)
end
-
+
def test_range_requirements
@input << "112\n-541\n28\n"
@input.rewind
@@ -1243,13 +1240,13 @@ class TestHighLine < Minitest::Test
q.in = 0..105
end
assert_equal(28, answer)
- assert_equal( "Tell me your age.\n" +
- "Your answer isn't within the expected range " +
- "(included in 0..105).\n" +
- "? " +
- "Your answer isn't within the expected range " +
- "(included in 0..105).\n" +
- "? ", @output.string )
+ assert_equal("Tell me your age.\n" \
+ "Your answer isn't within the expected range " \
+ "(included in 0..105).\n" \
+ "? " \
+ "Your answer isn't within the expected range " \
+ "(included in 0..105).\n" \
+ "? ", @output.string)
@input.truncate(@input.rewind)
@input << "1\n-541\n28\n"
@@ -1260,13 +1257,13 @@ class TestHighLine < Minitest::Test
q.above = 3
end
assert_equal(28, answer)
- assert_equal( "Tell me your age.\n" +
- "Your answer isn't within the expected range " +
- "(above 3).\n" +
- "? " +
- "Your answer isn't within the expected range " +
- "(above 3).\n" +
- "? ", @output.string )
+ assert_equal("Tell me your age.\n" \
+ "Your answer isn't within the expected range " \
+ "(above 3).\n" \
+ "? " \
+ "Your answer isn't within the expected range " \
+ "(above 3).\n" \
+ "? ", @output.string)
@input.truncate(@input.rewind)
@input << "1\n28\n-541\n"
@@ -1277,13 +1274,13 @@ class TestHighLine < Minitest::Test
q.below = 0
end
assert_equal(-541, answer)
- assert_equal( "Lowest numer you can think of?\n" +
- "Your answer isn't within the expected range " +
- "(below 0).\n" +
- "? " +
- "Your answer isn't within the expected range " +
- "(below 0).\n" +
- "? ", @output.string )
+ assert_equal("Lowest numer you can think of?\n" \
+ "Your answer isn't within the expected range " \
+ "(below 0).\n" \
+ "? " \
+ "Your answer isn't within the expected range " \
+ "(below 0).\n" \
+ "? ", @output.string)
@input.truncate(@input.rewind)
@input << "-541\n11\n6\n"
@@ -1295,13 +1292,13 @@ class TestHighLine < Minitest::Test
q.below = 10
end
assert_equal(6, answer)
- assert_equal( "Enter a low even number: " +
- "Your answer isn't within the expected range " +
- "(above 0 and below 10).\n" +
- "? " +
- "Your answer isn't within the expected range " +
- "(above 0 and below 10).\n" +
- "? ", @output.string )
+ assert_equal("Enter a low even number: " \
+ "Your answer isn't within the expected range " \
+ "(above 0 and below 10).\n" \
+ "? " \
+ "Your answer isn't within the expected range " \
+ "(above 0 and below 10).\n" \
+ "? ", @output.string)
@input.truncate(@input.rewind)
@input << "1\n-541\n6\n"
@@ -1314,27 +1311,27 @@ class TestHighLine < Minitest::Test
q.in = [2, 4, 6, 8]
end
assert_equal(6, answer)
- assert_equal( "Enter a low even number: " +
- "Your answer isn't within the expected range " +
- "(above 0, below 10, and included in [2, 4, 6, 8]).\n" +
- "? " +
- "Your answer isn't within the expected range " +
- "(above 0, below 10, and included in [2, 4, 6, 8]).\n" +
- "? ", @output.string )
- end
-
+ assert_equal("Enter a low even number: " \
+ "Your answer isn't within the expected range " \
+ "(above 0, below 10, and included in [2, 4, 6, 8]).\n" \
+ "? " \
+ "Your answer isn't within the expected range " \
+ "(above 0, below 10, and included in [2, 4, 6, 8]).\n" \
+ "? ", @output.string)
+ end
+
def test_reask
- number = 61676
+ number = 61_676
@input << "Junk!\n" << number << "\n"
@input.rewind
answer = @terminal.ask("Favorite number? ", Integer)
assert_kind_of(Integer, number)
- assert_instance_of(Fixnum, number)
+ assert_instance_of(Integer, number)
assert_equal(number, answer)
- assert_equal( "Favorite number? " +
- "You must enter a valid Integer.\n" +
- "? ", @output.string )
+ assert_equal("Favorite number? " \
+ "You must enter a valid Integer.\n" \
+ "? ", @output.string)
@input.rewind
@output.truncate(@output.rewind)
@@ -1344,43 +1341,43 @@ class TestHighLine < Minitest::Test
q.responses[:invalid_type] = "Not a valid number!"
end
assert_kind_of(Integer, number)
- assert_instance_of(Fixnum, number)
+ assert_instance_of(Integer, number)
assert_equal(number, answer)
- assert_equal( "Favorite number? " +
- "Not a valid number!\n" +
- "Favorite number? ", @output.string )
+ assert_equal("Favorite number? " \
+ "Not a valid number!\n" \
+ "Favorite number? ", @output.string)
@input.truncate(@input.rewind)
@input << "gen\ngene\n"
@input.rewind
@output.truncate(@output.rewind)
- answer = @terminal.ask("Select a mode: ", [:generate, :gentle])
+ answer = @terminal.ask("Select a mode: ", %i[generate gentle])
assert_instance_of(Symbol, answer)
assert_equal(:generate, answer)
- assert_equal( "Select a mode: " +
- "Ambiguous choice. " +
- "Please choose one of [generate, gentle].\n" +
- "? ", @output.string )
+ assert_equal("Select a mode: " \
+ "Ambiguous choice. " \
+ "Please choose one of [generate, gentle].\n" \
+ "? ", @output.string)
end
-
+
def test_response_embedding
@input << "112\n-541\n28\n"
@input.rewind
answer = @terminal.ask("Tell me your age.", Integer) do |q|
q.in = 0..105
- q.responses[:not_in_range] = "Need a #{q.answer_type}" +
+ q.responses[:not_in_range] = "Need a #{q.answer_type}" \
" #{q.expected_range}."
end
assert_equal(28, answer)
- assert_equal( "Tell me your age.\n" +
- "Need a Integer included in 0..105.\n" +
- "? " +
- "Need a Integer included in 0..105.\n" +
- "? ", @output.string )
+ assert_equal("Tell me your age.\n" \
+ "Need a Integer included in 0..105.\n" \
+ "? " \
+ "Need a Integer included in 0..105.\n" \
+ "? ", @output.string)
end
-
+
def test_say
@terminal.say("This will have a newline.")
assert_equal("This will have a newline.\n", @output.string)
@@ -1401,7 +1398,7 @@ class TestHighLine < Minitest::Test
assert_equal("This will not have a newline.\t", @output.string)
@output.truncate(@output.rewind)
-
+
@terminal.say("This will not\n end with a newline. ")
assert_equal("This will not\n end with a newline. ", @output.string)
@@ -1430,7 +1427,7 @@ class TestHighLine < Minitest::Test
def test_say_handles_non_string_argument
integer = 10
- hash = { :a => 20 }
+ hash = { a: 20 }
@terminal.say(integer)
assert_equal String(integer), @output.string.chomp
@@ -1442,20 +1439,20 @@ class TestHighLine < Minitest::Test
end
def test_terminal_size
- assert_instance_of(Fixnum, @terminal.terminal.terminal_size[0])
- assert_instance_of(Fixnum, @terminal.terminal.terminal_size[1])
+ assert_instance_of(Integer, @terminal.terminal.terminal_size[0])
+ assert_instance_of(Integer, @terminal.terminal.terminal_size[1])
end
def test_type_conversion
- number = 61676
+ number = 61_676
@input << number << "\n"
@input.rewind
answer = @terminal.ask("Favorite number? ", Integer)
assert_kind_of(Integer, answer)
- assert_instance_of(Fixnum, answer)
+ assert_instance_of(Integer, answer)
assert_equal(number, answer)
-
+
@input.truncate(@input.rewind)
number = 1_000_000_000_000_000_000_000_000_000_000
@input << number << "\n"
@@ -1463,7 +1460,7 @@ class TestHighLine < Minitest::Test
answer = @terminal.ask("Favorite number? ", Integer)
assert_kind_of(Integer, answer)
- assert_instance_of(Bignum, answer)
+ assert_instance_of(Integer, answer)
assert_equal(number, answer)
@input.truncate(@input.rewind)
@@ -1471,10 +1468,10 @@ class TestHighLine < Minitest::Test
@input << number << "\n"
@input.rewind
- answer = @terminal.ask( "Favorite number? ",
- lambda { |n| n.to_f.abs.round } )
+ answer = @terminal.ask("Favorite number? ",
+ ->(n) { n.to_f.abs.round })
assert_kind_of(Integer, answer)
- assert_instance_of(Fixnum, answer)
+ assert_instance_of(Integer, answer)
assert_equal(11, answer)
@input.truncate(@input.rewind)
@@ -1509,11 +1506,11 @@ class TestHighLine < Minitest::Test
@input << "gen\n"
@input.rewind
- answer = @terminal.ask("Select a mode: ", [:generate, :run])
+ answer = @terminal.ask("Select a mode: ", %i[generate run])
assert_instance_of(Symbol, answer)
assert_equal(:generate, answer)
end
-
+
def test_validation
@input << "system 'rm -rf /'\n105\n0b101_001\n"
@input.rewind
@@ -1522,17 +1519,17 @@ class TestHighLine < Minitest::Test
q.validate = /\A(?:0b)?[01_]+\Z/
end
assert_equal("0b101_001", answer)
- assert_equal( "Enter a binary number: " +
- "Your answer isn't valid " +
- "(must match /\\A(?:0b)?[01_]+\\Z/).\n" +
- "? " +
- "Your answer isn't valid " +
- "(must match /\\A(?:0b)?[01_]+\\Z/).\n" +
- "? ", @output.string )
+ assert_equal("Enter a binary number: " \
+ "Your answer isn't valid " \
+ "(must match /\\A(?:0b)?[01_]+\\Z/).\n" \
+ "? " \
+ "Your answer isn't valid " \
+ "(must match /\\A(?:0b)?[01_]+\\Z/).\n" \
+ "? ", @output.string)
@input.truncate(@input.rewind)
- @input << "Gray II, James Edward\n" +
- "Gray, Dana Ann Leslie\n" +
+ @input << "Gray II, James Edward\n" \
+ "Gray, Dana Ann Leslie\n" \
"Gray, James Edward\n"
@input.rewind
@@ -1546,11 +1543,11 @@ class TestHighLine < Minitest::Test
end
assert_equal("Gray, James Edward", answer)
end
-
+
def test_whitespace
@input << " A lot\tof \t space\t \there! \n"
@input.rewind
-
+
answer = @terminal.ask("Enter a whitespace filled string: ") do |q|
q.whitespace = :chomp
end
@@ -1603,7 +1600,7 @@ class TestHighLine < Minitest::Test
end
assert_equal(" A lot\tof \t space\t \there! \n", answer)
end
-
+
def test_track_eof
assert_raises(EOFError) { @terminal.ask("Any input left? ") }
@@ -1613,13 +1610,13 @@ class TestHighLine < Minitest::Test
HighLine.track_eof = false
begin
require 'highline/import'
- ask("And now? ") # this will still blow up, nothing available
+ ask("And now? ") # this will still blow up, nothing available
rescue
- refute_equal(EOFError, $!.class) # but HighLine's safe guards are off
+ refute_equal(EOFError, $ERROR_INFO.class) # but HighLine's safe guards are off
end
HighLine.default_instance = old_instance
end
-
+
def test_version
refute_nil(HighLine::VERSION)
assert_instance_of(String, HighLine::VERSION)
diff --git a/test/test_import.rb b/test/test_import.rb
index 40ff56d..c84c5fd 100644
--- a/test/test_import.rb
+++ b/test/test_import.rb
@@ -28,14 +28,14 @@ class TestImport < Minitest::Test
# If correctly initialized, it will contain several ins vars.
refute_empty HighLine.default_instance.instance_variables
end
-
+
def test_or_ask
old_instance = HighLine.default_instance
-
+
input = StringIO.new
output = StringIO.new
- HighLine.default_instance = HighLine.new(input, output)
-
+ HighLine.default_instance = HighLine.new(input, output)
+
input << "10\n"
input.rewind
@@ -45,15 +45,15 @@ class TestImport < Minitest::Test
assert_equal(20, "20".or_ask("How much? ", Integer))
assert_equal(20, 20.or_ask("How much? ", Integer))
-
+
assert_equal(10, 20.or_ask("How much? ", Integer) { |q| q.in = 1..10 })
ensure
HighLine.default_instance = old_instance
end
-
+
def test_redirection
old_instance = HighLine.default_instance
-
+
HighLine.default_instance = HighLine.new(nil, (output = StringIO.new))
say("Testing...")
assert_equal("Testing...\n", output.string)
diff --git a/test/test_list.rb b/test/test_list.rb
index 6e4c1de..ce982a8 100644
--- a/test/test_list.rb
+++ b/test/test_list.rb
@@ -7,16 +7,16 @@ require "highline/list"
class TestHighLineList < Minitest::Test
def setup
- @items = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" ]
+ @items = %w[a b c d e f g h i j]
end
def test_in_2_cols
list_in_two_cols =
- [ [ "a", "b" ],
- [ "c", "d" ],
- [ "e", "f" ],
- [ "g", "h" ],
- [ "i", "j" ] ]
+ [%w[a b],
+ %w[c d],
+ %w[e f],
+ %w[g h],
+ %w[i j]]
highline_list = HighLine::List.new(@items, cols: 2)
@@ -25,11 +25,11 @@ class TestHighLineList < Minitest::Test
def test_in_2_cols_col_down
col_down_list =
- [ [ "a", "f"],
- [ "b", "g"],
- [ "c", "h"],
- [ "d", "i"],
- [ "e", "j"] ]
+ [%w[a f],
+ %w[b g],
+ %w[c h],
+ %w[d i],
+ %w[e j]]
highline_list = HighLine::List.new(@items, cols: 2, col_down: true)
@@ -38,8 +38,8 @@ class TestHighLineList < Minitest::Test
def test_in_2_cols_transposed
transposed_list =
- [ [ "a", "c", "e", "g", "i" ],
- [ "b", "d", "f", "h", "j" ] ]
+ [%w[a c e g i],
+ %w[b d f h j]]
highline_list = HighLine::List.new(@items, cols: 2, transpose: true)
@@ -48,13 +48,13 @@ class TestHighLineList < Minitest::Test
def test_in_3_cols
list_in_three_cols =
- [ [ "a", "b", "c" ],
- [ "d", "e", "f" ],
- [ "g", "h", "i" ],
- [ "j" ] ]
+ [%w[a b c],
+ %w[d e f],
+ %w[g h i],
+ ["j"]]
highline_list = HighLine::List.new(@items, cols: 3)
assert_equal list_in_three_cols, highline_list.list
end
-end \ No newline at end of file
+end
diff --git a/test/test_menu.rb b/test/test_menu.rb
index 402b47d..514ff6b 100644
--- a/test/test_menu.rb
+++ b/test/test_menu.rb
@@ -90,7 +90,7 @@ 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
@@ -102,8 +102,8 @@ class TestMenu < Minitest::Test
menu.choice("Sample2", nil, "Sample1")
end
assert_equal(selected, "Sample1")
- assert_equal("1. Sample2\n" +
- "2. Sample1\n" +
+ assert_equal("1. Sample2\n" \
+ "2. Sample1\n" \
"? ", @output.string)
end
@@ -116,8 +116,8 @@ class TestMenu < Minitest::Test
menu.choice("Sample2", nil, "Sample1")
end
assert_equal(selected, "Sample2")
- assert_equal("1. Sample2\n" +
- "2. Sample1\n" +
+ assert_equal("1. Sample2\n" \
+ "2. Sample1\n" \
"? ", @output.string)
end
@@ -130,8 +130,8 @@ class TestMenu < Minitest::Test
menu.add_item(HighLine::Menu::Item.new("Sample2", text: "Sample1"))
end
assert_equal(selected, "Sample1")
- assert_equal("1. Sample2\n" +
- "2. Sample1\n" +
+ assert_equal("1. Sample2\n" \
+ "2. Sample1\n" \
"? ", @output.string)
end
@@ -144,8 +144,8 @@ class TestMenu < Minitest::Test
menu.add_item(HighLine::Menu::Item.new("Sample2", text: "Sample1"))
end
assert_equal(selected, "Sample2")
- assert_equal("1. Sample2\n" +
- "2. Sample1\n" +
+ assert_equal("1. Sample2\n" \
+ "2. Sample1\n" \
"? ", @output.string)
end
@@ -158,8 +158,8 @@ class TestMenu < Minitest::Test
menu.add_item(menu.build_item("Sample2", text: "Sample1"))
end
assert_equal(selected, "Sample2")
- assert_equal("1. Sample2\n" +
- "2. Sample1\n" +
+ assert_equal("1. Sample2\n" \
+ "2. Sample1\n" \
"? ", @output.string)
end
@@ -178,22 +178,22 @@ class TestMenu < Minitest::Test
menu.help("rules", "The rules of this system are as follows...")
end
end
- assert_equal( "1. load\n2. save\n3. quit\n4. help\n? " +
- "This command will display helpful messages about " +
- "functionality, like this one. To see the help for a " +
- "specific topic enter:\n" +
- "\thelp [TOPIC]\n" +
- "Try asking for help on any of the following:\n" +
- "\nload quit rules save \n" +
- "1. load\n2. save\n3. quit\n4. help\n? " +
- "= load\n\n" +
- "Load a file.\n" +
- "1. load\n2. save\n3. quit\n4. help\n? " +
- "= rules\n\n" +
- "The rules of this system are as follows...\n" +
- "1. load\n2. save\n3. quit\n4. help\n? " +
- "= missing\n\n" +
- "There's no help for that topic.\n", @output.string )
+ assert_equal("1. load\n2. save\n3. quit\n4. help\n? " \
+ "This command will display helpful messages about " \
+ "functionality, like this one. To see the help for a " \
+ "specific topic enter:\n" \
+ "\thelp [TOPIC]\n" \
+ "Try asking for help on any of the following:\n" \
+ "\nload quit rules save \n" \
+ "1. load\n2. save\n3. quit\n4. help\n? " \
+ "= load\n\n" \
+ "Load a file.\n" \
+ "1. load\n2. save\n3. quit\n4. help\n? " \
+ "= rules\n\n" \
+ "The rules of this system are as follows...\n" \
+ "1. load\n2. save\n3. quit\n4. help\n? " \
+ "= missing\n\n" \
+ "There's no help for that topic.\n", @output.string)
end
def test_index
@@ -238,7 +238,7 @@ class TestMenu < Minitest::Test
@input.rewind
@terminal.choose do |menu|
- menu.index = "*"
+ menu.index = "*"
menu.choice "Sample1"
menu.choice "Sample2"
@@ -265,7 +265,7 @@ class TestMenu < Minitest::Test
assert_equal(
HighLine.color("1. ", index_color) + "Sample1\n" +
HighLine.color("2. ", index_color) + "Sample2\n" +
- HighLine.color("3. ", index_color) + "Sample3\n" +
+ HighLine.color("3. ", index_color) + "Sample3\n" \
"? ",
@output.string
)
@@ -323,8 +323,8 @@ class TestMenu < Minitest::Test
colored_asterix = HighLine.color("* ", index_color)
assert_equal(
- "#{colored_asterix}Sample1\n" +
- "#{colored_asterix}Sample2\n" +
+ "#{colored_asterix}Sample1\n" \
+ "#{colored_asterix}Sample2\n" \
"#{colored_asterix}Sample3\n? ",
@output.string
)
@@ -343,8 +343,8 @@ class TestMenu < Minitest::Test
@terminal.choose(:load, :save, :quit) do |menu|
menu.header = "File Menu"
end
- assert_equal( "File Menu:\n" +
- "1. load\n2. save\n3. quit\n? ", @output.string )
+ assert_equal("File Menu:\n" \
+ "1. load\n2. save\n3. quit\n? ", @output.string)
@input.rewind
@output.truncate(@output.rewind)
@@ -354,14 +354,14 @@ class TestMenu < Minitest::Test
menu.header = "File Menu"
menu.prompt = "Operation? "
end
- assert_equal( "File Menu: Operation? " +
- "(load, save or quit) ", @output.string )
+ assert_equal("File Menu: Operation? " \
+ "(load, save or quit) ", @output.string)
@input.rewind
@output.truncate(@output.rewind)
@terminal.choose(:load, :save, :quit) do |menu|
- menu.layout = :menu_only
+ menu.layout = :menu_only
end
assert_equal("load, save or quit? ", @output.string)
@@ -391,9 +391,9 @@ class TestMenu < Minitest::Test
# Shows that by default proc results are returned.
output = @terminal.choose do |menu|
- menu.choice "Sample1" do "output1" end
- menu.choice "Sample2" do "output2" end
- menu.choice "Sample3" do "output3" end
+ menu.choice "Sample1" do "output1" end
+ menu.choice "Sample2" do "output2" end
+ menu.choice "Sample3" do "output3" end
end
assert_equal("output3", output)
@@ -402,10 +402,10 @@ class TestMenu < Minitest::Test
# _nil_on_handled to +true+.
#
output = @terminal.choose do |menu|
- menu.nil_on_handled = true
- menu.choice "Sample1" do "output1" end
- menu.choice "Sample2" do "output2" end
- menu.choice "Sample3" do "output3" end
+ menu.nil_on_handled = true
+ menu.choice "Sample1" do "output1" end
+ menu.choice "Sample2" do "output2" end
+ menu.choice "Sample3" do "output3" end
end
assert_equal(nil, output)
@@ -445,7 +445,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
@@ -527,7 +527,7 @@ class TestMenu < Minitest::Test
@input.rewind
selected = @terminal.choose do |menu|
- menu.index = :letter
+ menu.index = :letter
menu.choice :save
menu.choice :load
menu.choice :quit
@@ -596,12 +596,12 @@ 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'),
- "Paging message did not appear." )
+ assert(@output.string.index('press enter/return to continue or q to stop'),
+ "Paging message did not appear.")
# Make sure it only appeared once
- assert( @output.string !~ /q to stop.*q to stop/m,
- "Paging message appeared more than once." )
+ assert(@output.string !~ /q to stop.*q to stop/m,
+ "Paging message appeared more than once.")
end
def test_autocomplete_prompt
@@ -614,13 +614,13 @@ class TestMenu < Minitest::Test
menu.choice(:Ruby)
menu.prompt = "What is your favorite programming language? "
end
- languages = [:Perl, :Python, :Ruby]
- assert_equal("1. Perl\n" +
- "2. Python\n" +
- "3. Ruby\n" +
- "What is your favorite programming language? " +
- "You must choose one of [1, 2, 3, Perl, Python, Ruby].\n" +
- "? ", @output.string )
+ languages = %i[Perl Python Ruby]
+ assert_equal("1. Perl\n" \
+ "2. Python\n" \
+ "3. Ruby\n" \
+ "What is your favorite programming language? " \
+ "You must choose one of [1, 2, 3, Perl, Python, Ruby].\n" \
+ "? ", @output.string)
end
# Issue #180 - https://github.com/JEG2/highline/issues/180
@@ -652,14 +652,14 @@ class TestMenu < Minitest::Test
menu.choice "Sample2"
menu.choice "last"
end
- assert_equal(["Sample1", "last"], selected)
+ assert_equal(%w[Sample1 last], selected)
- assert_equal("1. Sample1\n" +
- "2. Sample2\n" +
- "3. last\n" +
- "? 1. Sample1\n" +
- "2. Sample2\n" +
- "3. last\n" +
+ assert_equal("1. Sample1\n" \
+ "2. Sample2\n" \
+ "3. last\n" \
+ "? 1. Sample1\n" \
+ "2. Sample2\n" \
+ "3. last\n" \
"? ", @output.string)
end
@@ -675,12 +675,12 @@ class TestMenu < Minitest::Test
end
assert_equal(["Sample1"], selected)
- assert_equal("1. Sample1\n" +
- "2. Sample2\n" +
- "3. last\n" +
- "? 1. Sample1\n" +
- "2. Sample2\n" +
- "3. last\n" +
+ assert_equal("1. Sample1\n" \
+ "2. Sample2\n" \
+ "3. last\n" \
+ "? 1. Sample1\n" \
+ "2. Sample2\n" \
+ "3. last\n" \
"? ", @output.string)
end
@@ -696,12 +696,12 @@ class TestMenu < Minitest::Test
end
assert_equal(["Sample1"], selected)
- assert_equal("1. Sample1\n" +
- "2. Sample2\n" +
- "3. last\n" +
- "? 1. Sample1\n" +
- "2. Sample2\n" +
- "3. last\n" +
+ assert_equal("1. Sample1\n" \
+ "2. Sample2\n" \
+ "3. last\n" \
+ "? 1. Sample1\n" \
+ "2. Sample2\n" \
+ "3. last\n" \
"? ", @output.string)
end
@@ -717,12 +717,12 @@ class TestMenu < Minitest::Test
end
assert_equal(["Sample1"], selected)
- assert_equal("1. Sample1\n" +
- "2. Sample2\n" +
- "3. last\n" +
- "? 1. Sample1\n" +
- "2. Sample2\n" +
- "3. last\n" +
+ assert_equal("1. Sample1\n" \
+ "2. Sample2\n" \
+ "3. last\n" \
+ "? 1. Sample1\n" \
+ "2. Sample2\n" \
+ "3. last\n" \
"? ", @output.string)
end
@@ -738,12 +738,12 @@ class TestMenu < Minitest::Test
end
assert_equal({ "First" => "Sample1", second: "last" }, selected)
- assert_equal("1. Sample1\n" +
- "2. Sample2\n" +
- "3. last\n" +
- "? 1. Sample1\n" +
- "2. Sample2\n" +
- "3. last\n" +
+ assert_equal("1. Sample1\n" \
+ "2. Sample2\n" \
+ "3. last\n" \
+ "? 1. Sample1\n" \
+ "2. Sample2\n" \
+ "3. last\n" \
"? ", @output.string)
end
end
diff --git a/test/test_paginator.rb b/test/test_paginator.rb
index 6dfa15b..39036ee 100644
--- a/test/test_paginator.rb
+++ b/test/test_paginator.rb
@@ -19,13 +19,13 @@ class TestHighLinePaginator < Minitest::Test
@input << "\n\n"
@input.rewind
- @terminal.say((1..50).map { |n| "This is line #{n}.\n"}.join)
- assert_equal( (1..22).map { |n| "This is line #{n}.\n"}.join +
+ @terminal.say((1..50).map { |n| "This is line #{n}.\n" }.join)
+ assert_equal((1..22).map { |n| "This is line #{n}.\n" }.join +
"\n-- press enter/return to continue or q to stop -- \n\n" +
- (23..44).map { |n| "This is line #{n}.\n"}.join +
+ (23..44).map { |n| "This is line #{n}.\n" }.join +
"\n-- press enter/return to continue or q to stop -- \n\n" +
- (45..50).map { |n| "This is line #{n}.\n"}.join,
- @output.string )
+ (45..50).map { |n| "This is line #{n}.\n" }.join,
+ @output.string)
end
def test_statement_lines_count_equal_to_page_at_shouldnt_paginate
@@ -70,4 +70,4 @@ class TestHighLinePaginator < Minitest::Test
# expect not to raise an error on next line
@terminal.say(list)
end
-end \ No newline at end of file
+end
diff --git a/test/test_simulator.rb b/test/test_simulator.rb
index 5f1f305..f22abe6 100644
--- a/test/test_simulator.rb
+++ b/test/test_simulator.rb
@@ -21,4 +21,4 @@ class SimulatorTest < Minitest::Test
assert_equal "18", age
end
end
-end \ No newline at end of file
+end
diff --git a/test/test_string_extension.rb b/test/test_string_extension.rb
index 9f87294..fb4b9ff 100644
--- a/test/test_string_extension.rb
+++ b/test/test_string_extension.rb
@@ -13,7 +13,6 @@ require "highline"
require "stringio"
require "string_methods"
-
# FakeString is here just to avoid
# using HighLine.colorize_strings
# on tests
@@ -39,7 +38,7 @@ class TestStringExtension < Minitest::Test
unless Gem::Version.new(YAML::VERSION) < Gem::Version.new("2.0.2")
highline_string = HighLine::String.new("Yaml didn't messed with HighLine::String")
yaml_highline_string = highline_string.to_yaml
- yaml_loaded_string = YAML.load(yaml_highline_string)
+ yaml_loaded_string = YAML.safe_load(yaml_highline_string)
assert_equal "Yaml didn't messed with HighLine::String", yaml_loaded_string
assert_equal highline_string, yaml_loaded_string
@@ -63,7 +62,7 @@ class TestStringExtension < Minitest::Test
def test_String_includes_StringExtension_when_receives_colorize_strings
@include_received = 0
- caller = Proc.new { @include_received += 1 }
+ caller = proc { @include_received += 1 }
::String.stub :include, caller do
HighLine.colorize_strings
end
diff --git a/test/test_string_highline.rb b/test/test_string_highline.rb
index 87db9c6..040e1a2 100644
--- a/test/test_string_highline.rb
+++ b/test/test_string_highline.rb
@@ -23,19 +23,19 @@ class TestHighLineString < Minitest::Test
# Basic constructor
assert_equal HighLine::String, @string.class
assert_equal "string", @string
-
+
# Alternative constructor method
new_string = HighLine::String("string")
assert_equal HighLine::String, new_string.class
assert_equal @string, new_string
-
+
# String methods work
assert_equal 6, @string.size
assert_equal "STRING", @string.upcase
end
include StringMethods
-
+
def test_string_class_is_unchanged
assert_raises(::NoMethodError) { "string".color(:blue) }
end
diff --git a/test/test_style.rb b/test/test_style.rb
index 2c44401..a73a35b 100755
--- a/test/test_style.rb
+++ b/test/test_style.rb
@@ -13,15 +13,14 @@ require "highline"
require "stringio"
class TestStyle < Minitest::Test
-
def setup
HighLine.reset
@input = StringIO.new
@output = StringIO.new
- @terminal = HighLine.new(@input, @output)
- @style1 = HighLine::Style.new(:name=>:foo, :code=>"\e[99m", :rgb=>[1,2,3])
- @style2 = HighLine::Style.new(:name=>:lando, :code=>"\e[98m")
- @style3 = HighLine::Style.new(:name=>[:foo, :lando], :list=>[:foo, :lando])
+ @terminal = HighLine.new(@input, @output)
+ @style1 = HighLine::Style.new(name: :foo, code: "\e[99m", rgb: [1, 2, 3])
+ @style2 = HighLine::Style.new(name: :lando, code: "\e[98m")
+ @style3 = HighLine::Style.new(name: %i[foo lando], list: %i[foo lando])
@style4 = HighLine::Style(:rgb_654321)
@added_styles_on_setup = 4 # update here if added more styles
@added_codes_to_index = 3 # :foo, :lando and :rgb_654321
@@ -39,15 +38,15 @@ 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
+ 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
+ assert_equal expected_code_index_array_size, cleared_code_index_array.size
end
def test_style_method
@@ -58,7 +57,7 @@ class TestStyle < Minitest::Test
assert_same new_style, s # i.e. s===the latest style created, but not the one searched for
# Retrieve a style from a new Style (no new Style created)
- s2 = HighLine::Style.new(:name=>:bar, :code=>"\e[97m")
+ s2 = HighLine::Style.new(name: :bar, code: "\e[97m")
s = HighLine.Style(s2)
assert_instance_of HighLine::Style, s
assert_same s2, s
@@ -96,35 +95,35 @@ class TestStyle < Minitest::Test
s = HighLine.Style(@style2.name)
assert_instance_of HighLine::Style, s
assert_same @style2, s
-
+
# 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
assert_equal "phooey", s.rgb
-
+
# Create style from an RGB foreground color code
s = HighLine.Style(:rgb_1f2e3d)
assert_instance_of HighLine::Style, s
assert_equal :rgb_1f2e3d, s.name
assert_equal "\e[38;5;23m", s.code # Trust me; more testing below
- assert_equal [31,46,61], s.rgb # 0x1f==31, 0x2e==46, 0x3d=61
-
+ assert_equal [31, 46, 61], s.rgb # 0x1f==31, 0x2e==46, 0x3d=61
+
# Create style from an RGB background color code
s = HighLine.Style(:on_rgb_1f2e3d)
assert_instance_of HighLine::Style, s
assert_equal :on_rgb_1f2e3d, s.name
assert_equal "\e[48;5;23m", s.code # Trust me; more testing below
- assert_equal [31,46,61], s.rgb # 0x1f==31, 0x2e==46, 0x3d=61
+ assert_equal [31, 46, 61], s.rgb # 0x1f==31, 0x2e==46, 0x3d=61
# Create a style list
s1 = HighLine.Style(:bold, :red)
assert_instance_of HighLine::Style, s1
- assert_equal [:bold, :red], s1.list
-
+ assert_equal %i[bold red], s1.list
+
# Find an existing style list
s2 = HighLine.Style(:bold, :red)
assert_instance_of HighLine::Style, s2
@@ -133,28 +132,28 @@ class TestStyle < Minitest::Test
# Create a style list with nils
s1 = HighLine.Style(:underline, nil, :blue)
assert_instance_of HighLine::Style, s1
- assert_equal [:underline, :blue], s1.list
-
+ assert_equal %i[underline blue], s1.list
+
# Raise an error for an undefined style
assert_raises(::NameError) { HighLine.Style(:fubar) }
end
-
+
def test_no_color_scheme
HighLine.color_scheme = nil
assert_raises(::NameError) { HighLine.Style(:critical) }
end
-
+
def test_with_color_scheme
HighLine.color_scheme = HighLine::SampleColorScheme.new
s = HighLine.Style(:critical)
assert_instance_of HighLine::Style, s
assert_equal :critical, s.name
- assert_equal [:yellow, :on_red], s.list
+ assert_equal %i[yellow on_red], s.list
end
-
+
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
@@ -162,10 +161,10 @@ class TestStyle < Minitest::Test
assert_instance_of String, code, "Bad code for #{color}"
end
end
-
+
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
@@ -173,10 +172,10 @@ class TestStyle < Minitest::Test
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
@@ -184,12 +183,12 @@ class TestStyle < Minitest::Test
assert_instance_of String, code, "Bad code for #{style_constant}"
end
end
-
+
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')
+ 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
@@ -205,9 +204,9 @@ class TestStyle < Minitest::Test
# 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_equal styles+1, HighLine::Style.list.size
- assert_equal codes+1, HighLine::Style.code_index.size
+ 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
@@ -217,16 +216,16 @@ class TestStyle < Minitest::Test
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')
+ 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
- assert_equal codes+2, HighLine::Style.code_index.size
+ assert_equal styles + 1, HighLine::Style.list.size
+ assert_equal codes + 2, HighLine::Style.code_index.size
refute_nil HighLine::Style.list[:s2]
assert_same s3, HighLine::Style.list[:s2]
refute_same s2, HighLine::Style.list[:s2]
@@ -240,9 +239,9 @@ class TestStyle < Minitest::Test
# 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 styles+2, HighLine::Style.list.size
- assert_equal codes+2, HighLine::Style.code_index.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
@@ -255,27 +254,27 @@ class TestStyle < Minitest::Test
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
assert_equal "abcdef", HighLine::Style.rgb_hex("abcdef")
- assert_equal "ABCDEF", HighLine::Style.rgb_hex("AB","CD","EF")
- assert_equal "010203", HighLine::Style.rgb_hex(1,2,3)
- assert_equal "123456", HighLine::Style.rgb_hex(18,52,86)
+ assert_equal "ABCDEF", HighLine::Style.rgb_hex("AB", "CD", "EF")
+ assert_equal "010203", HighLine::Style.rgb_hex(1, 2, 3)
+ assert_equal "123456", HighLine::Style.rgb_hex(18, 52, 86)
end
-
+
def test_rgb_parts
- assert_equal [1,2,3], HighLine::Style.rgb_parts("010203")
- assert_equal [18,52,86], HighLine::Style.rgb_parts("123456")
+ assert_equal [1, 2, 3], HighLine::Style.rgb_parts("010203")
+ assert_equal [18, 52, 86], HighLine::Style.rgb_parts("123456")
end
-
+
def test_rgb
s = HighLine::Style.rgb(1, 2, 3)
assert_instance_of HighLine::Style, s
assert_equal :rgb_010203, s.name
- assert_equal [1,2,3], s.rgb
+ assert_equal [1, 2, 3], s.rgb
assert_equal "\e[38;5;16m", s.code
- s = HighLine::Style.rgb("12", "34","56")
+ s = HighLine::Style.rgb("12", "34", "56")
assert_instance_of HighLine::Style, s
assert_equal :rgb_123456, s.name
assert_equal [0x12, 0x34, 0x56], s.rgb
@@ -287,104 +286,104 @@ class TestStyle < Minitest::Test
assert_equal [0xab, 0xcd, 0xef], s.rgb
assert_equal "\e[38;5;189m", s.code
end
-
+
def test_rgb_number
- # ANSI RGB coding splits 0..255 into equal sixths, and then the
+ # ANSI RGB coding splits 0..255 into equal sixths, and then the
# red green and blue are encoded in base 6, plus 16, i.e.
# 16 + 36*(red_level) + 6*(green_level) + blue_level,
# where each of red_level, green_level, and blue_level are in
# the range 0..5
-
+
# This test logic works because 42 is just below 1/6 of 255,
# and 43 is just above
-
- assert_equal 16 + 0*36 + 0*6 + 0, HighLine::Style.rgb_number( 0, 0, 0)
- assert_equal 16 + 0*36 + 0*6 + 0, HighLine::Style.rgb_number( 0, 0, 42)
- assert_equal 16 + 0*36 + 0*6 + 1, HighLine::Style.rgb_number( 0, 0, 43)
-
- assert_equal 16 + 0*36 + 0*6 + 0, HighLine::Style.rgb_number( 0, 42, 0)
- assert_equal 16 + 0*36 + 0*6 + 0, HighLine::Style.rgb_number( 0, 42, 42)
- assert_equal 16 + 0*36 + 0*6 + 1, HighLine::Style.rgb_number( 0, 42, 43)
-
- assert_equal 16 + 0*36 + 1*6 + 0, HighLine::Style.rgb_number( 0, 43, 0)
- assert_equal 16 + 0*36 + 1*6 + 0, HighLine::Style.rgb_number( 0, 43, 42)
- assert_equal 16 + 0*36 + 1*6 + 1, HighLine::Style.rgb_number( 0, 43, 43)
-
- assert_equal 16 + 0*36 + 0*6 + 0, HighLine::Style.rgb_number( 42, 0, 0)
- assert_equal 16 + 0*36 + 0*6 + 0, HighLine::Style.rgb_number( 42, 0, 42)
- assert_equal 16 + 0*36 + 0*6 + 1, HighLine::Style.rgb_number( 42, 0, 43)
-
- assert_equal 16 + 0*36 + 0*6 + 0, HighLine::Style.rgb_number( 42, 42, 0)
- assert_equal 16 + 0*36 + 0*6 + 0, HighLine::Style.rgb_number( 42, 42, 42)
- assert_equal 16 + 0*36 + 0*6 + 1, HighLine::Style.rgb_number( 42, 42, 43)
-
- assert_equal 16 + 0*36 + 1*6 + 0, HighLine::Style.rgb_number( 42, 43, 0)
- assert_equal 16 + 0*36 + 1*6 + 0, HighLine::Style.rgb_number( 42, 43, 42)
- assert_equal 16 + 0*36 + 1*6 + 1, HighLine::Style.rgb_number( 42, 43, 43)
-
- assert_equal 16 + 1*36 + 0*6 + 0, HighLine::Style.rgb_number( 43, 0, 0)
- assert_equal 16 + 1*36 + 0*6 + 0, HighLine::Style.rgb_number( 43, 0, 42)
- assert_equal 16 + 1*36 + 0*6 + 1, HighLine::Style.rgb_number( 43, 0, 43)
-
- assert_equal 16 + 1*36 + 0*6 + 0, HighLine::Style.rgb_number( 43, 42, 0)
- assert_equal 16 + 1*36 + 0*6 + 0, HighLine::Style.rgb_number( 43, 42, 42)
- assert_equal 16 + 1*36 + 0*6 + 1, HighLine::Style.rgb_number( 43, 42, 43)
-
- assert_equal 16 + 1*36 + 1*6 + 0, HighLine::Style.rgb_number( 43, 43, 0)
- 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 + 0 * 36 + 0 * 6 + 0, HighLine::Style.rgb_number(0, 0, 0)
+ assert_equal 16 + 0 * 36 + 0 * 6 + 0, HighLine::Style.rgb_number(0, 0, 42)
+ assert_equal 16 + 0 * 36 + 0 * 6 + 1, HighLine::Style.rgb_number(0, 0, 43)
+
+ assert_equal 16 + 0 * 36 + 0 * 6 + 0, HighLine::Style.rgb_number(0, 42, 0)
+ assert_equal 16 + 0 * 36 + 0 * 6 + 0, HighLine::Style.rgb_number(0, 42, 42)
+ assert_equal 16 + 0 * 36 + 0 * 6 + 1, HighLine::Style.rgb_number(0, 42, 43)
+
+ assert_equal 16 + 0 * 36 + 1 * 6 + 0, HighLine::Style.rgb_number(0, 43, 0)
+ assert_equal 16 + 0 * 36 + 1 * 6 + 0, HighLine::Style.rgb_number(0, 43, 42)
+ assert_equal 16 + 0 * 36 + 1 * 6 + 1, HighLine::Style.rgb_number(0, 43, 43)
+
+ assert_equal 16 + 0 * 36 + 0 * 6 + 0, HighLine::Style.rgb_number(42, 0, 0)
+ assert_equal 16 + 0 * 36 + 0 * 6 + 0, HighLine::Style.rgb_number(42, 0, 42)
+ assert_equal 16 + 0 * 36 + 0 * 6 + 1, HighLine::Style.rgb_number(42, 0, 43)
+
+ assert_equal 16 + 0 * 36 + 0 * 6 + 0, HighLine::Style.rgb_number(42, 42, 0)
+ assert_equal 16 + 0 * 36 + 0 * 6 + 0, HighLine::Style.rgb_number(42, 42, 42)
+ assert_equal 16 + 0 * 36 + 0 * 6 + 1, HighLine::Style.rgb_number(42, 42, 43)
+
+ assert_equal 16 + 0 * 36 + 1 * 6 + 0, HighLine::Style.rgb_number(42, 43, 0)
+ assert_equal 16 + 0 * 36 + 1 * 6 + 0, HighLine::Style.rgb_number(42, 43, 42)
+ assert_equal 16 + 0 * 36 + 1 * 6 + 1, HighLine::Style.rgb_number(42, 43, 43)
+
+ assert_equal 16 + 1 * 36 + 0 * 6 + 0, HighLine::Style.rgb_number(43, 0, 0)
+ assert_equal 16 + 1 * 36 + 0 * 6 + 0, HighLine::Style.rgb_number(43, 0, 42)
+ assert_equal 16 + 1 * 36 + 0 * 6 + 1, HighLine::Style.rgb_number(43, 0, 43)
+
+ assert_equal 16 + 1 * 36 + 0 * 6 + 0, HighLine::Style.rgb_number(43, 42, 0)
+ assert_equal 16 + 1 * 36 + 0 * 6 + 0, HighLine::Style.rgb_number(43, 42, 42)
+ assert_equal 16 + 1 * 36 + 0 * 6 + 1, HighLine::Style.rgb_number(43, 42, 43)
+
+ assert_equal 16 + 1 * 36 + 1 * 6 + 0, HighLine::Style.rgb_number(43, 43, 0)
+ 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)
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)
-
- 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", 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", 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", 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", 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 "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", 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 "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 "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", 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", 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", 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", 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", 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 "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", 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 "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)
+
# 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", HighLine::Style.ansi_rgb_to_hex(16 + 5 * 36 + 5 * 6 + 5)
end
-
+
def test_list
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
+ 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
@@ -392,30 +391,30 @@ class TestStyle < Minitest::Test
# Add another Style with a new name and code
assert_nil HighLine::Style.list[:s6]
- s6 = HighLine::Style.new(:name=>:s6, :code=>'bar')
- assert_equal list_size+2, HighLine::Style.list.size
+ 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
-
+
# 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
+ s7 = HighLine::Style.new(name: :s6, code: 'baz')
+ assert_equal list_size + 2, HighLine::Style.list.size # No net addition to list
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
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_equal list_size+1, HighLine::Style.code_index.size
+ 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
@@ -423,8 +422,8 @@ class TestStyle < Minitest::Test
# Add another Style with a new name and code
assert_nil HighLine::Style.code_index['c3po']
- HighLine::Style.new(:name=>:s9, :code=>'c3po')
- assert_equal list_size+2, HighLine::Style.code_index.size
+ 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
@@ -432,33 +431,33 @@ class TestStyle < Minitest::Test
# 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 list_size+2, HighLine::Style.code_index.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
end
-
+
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" )
+ 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" )
+ HighLine::Style.uncolor("This should be \e[38;5;137mrgb_906030\e[0m!\n")
end
-
+
def test_color
assert_equal "\e[99mstring\e[0m", @style1.color("string") # simple style
assert_equal "\e[99m\e[98mstring\e[0m", @style3.color("string") # Style list
end
-
+
def test_code
assert_equal "\e[99m", @style1.code # simple style
assert_equal "\e[99m\e[98m", @style3.code # Style list
end
-
+
def test_red
assert_equal 0x65, @style4.red
assert_equal 0, HighLine::Style(:none).red # Probably reliable
@@ -466,15 +465,15 @@ class TestStyle < Minitest::Test
assert_equal 255, HighLine::Style(:bright_magenta).red # Seems to be reliable
assert_equal 255, HighLine::Style(:on_none).red # Probably reliable
end
-
+
def test_green
assert_equal 0x43, @style4.green
assert_equal 0, HighLine::Style(:none).green # Probably reliable
assert_equal 0, HighLine::Style(:black).green # Probably reliable
- assert 240 <= HighLine::Style(:bright_cyan).green # Probably reliable
+ assert HighLine::Style(:bright_cyan).green >= 240 # Probably reliable
assert_equal 255, HighLine::Style(:on_none).green # Probably reliable
end
-
+
def test_blue
assert_equal 0x21, @style4.blue
assert_equal 0, HighLine::Style(:none).blue # Probably reliable
@@ -482,121 +481,121 @@ class TestStyle < Minitest::Test
assert_equal 255, HighLine::Style(:bright_blue).blue # Probably reliable
assert_equal 255, HighLine::Style(:on_none).blue # Probably reliable
end
-
+
def test_builtin
assert HighLine::Style(:red).builtin
assert !@style1.builtin
end
-
+
def test_variant
style1_name = @style1.name
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 [1,2,3], s1.rgb # Unchanged
-
- s2 = @style1.variant(:new_foo2, :increment=>-15)
+ assert_equal [1, 2, 3], s1.rgb # Unchanged
+
+ s2 = @style1.variant(:new_foo2, increment: -15)
assert_instance_of HighLine::Style, s2
- refute_same @style1, s2 # This is a copy
+ refute_same @style1, s2 # This is a copy
assert_equal :new_foo2, s2.name # Changed
assert_equal "\e[84m", s2.code # 99 (original code) - 15
- assert_equal [1,2,3], s2.rgb # Unchanged
-
- s3 = @style1.variant(:new_foo3, :code=>"\e[55m", :increment=>15)
+ assert_equal [1, 2, 3], s2.rgb # Unchanged
+
+ s3 = @style1.variant(:new_foo3, code: "\e[55m", increment: 15)
assert_instance_of HighLine::Style, s3
- refute_same @style1, s3 # This is a copy
+ refute_same @style1, s3 # This is a copy
assert_equal :new_foo3, s3.name # Changed
assert_equal "\e[70m", s3.code # 99 (new code) + 15
- assert_equal [1,2,3], s3.rgb # Unchanged
-
- s4 = @style1.variant(:new_foo4, :code=>"\e[55m", :increment=>15, :rgb=>"blah")
+ assert_equal [1, 2, 3], s3.rgb # Unchanged
+
+ s4 = @style1.variant(:new_foo4, code: "\e[55m", increment: 15, rgb: "blah")
assert_instance_of HighLine::Style, s4
- refute_same @style1, s4 # This is a copy
+ 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
s5 = @style1.variant(:new_foo5)
assert_instance_of HighLine::Style, s5
- refute_same @style1, s5 # This is a copy
+ refute_same @style1, s5 # This is a copy
assert_equal :new_foo5, s5.name # Changed
assert_equal "\e[99m", s5.code # Unchanged
- assert_equal [1,2,3], s5.rgb # Unchanged
+ assert_equal [1, 2, 3], s5.rgb # Unchanged
# No @style1's have been harmed in the running of this test
assert_equal style1_name, @style1.name
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
end
-
+
def test_on
style1_name = @style1.name
style1_code = @style1.code
style1_rgb = @style1.rgb
-
+
s1 = @style1.on
assert_instance_of HighLine::Style, s1
- refute_same @style1, s1 # This is a copy
+ refute_same @style1, s1 # This is a copy
assert_equal :on_foo, s1.name # Changed
assert_equal "\e[109m", s1.code # Changed
- assert_equal [1,2,3], s1.rgb # Unchanged
+ assert_equal [1, 2, 3], s1.rgb # Unchanged
# No @style1's have been harmed in the running of this test
assert_equal style1_name, @style1.name
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
end
-
+
def test_bright
style1_name = @style1.name
style1_code = @style1.code
style1_rgb = @style1.rgb
-
+
s1 = @style1.bright
assert_instance_of HighLine::Style, s1
- refute_same @style1, s1 # This is a copy
+ refute_same @style1, s1 # This is a copy
assert_equal :bright_foo, s1.name # Changed
assert_equal "\e[159m", s1.code # Changed
- assert_equal [129,130,131], s1.rgb # Changed
+ assert_equal [129, 130, 131], s1.rgb # Changed
# No @style1's have been harmed in the running of this test
assert_equal style1_name, @style1.name
assert_equal style1_code, @style1.code
assert_equal style1_rgb, @style1.rgb
-
- s2_base = HighLine::Style.new(:name=>:leia, :code=>"\e[92m", :rgb=>[0,0,14])
+
+ s2_base = HighLine::Style.new(name: :leia, code: "\e[92m", rgb: [0, 0, 14])
s2 = s2_base.bright
assert_instance_of HighLine::Style, s2
- refute_same s2_base, s2 # This is a copy
+ refute_same s2_base, s2 # This is a copy
assert_equal :bright_leia, s2.name # Changed
assert_equal "\e[152m", s2.code # Changed
- assert_equal [0,0,142], s2.rgb # Changed
-
- s3_base = HighLine::Style.new(:name=>:luke, :code=>"\e[93m", :rgb=>[20,21,0])
+ assert_equal [0, 0, 142], s2.rgb # Changed
+
+ s3_base = HighLine::Style.new(name: :luke, code: "\e[93m", rgb: [20, 21, 0])
s3 = s3_base.bright
assert_instance_of HighLine::Style, s3
- refute_same s3_base, s3 # This is a copy
+ refute_same s3_base, s3 # This is a copy
assert_equal :bright_luke, s3.name # Changed
assert_equal "\e[153m", s3.code # Changed
- assert_equal [148,149,0], s3.rgb # Changed
-
- s4_base = HighLine::Style.new(:name=>:r2d2, :code=>"\e[94m", :rgb=>[0,0,0])
+ assert_equal [148, 149, 0], s3.rgb # Changed
+
+ s4_base = HighLine::Style.new(name: :r2d2, code: "\e[94m", rgb: [0, 0, 0])
s4 = s4_base.bright
assert_instance_of HighLine::Style, s4
- refute_same s4_base, s4 # This is a copy
+ refute_same s4_base, s4 # This is a copy
assert_equal :bright_r2d2, s4.name # Changed
assert_equal "\e[154m", s4.code # Changed
- assert_equal [128,128,128], s4.rgb # Changed; special case
-
+ assert_equal [128, 128, 128], s4.rgb # Changed; special case
+
assert_raises(::RuntimeError) { @style3.bright } # Can't create a variant of a list style
end
diff --git a/test/test_wrapper.rb b/test/test_wrapper.rb
index f7e4871..1db89fc 100644
--- a/test/test_wrapper.rb
+++ b/test/test_wrapper.rb
@@ -21,19 +21,19 @@ class TestHighLineWrapper < Minitest::Test
def test_wrap_long_lines_correctly
long_line =
- "This is a long flowing paragraph meant to span " +
- "several lines. This text should definitely be " +
- "wrapped at the set limit, in the result. Your code " +
+ "This is a long flowing paragraph meant to span " \
+ "several lines. This text should definitely be " \
+ "wrapped at the set limit, in the result. Your code " \
"does well with things like this.\n\n"
wrapped_long_line =
- "This is a long flowing paragraph meant to span " +
- "several lines. This text should\n" +
+ "This is a long flowing paragraph meant to span " \
+ "several lines. This text should\n" \
- "definitely be wrapped at the set limit, in the " +
- "result. Your code does well with\n" +
+ "definitely be wrapped at the set limit, in the " \
+ "result. Your code does well with\n" \
- "things like this.\n\n"
+ "things like this.\n\n"
wrapped = wrap(long_line)
assert_equal wrapped_long_line, wrapped
@@ -41,13 +41,13 @@ class TestHighLineWrapper < Minitest::Test
def test_dont_wrap_already_well_wrapped_text
well_formatted_text =
- " * This is a simple embedded list.\n" +
- " * You're code should not mess with this...\n" +
- " * Because it's already formatted correctly and does not\n" +
+ " * This is a simple embedded list.\n" \
+ " * You're code should not mess with this...\n" \
+ " * Because it's already formatted correctly and does not\n" \
" exceed the limit!\n"
wrapped = wrap(well_formatted_text)
- assert_equal well_formatted_text, wrapped
+ assert_equal well_formatted_text, wrapped
end
def test_wrap_single_word_longer_than_wrap_at
@@ -185,4 +185,4 @@ class TestHighLineWrapper < Minitest::Test
end
end
end
-end \ No newline at end of file
+end