summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAbinoam Praxedes Marques Jr <abinoam@gmail.com>2015-07-06 21:56:21 -0300
committerAbinoam Praxedes Marques Jr <abinoam@gmail.com>2015-07-06 21:56:21 -0300
commit5903ec1f95696a08b9253c788e7b2a4e581068ed (patch)
tree5ed6d330df57c30cae0fb805f3e844273c6f9731 /test
parent327051c1c217df2880c3a53f31484f7e815e847f (diff)
parentbb9902245d4a719c191e4e01d7e9a5a9e53d38ee (diff)
downloadhighline-5903ec1f95696a08b9253c788e7b2a4e581068ed.tar.gz
Merge branch 'v2.0.0-develop' into master solving conflictsv2.0.0.pre.develop.1v2.0.0-develop.1
Diffstat (limited to 'test')
-rw-r--r--test/string_methods.rb3
-rw-r--r--test/test_color_scheme.rb (renamed from test/tc_color_scheme.rb)17
-rw-r--r--test/test_helper.rb11
-rwxr-xr-xtest/test_highline.rb (renamed from test/tc_highline.rb)162
-rw-r--r--test/test_import.rb (renamed from test/tc_import.rb)8
-rw-r--r--test/test_list.rb61
-rw-r--r--test/test_menu.rb (renamed from test/tc_menu.rb)10
-rw-r--r--test/test_paginator.rb31
-rw-r--r--test/test_simulator.rb25
-rw-r--r--test/test_string_extension.rb (renamed from test/tc_string_extension.rb)21
-rw-r--r--test/test_string_highline.rb (renamed from test/tc_string_highline.rb)11
-rwxr-xr-xtest/test_style.rb (renamed from test/tc_style.rb)96
-rw-r--r--test/test_wrapper.rb189
13 files changed, 500 insertions, 145 deletions
diff --git a/test/string_methods.rb b/test/string_methods.rb
index 0ae2c5c..9c61359 100644
--- a/test/string_methods.rb
+++ b/test/string_methods.rb
@@ -1,3 +1,6 @@
+#!/usr/bin/env ruby
+# coding: utf-8
+
# string_methods.rb
#
# Created by Richard LeBer 2011-06-27
diff --git a/test/tc_color_scheme.rb b/test/test_color_scheme.rb
index a6c6c1a..388c0ea 100644
--- a/test/tc_color_scheme.rb
+++ b/test/test_color_scheme.rb
@@ -1,3 +1,6 @@
+#!/usr/bin/env ruby
+# coding: utf-8
+
# tc_color_scheme.rb
#
# Created by Jeremy Hinegardner on 2007-01-24.
@@ -5,22 +8,18 @@
#
# This is Free Software. See LICENSE and COPYING for details.
-require "test/unit"
+require "minitest/autorun"
+require "test_helper"
require "highline"
require "stringio"
-class TestColorScheme < Test::Unit::TestCase
+class TestColorScheme < Minitest::Test
def setup
+ HighLine.reset
@input = StringIO.new
@output = StringIO.new
@terminal = HighLine.new(@input, @output)
-
- @old_color_scheme = HighLine.color_scheme
- end
-
- def teardown
- HighLine.color_scheme = @old_color_scheme
end
def test_using_color_scheme
@@ -88,7 +87,7 @@ class TestColorScheme < Test::Unit::TestCase
assert_equal [:bold, :yellow], HighLine.color_scheme.definition(:warning)
# turn it back off, should raise an exception
- HighLine.color_scheme = @old_color_scheme
+ HighLine.color_scheme = nil
assert_raises(NameError) {
@terminal.say("This should be <%= color('nothing at all', :error) %>.")
}
diff --git a/test/test_helper.rb b/test/test_helper.rb
new file mode 100644
index 0000000..ac8e809
--- /dev/null
+++ b/test/test_helper.rb
@@ -0,0 +1,11 @@
+#!/usr/bin/env ruby
+# coding: utf-8
+
+require 'simplecov'
+SimpleCov.start do
+ add_filter "test_"
+end
+
+require "codeclimate-test-reporter"
+CodeClimate::TestReporter.start
+
diff --git a/test/tc_highline.rb b/test/test_highline.rb
index cdda30a..b3e822b 100755
--- a/test/tc_highline.rb
+++ b/test/test_highline.rb
@@ -1,4 +1,6 @@
-# encoding: utf-8
+#!/usr/bin/env ruby
+# coding: utf-8
+
# tc_highline.rb
#
# Created by James Edward Gray II on 2005-04-26.
@@ -6,13 +8,16 @@
#
# This is Free Software. See LICENSE and COPYING for details.
-require "test/unit"
+require "minitest/autorun"
+require "test_helper"
require "highline"
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.
@@ -21,9 +26,11 @@ if HighLine::CHARACTER_MODE == "Win32API"
end
end
end
+=end
-class TestHighLine < Test::Unit::TestCase
+class TestHighLine < Minitest::Test
def setup
+ HighLine.reset
@input = StringIO.new
@output = StringIO.new
@terminal = HighLine.new(@input, @output)
@@ -60,7 +67,7 @@ class TestHighLine < Test::Unit::TestCase
assert_equal(name, @terminal.ask("What is your name? "))
- assert_raise(EOFError) { @terminal.ask("Any input left? ") }
+ assert_raises(EOFError) { @terminal.ask("Any input left? ") }
end
def test_ask_string
@@ -70,9 +77,28 @@ class TestHighLine < Test::Unit::TestCase
assert_equal(name, @terminal.ask("What is your name? ", String))
- assert_raise(EOFError) { @terminal.ask("Any input left? ", String) }
+ assert_raises(EOFError) { @terminal.ask("Any input left? ", String) }
+ end
+
+ def test_ask_string_converting
+ name = "James Edward Gray II"
+ @input << name << "\n"
+ @input.rewind
+
+ answer = @terminal.ask("What is your name? ", String)
+
+ assert_instance_of HighLine::String, answer
+
+ @input.rewind
+
+ answer = @terminal.ask("What is your name? ", HighLine::String)
+
+ assert_instance_of HighLine::String, answer
+
+ assert_raises(EOFError) { @terminal.ask("Any input left? ", HighLine::String) }
end
+
def test_indent
text = "Testing...\n"
@terminal.indent_level=1
@@ -91,28 +117,29 @@ class TestHighLine < Test::Unit::TestCase
assert_equal(' '*10+text, @output.string)
@output.truncate(@output.rewind)
+ @terminal.indent_level=0
@terminal.indent_size=4
@terminal.indent {
- @terminal.say(text)
+ @terminal.say(text)
}
assert_equal(' '*4+text, @output.string)
@output.truncate(@output.rewind)
@terminal.indent_size=2
@terminal.indent(3) { |t|
- t.say(text)
+ t.say(text)
}
assert_equal(' '*6+text, @output.string)
@output.truncate(@output.rewind)
@terminal.indent { |t|
+ t.indent {
t.indent {
- t.indent {
- t.indent { |tt|
- tt.say(text)
- }
- }
+ t.indent { |tt|
+ tt.say(text)
+ }
}
+ }
}
assert_equal(' '*8+text, @output.string)
@@ -392,7 +419,7 @@ class TestHighLine < Test::Unit::TestCase
# turn off color
old_setting = HighLine.use_color?
- assert_nothing_raised(Exception) { HighLine.use_color = false }
+ HighLine.use_color = false
@terminal.say("This should be <%= color('cyan', CYAN) %>!")
assert_equal("This should be cyan!\n", @output.string)
HighLine.use_color = old_setting
@@ -448,7 +475,7 @@ class TestHighLine < Test::Unit::TestCase
@input.rewind
answer = @terminal.ask("Enter a filename: ") do |q|
- q.confirm = "Are you sure you want to overwrite <%= @answer %>? "
+ q.confirm = "Are you sure you want to overwrite <%= answer %>? "
q.responses[:ask_on_error] = :question
end
assert_equal("save.txt", answer)
@@ -464,7 +491,7 @@ class TestHighLine < Test::Unit::TestCase
@output.truncate(@output.rewind)
answer = @terminal.ask("Enter a filename: ") do |q|
- q.confirm = "Are you sure you want to overwrite <%= @answer %>? "
+ q.confirm = "Are you sure you want to overwrite <%= answer %>? "
end
assert_equal("junk.txt", answer)
assert_equal( "Enter a filename: " +
@@ -576,10 +603,10 @@ class TestHighLine < Test::Unit::TestCase
end
def test_files
- @input << "#{File.basename(__FILE__)[0, 5]}\n"
+ @input << "#{File.basename(__FILE__)[0, 7]}\n"
@input.rewind
- assert_equal "tc_hi\n",@input.read
+ assert_equal "test_hi\n",@input.read
@input.rewind
file = @terminal.ask("Select a file: ", File) do |q|
@@ -587,7 +614,7 @@ class TestHighLine < Test::Unit::TestCase
q.glob = "*.rb"
end
assert_instance_of(File, file)
- assert_equal("# encoding: utf-8\n", file.gets)
+ assert_equal("#!/usr/bin/env ruby\n", file.gets)
file.close
@input.rewind
@@ -600,7 +627,7 @@ class TestHighLine < Test::Unit::TestCase
assert_equal(File.size(__FILE__), pathname.size)
end
- def test_gather
+ def test_gather_with_integer
@input << "James\nDana\nStorm\nGypsy\n\n"
@input.rewind
@@ -610,27 +637,33 @@ class TestHighLine < Test::Unit::TestCase
assert_equal(%w{James Dana Storm Gypsy}, answers)
assert_equal("\n", @input.gets)
assert_equal("Enter four names:\n", @output.string)
+ end
+ def test_gather_with_an_empty_string
+ @input << "James\nDana\nStorm\nGypsy\n\n"
@input.rewind
answers = @terminal.ask("Enter four names:") do |q|
q.gather = ""
end
assert_equal(%w{James Dana Storm Gypsy}, answers)
+ end
+ def test_gather_with_regexp
+ @input << "James\nDana\nStorm\nGypsy\n\n"
@input.rewind
answers = @terminal.ask("Enter four names:") do |q|
q.gather = /^\s*$/
end
assert_equal(%w{James Dana Storm Gypsy}, answers)
+ end
- @input.truncate(@input.rewind)
+ def test_gather_with_hash
@input << "29\n49\n30\n"
@input.rewind
- @output.truncate(@output.rewind)
- answers = @terminal.ask("<%= @key %>: ", Integer) do |q|
+ answers = @terminal.ask("<%= key %>: ", Integer) do |q|
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},
@@ -669,7 +702,7 @@ class TestHighLine < Test::Unit::TestCase
@input.rewind
@output.truncate(@output.rewind)
- answer = @terminal.ask("<%= @key %>: ") do |q|
+ answer = @terminal.ask("<%= key %>: ") do |q|
q.verify_match = true
q.gather = {"Enter a password" => '', "Please type it again" => ''}
end
@@ -680,7 +713,7 @@ class TestHighLine < Test::Unit::TestCase
@input.rewind
@output.truncate(@output.rewind)
- answer = @terminal.ask("<%= @key %>: ") do |q|
+ answer = @terminal.ask("<%= key %>: ") do |q|
q.verify_match = true
q.responses[:mismatch] = 'Typing mismatch!'
q.responses[:ask_on_error] = ''
@@ -855,8 +888,8 @@ class TestHighLine < Test::Unit::TestCase
end
def test_mode
- assert(%w[Win32API termios ncurses stty jline].include?(HighLine::CHARACTER_MODE),
- "#{HighLine::CHARACTER_MODE} not in list")
+ assert(%w[Win32API termios ncurses stty unix_stty jline].include?(@terminal.terminal.character_mode),
+ "#{@terminal.terminal.character_mode} not in list")
end
class NameClass
@@ -935,7 +968,7 @@ class TestHighLine < Test::Unit::TestCase
q.echo = false
end
- assert_not_equal("password", answer)
+ refute_equal("password", answer)
assert_equal("passwor", answer)
end
@@ -947,7 +980,7 @@ class TestHighLine < Test::Unit::TestCase
q.echo = false
end
- assert_not_equal("maçã", answer)
+ refute_equal("maçã", answer)
assert_equal("maç", answer)
end
@@ -962,21 +995,6 @@ class TestHighLine < Test::Unit::TestCase
assert_equal("Type: ****\n", @output.string)
assert_equal("maçã", answer)
end
-
- def test_paging
- @terminal.page_at = 22
-
- @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 +
- "\n-- press enter/return to continue or q to stop -- \n\n" +
- (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 )
- end
def test_range_requirements
@input << "112\n-541\n28\n"
@@ -1095,8 +1113,8 @@ class TestHighLine < Test::Unit::TestCase
answer = @terminal.ask("Tell me your age.", Integer) do |q|
q.in = 0..105
- q.responses[:not_in_range] = "Need a <%= @question.answer_type %>" +
- " <%= @question.expected_range %>."
+ q.responses[:not_in_range] = "Need a <%= question.answer_type %>" +
+ " <%= question.expected_range %>."
end
assert_equal(28, answer)
assert_equal( "Tell me your age.\n" +
@@ -1144,7 +1162,7 @@ class TestHighLine < Test::Unit::TestCase
@output.truncate(@output.rewind)
- assert_nothing_raised { @terminal.say(nil) }
+ @terminal.say(nil)
assert_equal("", @output.string)
end
@@ -1152,18 +1170,18 @@ class TestHighLine < Test::Unit::TestCase
integer = 10
hash = { :a => 20 }
- assert_nothing_raised { @terminal.say(integer) }
+ @terminal.say(integer)
assert_equal String(integer), @output.string.chomp
@output.truncate(@output.rewind)
- assert_nothing_raised { @terminal.say(hash) }
+ @terminal.say(hash)
assert_equal String(hash), @output.string.chomp
end
def test_terminal_size
- assert_instance_of(Fixnum, @terminal.terminal_size[0])
- assert_instance_of(Fixnum, @terminal.terminal_size[1])
+ assert_instance_of(Fixnum, @terminal.terminal.terminal_size[0])
+ assert_instance_of(Fixnum, @terminal.terminal.terminal_size[1])
end
def test_type_conversion
@@ -1303,58 +1321,24 @@ class TestHighLine < Test::Unit::TestCase
assert_equal(" A lot\tof \t space\t \there! \n", answer)
end
- def test_wrap
- @terminal.wrap_at = 80
-
- @terminal.say("This is a very short line.")
- assert_equal("This is a very short line.\n", @output.string)
-
- @output.truncate(@output.rewind)
-
- @terminal.say( "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" +
- " * 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!" )
- assert_equal( "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" +
- "things like this.\n\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", @output.string )
-
- @output.truncate(@output.rewind)
-
- @terminal.say("-=" * 50)
- assert_equal(("-=" * 40 + "\n") + ("-=" * 10 + "\n"), @output.string)
- end
-
def test_track_eof
- assert_raise(EOFError) { @terminal.ask("Any input left? ") }
+ assert_raises(EOFError) { @terminal.ask("Any input left? ") }
# turn EOF tracking
old_setting = HighLine.track_eof?
- assert_nothing_raised(Exception) { HighLine.track_eof = false }
+ HighLine.track_eof = false
begin
@terminal.ask("And now? ") # this will still blow up, nothing available
rescue
- assert_not_equal(EOFError, $!.class) # but HighLine's safe guards are off
+ refute_equal(EOFError, $!.class) # but HighLine's safe guards are off
end
HighLine.track_eof = old_setting
end
def test_version
- assert_not_nil(HighLine::VERSION)
+ refute_nil(HighLine::VERSION)
assert_instance_of(String, HighLine::VERSION)
assert(HighLine::VERSION.frozen?)
- assert_match(/\A\d+\.\d+\.\d+\Z/, HighLine::VERSION)
+ assert_match(/\A\d+\.\d+\.\d+(-.*)?/, HighLine::VERSION)
end
end
diff --git a/test/tc_import.rb b/test/test_import.rb
index 4077dfc..4bac518 100644
--- a/test/tc_import.rb
+++ b/test/test_import.rb
@@ -1,3 +1,6 @@
+#!/usr/bin/env ruby
+# coding: utf-8
+
# tc_import.rb
#
# Created by James Edward Gray II on 2005-04-26.
@@ -5,12 +8,13 @@
#
# This is Free Software. See LICENSE and COPYING for details.
-require "test/unit"
+require "minitest/autorun"
+require "test_helper"
require "highline/import"
require "stringio"
-class TestImport < Test::Unit::TestCase
+class TestImport < Minitest::Test
def test_import
assert_respond_to(self, :agree)
assert_respond_to(self, :ask)
diff --git a/test/test_list.rb b/test/test_list.rb
new file mode 100644
index 0000000..c363642
--- /dev/null
+++ b/test/test_list.rb
@@ -0,0 +1,61 @@
+#!/usr/bin/env ruby
+# coding: utf-8
+
+require "minitest/autorun"
+require "test_helper"
+
+require "highline/list"
+
+class TestHighLineList < Minitest::Test
+ def setup
+ @items = [ "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" ] ]
+
+ highline_list = HighLine::List.new(@items, cols: 2)
+
+ assert_equal list_in_two_cols, highline_list.list
+ end
+
+ def test_in_2_cols_col_down
+ col_down_list =
+ [ [ "a", "f"],
+ [ "b", "g"],
+ [ "c", "h"],
+ [ "d", "i"],
+ [ "e", "j"] ]
+
+ highline_list = HighLine::List.new(@items, cols: 2, col_down: true)
+
+ assert_equal col_down_list, highline_list.list
+ end
+
+ def test_in_2_cols_transposed
+ transposed_list =
+ [ [ "a", "c", "e", "g", "i" ],
+ [ "b", "d", "f", "h", "j" ] ]
+
+ highline_list = HighLine::List.new(@items, cols: 2, transpose: true)
+
+ assert_equal transposed_list, highline_list.list
+ end
+
+ def test_in_3_cols
+ list_in_three_cols =
+ [ [ "a", "b", "c" ],
+ [ "d", "e", "f" ],
+ [ "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
diff --git a/test/tc_menu.rb b/test/test_menu.rb
index b6e7301..de01115 100644
--- a/test/tc_menu.rb
+++ b/test/test_menu.rb
@@ -1,4 +1,6 @@
+#!/usr/bin/env ruby
# coding: utf-8
+
# tc_menu.rb
#
# Created by Gregory Thomas Brown on 2005-05-10.
@@ -6,13 +8,15 @@
#
# This is Free Software. See LICENSE and COPYING for details.
-require "test/unit"
+require "minitest/autorun"
+require "test_helper"
require "highline"
require "stringio"
-class TestMenu < Test::Unit::TestCase
+class TestMenu < Minitest::Test
def setup
+ HighLine.reset
@input = StringIO.new
@output = StringIO.new
@terminal = HighLine.new(@input, @output)
@@ -201,7 +205,7 @@ class TestMenu < Test::Unit::TestCase
@output.truncate(@output.rewind)
@terminal.choose(:load, :save, :quit) do |menu|
- menu.layout = '<%= list(@menu) %>File Menu: '
+ menu.layout = '<%= list(menu) %>File Menu: '
end
assert_equal("1. load\n2. save\n3. quit\nFile Menu: ", @output.string)
end
diff --git a/test/test_paginator.rb b/test/test_paginator.rb
new file mode 100644
index 0000000..5f89899
--- /dev/null
+++ b/test/test_paginator.rb
@@ -0,0 +1,31 @@
+#!/usr/bin/env ruby
+# coding: utf-8
+
+require "minitest/autorun"
+require "test_helper"
+
+require "highline"
+
+class TestHighLinePaginator < Minitest::Test
+ def setup
+ HighLine.reset
+ @input = StringIO.new
+ @output = StringIO.new
+ @terminal = HighLine.new(@input, @output)
+ end
+
+ def test_paging
+ @terminal.page_at = 22
+
+ @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 +
+ "\n-- press enter/return to continue or q to stop -- \n\n" +
+ (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 )
+ end
+end \ No newline at end of file
diff --git a/test/test_simulator.rb b/test/test_simulator.rb
new file mode 100644
index 0000000..15691d9
--- /dev/null
+++ b/test/test_simulator.rb
@@ -0,0 +1,25 @@
+require "minitest/autorun"
+require "test_helper"
+
+require "highline/import"
+require "highline/simulate"
+
+class SimulatorTest < Minitest::Test
+ def setup
+ input = StringIO.new
+ output = StringIO.new
+ $terminal = HighLine.new(input, output)
+ end
+
+ def test_simulator
+ HighLine::Simulate.with("Bugs Bunny", "18") do
+ name = ask("What is your name?")
+
+ assert_equal "Bugs Bunny", name
+
+ age = ask("What is your age?")
+
+ assert_equal "18", age
+ end
+ end
+end \ No newline at end of file
diff --git a/test/tc_string_extension.rb b/test/test_string_extension.rb
index 63770be..2527da5 100644
--- a/test/tc_string_extension.rb
+++ b/test/test_string_extension.rb
@@ -1,19 +1,32 @@
+#!/usr/bin/env ruby
+# coding: utf-8
+
# tc_string_extension.rb
#
# Created by Richard LeBer 2011-06-27
#
# This is Free Software. See LICENSE and COPYING for details.
-require "test/unit"
+require "minitest/autorun"
+require "test_helper"
require "highline"
require "stringio"
require "string_methods"
-class TestStringExtension < Test::Unit::TestCase
+
+# FakeString is here just to avoid
+# using HighLine.colorize_strings
+# on tests
+
+class FakeString < String
+ include HighLine::StringExtensions
+end
+
+class TestStringExtension < Minitest::Test
def setup
- HighLine.colorize_strings
- @string = "string"
+ HighLine.reset
+ @string = FakeString.new "string"
end
include StringMethods
diff --git a/test/tc_string_highline.rb b/test/test_string_highline.rb
index a0428e8..ad450af 100644
--- a/test/tc_string_highline.rb
+++ b/test/test_string_highline.rb
@@ -1,17 +1,22 @@
+#!/usr/bin/env ruby
+# coding: utf-8
+
# tc_highline_string.rb
#
# Created by Richard LeBer 2011-06-27
#
# This is Free Software. See LICENSE and COPYING for details.
-require "test/unit"
+require "minitest/autorun"
+require "test_helper"
require "highline"
require "stringio"
require "string_methods"
-class TestHighLineString < Test::Unit::TestCase
+class TestHighLineString < Minitest::Test
def setup
+ HighLine.reset
@string = HighLine::String.new("string")
end
@@ -33,6 +38,6 @@ class TestHighLineString < Test::Unit::TestCase
include StringMethods
def test_string_class_is_unchanged
- assert_raise(::NoMethodError) { "string".color(:blue) }
+ assert_raises(::NoMethodError) { "string".color(:blue) }
end
end
diff --git a/test/tc_style.rb b/test/test_style.rb
index 13eeead..ccba936 100755
--- a/test/tc_style.rb
+++ b/test/test_style.rb
@@ -1,17 +1,22 @@
+#!/usr/bin/env ruby
+# coding: utf-8
+
# tc_style.rb
#
# Created by Richard LeBer on 2011-06-11.
#
# This is Free Software. See LICENSE and COPYING for details.
-require "test/unit"
+require "minitest/autorun"
+require "test_helper"
require "highline"
require "stringio"
-class TestStyle < Test::Unit::TestCase
+class TestStyle < Minitest::Test
def setup
+ HighLine.reset
@input = StringIO.new
@output = StringIO.new
@terminal = HighLine.new(@input, @output)
@@ -19,12 +24,33 @@ class TestStyle < Test::Unit::TestCase
@style2 = HighLine::Style.new(:name=>:lando, :code=>"\e[98m")
@style3 = HighLine::Style.new(:name=>[:foo, :lando], :list=>[: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
end
-
- def teardown
- # HighLine::Style.clear_index
+
+ def test_clear_index_reset_styles_to_builtin
+ styles_size_after_setup = HighLine::Style.list.size
+ expected_styles_size = styles_size_after_setup - @added_styles_on_setup
+
+ HighLine::Style.clear_index
+ styles_size_after_clear_index = HighLine::Style.list.size
+
+ assert_equal expected_styles_size, styles_size_after_clear_index
end
-
+
+ def test_clear_index_reset_code_index_to_builtin
+ code_index = HighLine::Style.code_index
+ code_index_array = code_index.map { |code, style_array| style_array }.flatten
+ expected_code_index_array_size = code_index_array.size - @added_codes_to_index
+
+ 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
+
+ assert_equal expected_code_index_array_size, cleared_code_index_array.size
+ end
+
def test_style_method
# Retrieve a style from an existing Style (no new Style created)
new_style = @style1.dup # This will replace @style1 in the indexes
@@ -101,12 +127,12 @@ class TestStyle < Test::Unit::TestCase
assert_equal [:underline, :blue], s1.list
# Raise an error for an undefined style
- assert_raise(::NameError) { HighLine.Style(:fubar) }
+ assert_raises(::NameError) { HighLine.Style(:fubar) }
end
def test_no_color_scheme
HighLine.color_scheme = nil
- assert_raise(::NameError) { HighLine.Style(:critical) }
+ assert_raises(::NameError) { HighLine.Style(:critical) }
end
def test_with_color_scheme
@@ -155,7 +181,7 @@ class TestStyle < Test::Unit::TestCase
assert_nil HighLine::Style.list[:s1]
assert_nil HighLine::Style.code_index['foo']
s1 = HighLine::Style.new(:name=>:s1, :code=>'foo')
- assert_not_nil HighLine::Style.list[:s1]
+ refute_nil HighLine::Style.list[:s1]
assert_same s1, HighLine::Style.list[:s1]
assert_equal :s1, HighLine::Style.list[:s1].name
assert_equal 'foo', HighLine::Style.list[:s1].code
@@ -173,7 +199,7 @@ class TestStyle < Test::Unit::TestCase
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
- assert_not_nil HighLine::Style.list[:s2]
+ refute_nil HighLine::Style.list[:s2]
assert_same s2, HighLine::Style.list[:s2]
assert_equal :s2, HighLine::Style.list[:s2].name
assert_equal 'bar', HighLine::Style.list[:s2].code
@@ -185,16 +211,16 @@ class TestStyle < Test::Unit::TestCase
# Add a Style with an existing name
s3_before = HighLine::Style.list[:s2]
- assert_not_nil HighLine::Style.list[:s2]
+ refute_nil HighLine::Style.list[:s2]
assert_nil HighLine::Style.code_index['baz']
s3 = HighLine::Style.new(:name=>:s2, :code=>'baz')
- assert_not_same s2, s3
- assert_not_same s3_before, s3
+ 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_not_nil HighLine::Style.list[:s2]
+ refute_nil HighLine::Style.list[:s2]
assert_same s3, HighLine::Style.list[:s2]
- assert_not_same s2, HighLine::Style.list[:s2]
+ refute_same s2, HighLine::Style.list[:s2]
assert_equal :s2, HighLine::Style.list[:s2].name
assert_equal 'baz', HighLine::Style.list[:s2].code
assert_instance_of Array, HighLine::Style.code_index['baz']
@@ -208,7 +234,7 @@ class TestStyle < Test::Unit::TestCase
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
- assert_not_nil HighLine::Style.list[:s4]
+ refute_nil HighLine::Style.list[:s4]
assert_same s4, HighLine::Style.list[:s4]
assert_equal :s4, HighLine::Style.list[:s4].name
assert_equal 'baz', HighLine::Style.list[:s4].code
@@ -348,9 +374,9 @@ class TestStyle < Test::Unit::TestCase
# Add a Style with a new name and code
assert_nil HighLine::Style.list[:s5]
s5 = HighLine::Style.new(:name=>:s5, :code=>'foo')
- assert_not_nil HighLine::Style.list[:s5]
+ refute_nil HighLine::Style.list[:s5]
assert_equal list_size+1, HighLine::Style.list.size
- assert_not_nil HighLine::Style.list[:s5]
+ refute_nil HighLine::Style.list[:s5]
assert_same s5, HighLine::Style.list[:s5]
assert_equal :s5, HighLine::Style.list[:s5].name
assert_equal 'foo', HighLine::Style.list[:s5].code
@@ -359,7 +385,7 @@ class TestStyle < Test::Unit::TestCase
assert_nil HighLine::Style.list[:s6]
s6 = HighLine::Style.new(:name=>:s6, :code=>'bar')
assert_equal list_size+2, HighLine::Style.list.size
- assert_not_nil HighLine::Style.list[:s6]
+ 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
@@ -367,9 +393,9 @@ class TestStyle < Test::Unit::TestCase
# 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
- assert_not_nil HighLine::Style.list[:s6]
+ refute_nil HighLine::Style.list[:s6]
assert_same s7, HighLine::Style.list[:s6] # New one replaces old one
- assert_not_same s6, HighLine::Style.list[:s6]
+ refute_same s6, HighLine::Style.list[:s6]
assert_equal :s6, HighLine::Style.list[:s6].name
assert_equal 'baz', HighLine::Style.list[:s6].code
end
@@ -460,35 +486,35 @@ class TestStyle < Test::Unit::TestCase
s1 = @style1.variant(:new_foo1, :code=>'abracadabra')
assert_instance_of HighLine::Style, s1
- assert_not_same @style1, s1 # This is a copy
+ 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_instance_of HighLine::Style, s2
- assert_not_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_instance_of HighLine::Style, s3
- assert_not_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_instance_of HighLine::Style, s4
- assert_not_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
- assert_not_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
@@ -498,7 +524,7 @@ class TestStyle < Test::Unit::TestCase
assert_equal style1_code, @style1.code
assert_equal style1_rgb, @style1.rgb
- assert_raise(::RuntimeError) { @style3.variant(:new_foo6) } # Can't create a variant of a list style
+ assert_raises(::RuntimeError) { @style3.variant(:new_foo6) } # Can't create a variant of a list style
end
def test_on
@@ -508,7 +534,7 @@ class TestStyle < Test::Unit::TestCase
s1 = @style1.on
assert_instance_of HighLine::Style, s1
- assert_not_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
@@ -518,7 +544,7 @@ class TestStyle < Test::Unit::TestCase
assert_equal style1_code, @style1.code
assert_equal style1_rgb, @style1.rgb
- assert_raise(::RuntimeError) { @style3.on } # Can't create a variant of a list style
+ assert_raises(::RuntimeError) { @style3.on } # Can't create a variant of a list style
end
def test_bright
@@ -528,7 +554,7 @@ class TestStyle < Test::Unit::TestCase
s1 = @style1.bright
assert_instance_of HighLine::Style, s1
- assert_not_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
@@ -541,7 +567,7 @@ class TestStyle < Test::Unit::TestCase
s2_base = HighLine::Style.new(:name=>:leia, :code=>"\e[92m", :rgb=>[0,0,14])
s2 = s2_base.bright
assert_instance_of HighLine::Style, s2
- assert_not_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
@@ -549,7 +575,7 @@ class TestStyle < Test::Unit::TestCase
s3_base = HighLine::Style.new(:name=>:luke, :code=>"\e[93m", :rgb=>[20,21,0])
s3 = s3_base.bright
assert_instance_of HighLine::Style, s3
- assert_not_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
@@ -557,19 +583,19 @@ class TestStyle < Test::Unit::TestCase
s4_base = HighLine::Style.new(:name=>:r2d2, :code=>"\e[94m", :rgb=>[0,0,0])
s4 = s4_base.bright
assert_instance_of HighLine::Style, s4
- assert_not_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_raise(::RuntimeError) { @style3.bright } # Can't create a variant of a list style
+ assert_raises(::RuntimeError) { @style3.bright } # Can't create a variant of a list style
end
def test_light_do_the_same_as_bright
bright_style = @style1.bright
light_style = @style1.light
- assert_not_equal bright_style, light_style
+ refute_equal bright_style, light_style
assert_equal :bright_foo, bright_style.name
assert_equal :light_foo, light_style.name
assert_equal bright_style.code, light_style.code
diff --git a/test/test_wrapper.rb b/test/test_wrapper.rb
new file mode 100644
index 0000000..6afcdff
--- /dev/null
+++ b/test/test_wrapper.rb
@@ -0,0 +1,189 @@
+#!/usr/bin/env ruby
+# coding: utf-8
+
+require "minitest/autorun"
+require "test_helper"
+
+require "highline/wrapper"
+
+class TestHighLineWrapper < Minitest::Test
+ def setup
+ @wrap_at = 80
+ end
+
+ def wrap(text)
+ HighLine::Wrapper.wrap text, @wrap_at
+ end
+
+ def test_dont_wrap_if_line_is_shorter_than_wrap_at
+ wrapped = wrap("This is a very short line.\n")
+ assert_equal "This is a very short line.\n", wrapped
+ end
+
+ 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 " +
+ "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" +
+
+ "definitely be wrapped at the set limit, in the " +
+ "result. Your code does well with\n" +
+
+ "things like this.\n\n"
+
+ wrapped = wrap(long_line)
+ assert_equal wrapped_long_line, wrapped
+ end
+
+ 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" +
+ " exceed the limit!\n"
+
+ wrapped = wrap(well_formatted_text)
+ assert_equal well_formatted_text, wrapped
+ end
+
+ def test_wrap_single_word_longer_than_wrap_at
+ wrapped = wrap("-=" * 50)
+ assert_equal(("-=" * 40 + "\n") + ("-=" * 10), wrapped)
+ end
+
+ def test_wrap_plain_text
+ line = "123 567 901 345"
+
+ 1.upto(25) do |wrap_at|
+ wrapped = HighLine::Wrapper.wrap(line, wrap_at)
+
+ case wrap_at
+ when 1
+ assert_equal "1\n2\n3\n5\n6\n7\n9\n0\n1\n3\n4\n5", wrapped
+ when 2
+ assert_equal "12\n3\n56\n7\n90\n1\n34\n5", wrapped
+ when 3..6
+ assert_equal "123\n567\n901\n345", wrapped
+ when 7..10
+ assert_equal "123 567\n901 345", wrapped
+ when 11..14
+ assert_equal "123 567 901\n345", wrapped
+ when 15..25
+ assert_equal "123 567 901 345", wrapped
+ end
+ end
+ end
+
+ def test_wrap_whole_colored_text
+ skip "TODO: Implement whole colored text wrapping!"
+ line = "\e[31m123 567 901 345\e[0m"
+
+ 1.upto(25) do |wrap_at|
+ wrapped = HighLine::Wrapper.wrap(line, wrap_at)
+
+ case wrap_at
+ when 1
+ assert_equal "\e[31m1\n2\n3\n5\n6\n7\n9\n0\n1\n3\n4\n5\e[0m", wrapped
+ when 2
+ assert_equal "\e[31m12\n3\n56\n7\n90\n1\n34\n5\e[0m", wrapped
+ when 3..6
+ assert_equal "\e[31m123\n567\n901\n345\e[0m", wrapped
+ when 7..10
+ assert_equal "\e[31m123 567\n901 345\e[0m", wrapped
+ when 11..14
+ assert_equal "\e[31m123 567 901\n345\e[0m", wrapped
+ when 15..25
+ assert_equal "\e[31m123 567 901 345\e[0m", wrapped
+ end
+ end
+ end
+
+ def test_wrap_partially_colored_text
+ skip "TODO: Implement middle colored text wrapping!"
+ line = "123 567 \e[31m901\e[0m 345"
+
+ 1.upto(25) do |wrap_at|
+ wrapped = HighLine::Wrapper.wrap(line, wrap_at)
+
+ case wrap_at
+ when 1
+ assert_equal "1\n2\n3\n5\n6\n7\n\e[31m9\n0\n1\e[0m\n3\n4\n5", wrapped
+ when 2
+ assert_equal "12\n3\n56\n7\n\e[31m90\n1\e[0m\n34\n5", wrapped
+ when 3..6
+ assert_equal "123\n567\n\e[31m901\e[0m\n345", wrapped
+ when 7..10
+ assert_equal "123 567\n\e[31m901\e[0m 345", wrapped
+ when 11..14
+ assert_equal "123 567 \e[31m901\e[0m\n345", wrapped
+ when 15..25
+ assert_equal "123 567 \e[31m901\e[0m 345", wrapped
+ end
+ end
+ end
+
+ def test_wrap_text_with_partially_colored_word_in_the_middle
+ skip "TODO: Implement middle partially colored text wrapping!"
+ line = "123 567 9\e[31m0\e[0m1 345"
+
+ 1.upto(25) do |wrap_at|
+ wrapped = HighLine::Wrapper.wrap(line, wrap_at)
+
+ case wrap_at
+ when 1
+ assert_equal "1\n2\n3\n5\n6\n7\n9\n\e[31m0\e[0m\n1\n3\n4\n5", wrapped
+ when 2
+ assert_equal "12\n3\n56\n7\n9\e[31m0\e[0m\n1\n34\n5", wrapped
+ when 3..6
+ assert_equal "123\n567\n9\e[31m0\e[0m1\n345", wrapped
+ when 7..10
+ assert_equal "123 567\n9\e[31m0\e[0m1 345", wrapped
+ when 11..14
+ assert_equal "123 567 9\e[31m0\e[0m1\n345", wrapped
+ when 15..25
+ assert_equal "123 567 9\e[31m0\e[0m1 345", wrapped
+ end
+ end
+ end
+
+ def test_wrap_when_multibyte_characters_present
+ line_ascii = "Sera um passaro?"
+ line_utf8 = "Será um pássaro?"
+
+ assert_equal 16, line_ascii.size
+ assert_equal 16, line_ascii.bytesize
+
+ assert_equal 16, line_utf8.size
+ assert_equal 18, line_utf8.bytesize
+
+ 1.upto(18) do |wrap_at|
+ wrapped = HighLine::Wrapper.wrap(line_utf8, wrap_at)
+
+ case wrap_at
+ when 1
+ assert_equal "S\ne\nr\ná\nu\nm\np\ná\ns\ns\na\nr\no\n?", wrapped
+ when 2
+ assert_equal "Se\nrá\num\npá\nss\nar\no?", wrapped
+ when 3
+ assert_equal "Ser\ná\num\npás\nsar\no?", wrapped
+ when 4
+ assert_equal "Será\num\npáss\naro?", wrapped
+ when 5
+ assert_equal "Será\num\npássa\nro?", wrapped
+ when 6
+ assert_equal "Será\num\npássar\no?", wrapped
+ when 7
+ assert_equal "Será um\npássaro\n?", wrapped
+ when 15..8
+ assert_equal "Será um\npássaro?", wrapped
+ when 16..18
+ assert_equal "Será um pássaro?", wrapped
+ end
+ end
+ end
+end \ No newline at end of file