summaryrefslogtreecommitdiff
path: root/test/test_highline.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_highline.rb')
-rwxr-xr-xtest/test_highline.rb110
1 files changed, 110 insertions, 0 deletions
diff --git a/test/test_highline.rb b/test/test_highline.rb
index 9cdfeb4..ce1233d 100755
--- a/test/test_highline.rb
+++ b/test/test_highline.rb
@@ -502,9 +502,119 @@ class TestHighLine < Minitest::Test
# turn off color
old_setting = HighLine.use_color?
HighLine.use_color = false
+ @terminal.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
+ @terminal.use_color = old_setting
+ end
+
+ def test_color_setting_per_instance
+ require 'highline/import'
+ old_glob_term = $terminal
+ old_setting = HighLine.use_color?
+
+ gterm_input = StringIO.new
+ gterm_output = StringIO.new
+ $terminal = HighLine.new(gterm_input, gterm_output)
+
+ # It can set coloring at HighLine class
+ cli_input = StringIO.new
+ cli_output = StringIO.new
+
+ cli = HighLine.new(cli_input, cli_output)
+
+ # Testing with both use_color setted to true
+ HighLine.use_color = true
+ @terminal.use_color = true
+ cli.use_color = true
+
+ say("This should be <%= color('cyan', CYAN) %>!")
+ assert_equal("This should be \e[36mcyan\e[0m!\n", gterm_output.string)
+
+ @terminal.say("This should be <%= color('cyan', CYAN) %>!")
+ 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 \e[36mcyan\e[0m!\n", cli_output.string)
+
+ gterm_output.truncate(gterm_output.rewind)
+ @output.truncate(@output.rewind)
+ cli_output.truncate(cli_output.rewind)
+
+ # Testing with both use_color setted to false
+ HighLine.use_color = false
+ @terminal.use_color = false
+ cli.use_color = false
+
+ say("This should be <%= color('cyan', CYAN) %>!")
+ assert_equal("This should be cyan!\n", gterm_output.string)
+
+ @terminal.say("This should be <%= color('cyan', CYAN) %>!")
+ assert_equal("This should be cyan!\n", @output.string)
+
+ cli.say("This should be <%= color('cyan', CYAN) %>!")
+ assert_equal("This should be cyan!\n", cli_output.string)
+
+ gterm_output.truncate(gterm_output.rewind)
+ @output.truncate(@output.rewind)
+ cli_output.truncate(cli_output.rewind)
+
+ # Now check when class and instance doesn't agree about use_color
+
+ # Class false, instance true
+ HighLine.use_color = false
+ @terminal.use_color = false
+ cli.use_color = true
+
+ say("This should be <%= color('cyan', CYAN) %>!")
+ assert_equal("This should be cyan!\n", gterm_output.string)
+
+ @terminal.say("This should be <%= color('cyan', CYAN) %>!")
+ assert_equal("This should be cyan!\n", @output.string)
+
+ cli.say("This should be <%= color('cyan', CYAN) %>!")
+ assert_equal("This should be \e[36mcyan\e[0m!\n", cli_output.string)
+
+ gterm_output.truncate(gterm_output.rewind)
+ @output.truncate(@output.rewind)
+ cli_output.truncate(cli_output.rewind)
+
+ # Class true, instance false
+ HighLine.use_color = true
+ @terminal.use_color = true
+ cli.use_color = false
+
+ say("This should be <%= color('cyan', CYAN) %>!")
+ assert_equal("This should be \e[36mcyan\e[0m!\n", gterm_output.string)
+
+ @terminal.say("This should be <%= color('cyan', CYAN) %>!")
+ 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 )
+
+ gterm_output.truncate(gterm_output.rewind)
+ @output.truncate(@output.rewind)
+ cli_output.truncate(cli_output.rewind)
+
+ HighLine.use_color = old_setting
+ @terminal.use_color = old_setting
+ $terminal = old_glob_term
+ end
+
+ def test_reset_use_color
+ HighLine.use_color = false
+ refute HighLine.use_color?
+ HighLine.reset_use_color
+ assert HighLine.use_color?
+ end
+
+ def test_reset_use_color_when_highline_reset
+ HighLine.use_color = false
+ refute HighLine.use_color?
+ HighLine.reset
+ assert HighLine.use_color?
end
def test_uncolor