highline 2.0.0.pre.develop.9 → 2.0.0.pre.develop.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +59 -5
- data/.travis.yml +9 -4
- data/Changelog.md +11 -0
- data/Gemfile +12 -19
- data/Rakefile +5 -11
- data/examples/ansi_colors.rb +6 -11
- data/examples/asking_for_arrays.rb +4 -3
- data/examples/basic_usage.rb +29 -22
- data/examples/color_scheme.rb +11 -10
- data/examples/get_character.rb +6 -5
- data/examples/limit.rb +2 -1
- data/examples/menus.rb +11 -11
- data/examples/overwrite.rb +7 -6
- data/examples/page_and_wrap.rb +5 -4
- data/examples/password.rb +2 -1
- data/examples/repeat_entry.rb +7 -5
- data/examples/trapping_eof.rb +2 -1
- data/examples/using_readline.rb +2 -1
- data/highline.gemspec +25 -25
- data/lib/highline.rb +103 -111
- data/lib/highline/builtin_styles.rb +45 -41
- data/lib/highline/color_scheme.rb +32 -28
- data/lib/highline/compatibility.rb +3 -3
- data/lib/highline/custom_errors.rb +2 -1
- data/lib/highline/import.rb +8 -11
- data/lib/highline/list.rb +4 -8
- data/lib/highline/list_renderer.rb +207 -201
- data/lib/highline/menu.rb +75 -63
- data/lib/highline/menu/item.rb +2 -0
- data/lib/highline/paginator.rb +5 -6
- data/lib/highline/question.rb +38 -36
- data/lib/highline/question/answer_converter.rb +2 -2
- data/lib/highline/question_asker.rb +15 -17
- data/lib/highline/simulate.rb +11 -13
- data/lib/highline/statement.rb +12 -10
- data/lib/highline/string.rb +9 -8
- data/lib/highline/string_extensions.rb +30 -14
- data/lib/highline/style.rb +68 -45
- data/lib/highline/template_renderer.rb +5 -5
- data/lib/highline/terminal.rb +24 -31
- data/lib/highline/terminal/io_console.rb +2 -2
- data/lib/highline/terminal/ncurses.rb +4 -3
- data/lib/highline/terminal/unix_stty.rb +12 -9
- data/lib/highline/version.rb +1 -1
- data/lib/highline/wrapper.rb +12 -11
- metadata +34 -43
- data/test/acceptance/acceptance.rb +0 -62
- data/test/acceptance/acceptance_test.rb +0 -69
- data/test/acceptance/at_color_output_using_erb_templates.rb +0 -17
- data/test/acceptance/at_echo_false.rb +0 -23
- data/test/acceptance/at_readline.rb +0 -37
- data/test/io_console_compatible.rb +0 -37
- data/test/string_methods.rb +0 -35
- data/test/test_answer_converter.rb +0 -26
- data/test/test_color_scheme.rb +0 -94
- data/test/test_helper.rb +0 -22
- data/test/test_highline.rb +0 -1627
- data/test/test_import.rb +0 -55
- data/test/test_list.rb +0 -60
- data/test/test_menu.rb +0 -749
- data/test/test_paginator.rb +0 -73
- data/test/test_question_asker.rb +0 -20
- data/test/test_simulator.rb +0 -24
- data/test/test_string_extension.rb +0 -72
- data/test/test_string_highline.rb +0 -42
- data/test/test_style.rb +0 -613
- data/test/test_wrapper.rb +0 -188
data/test/test_paginator.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# coding: utf-8
|
3
|
-
|
4
|
-
require "test_helper"
|
5
|
-
|
6
|
-
require "highline"
|
7
|
-
|
8
|
-
class TestHighLinePaginator < Minitest::Test
|
9
|
-
def setup
|
10
|
-
HighLine.reset
|
11
|
-
@input = StringIO.new
|
12
|
-
@output = StringIO.new
|
13
|
-
@terminal = HighLine.new(@input, @output)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_paging
|
17
|
-
@terminal.page_at = 22
|
18
|
-
|
19
|
-
@input << "\n\n"
|
20
|
-
@input.rewind
|
21
|
-
|
22
|
-
@terminal.say((1..50).map { |n| "This is line #{n}.\n"}.join)
|
23
|
-
assert_equal( (1..22).map { |n| "This is line #{n}.\n"}.join +
|
24
|
-
"\n-- press enter/return to continue or q to stop -- \n\n" +
|
25
|
-
(23..44).map { |n| "This is line #{n}.\n"}.join +
|
26
|
-
"\n-- press enter/return to continue or q to stop -- \n\n" +
|
27
|
-
(45..50).map { |n| "This is line #{n}.\n"}.join,
|
28
|
-
@output.string )
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_statement_lines_count_equal_to_page_at_shouldnt_paginate
|
32
|
-
@terminal.page_at = 6
|
33
|
-
|
34
|
-
@input << "\n"
|
35
|
-
@input.rewind
|
36
|
-
|
37
|
-
list = "a\nb\nc\nd\ne\nf\n"
|
38
|
-
|
39
|
-
@terminal.say(list)
|
40
|
-
assert_equal(list, @output.string)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_statement_with_one_line_bigger_than_page_at_should_paginate
|
44
|
-
@terminal.page_at = 6
|
45
|
-
|
46
|
-
@input << "\n"
|
47
|
-
@input.rewind
|
48
|
-
|
49
|
-
list = "a\nb\nc\nd\ne\nf\ng\n"
|
50
|
-
|
51
|
-
paginated =
|
52
|
-
"a\nb\nc\nd\ne\nf\n" \
|
53
|
-
"\n-- press enter/return to continue or q to stop -- \n\n" \
|
54
|
-
"g\n"
|
55
|
-
|
56
|
-
@terminal.say(list)
|
57
|
-
assert_equal(paginated, @output.string)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_quiting_paging_shouldnt_raise
|
61
|
-
# See https://github.com/JEG2/highline/issues/168
|
62
|
-
|
63
|
-
@terminal.page_at = 6
|
64
|
-
|
65
|
-
@input << "q"
|
66
|
-
@input.rewind
|
67
|
-
|
68
|
-
list = "a\nb\nc\nd\ne\nf\n"
|
69
|
-
|
70
|
-
# expect not to raise an error on next line
|
71
|
-
@terminal.say(list)
|
72
|
-
end
|
73
|
-
end
|
data/test/test_question_asker.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class TestQuestion < Minitest::Test
|
4
|
-
def setup
|
5
|
-
@input = StringIO.new
|
6
|
-
@output = StringIO.new
|
7
|
-
@highline = HighLine.new(@input, @output)
|
8
|
-
|
9
|
-
@question = HighLine::Question.new("How are you?", nil)
|
10
|
-
@asker = HighLine::QuestionAsker.new(@question, @highline)
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_ask_once
|
14
|
-
answer = "Very good, thanks for asking!"
|
15
|
-
|
16
|
-
@input.string = answer
|
17
|
-
|
18
|
-
assert_equal answer, @asker.ask_once
|
19
|
-
end
|
20
|
-
end
|
data/test/test_simulator.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
require "highline/import"
|
4
|
-
require "highline/simulate"
|
5
|
-
|
6
|
-
class SimulatorTest < Minitest::Test
|
7
|
-
def setup
|
8
|
-
input = StringIO.new
|
9
|
-
output = StringIO.new
|
10
|
-
$terminal = HighLine.new(input, output)
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_simulator
|
14
|
-
HighLine::Simulate.with("Bugs Bunny", "18") do
|
15
|
-
name = ask("What is your name?")
|
16
|
-
|
17
|
-
assert_equal "Bugs Bunny", name
|
18
|
-
|
19
|
-
age = ask("What is your age?")
|
20
|
-
|
21
|
-
assert_equal "18", age
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# coding: utf-8
|
3
|
-
|
4
|
-
# tc_string_extension.rb
|
5
|
-
#
|
6
|
-
# Created by Richard LeBer 2011-06-27
|
7
|
-
#
|
8
|
-
# This is Free Software. See LICENSE and COPYING for details.
|
9
|
-
|
10
|
-
require "test_helper"
|
11
|
-
|
12
|
-
require "highline"
|
13
|
-
require "stringio"
|
14
|
-
require "string_methods"
|
15
|
-
|
16
|
-
|
17
|
-
# FakeString is here just to avoid
|
18
|
-
# using HighLine.colorize_strings
|
19
|
-
# on tests
|
20
|
-
|
21
|
-
class FakeString < String
|
22
|
-
include HighLine::StringExtensions
|
23
|
-
end
|
24
|
-
|
25
|
-
class TestStringExtension < Minitest::Test
|
26
|
-
def setup
|
27
|
-
HighLine.reset
|
28
|
-
@string = FakeString.new "string"
|
29
|
-
end
|
30
|
-
|
31
|
-
def teardown
|
32
|
-
HighLine.reset
|
33
|
-
end
|
34
|
-
|
35
|
-
include StringMethods
|
36
|
-
|
37
|
-
def test_Highline_String_is_yaml_serializable
|
38
|
-
require 'yaml'
|
39
|
-
unless Gem::Version.new(YAML::VERSION) < Gem::Version.new("2.0.2")
|
40
|
-
highline_string = HighLine::String.new("Yaml didn't messed with HighLine::String")
|
41
|
-
yaml_highline_string = highline_string.to_yaml
|
42
|
-
yaml_loaded_string = YAML.load(yaml_highline_string)
|
43
|
-
|
44
|
-
assert_equal "Yaml didn't messed with HighLine::String", yaml_loaded_string
|
45
|
-
assert_equal highline_string, yaml_loaded_string
|
46
|
-
assert_instance_of HighLine::String, yaml_loaded_string
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_highline_string_respond_to_color
|
51
|
-
assert HighLine::String.new("highline string").respond_to? :color
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_normal_string_doesnt_respond_to_color
|
55
|
-
refute "normal_string".respond_to? :color
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_highline_string_still_raises_for_non_available_messages
|
59
|
-
assert_raises(NoMethodError) do
|
60
|
-
@string.unknown_message
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_String_includes_StringExtension_when_receives_colorize_strings
|
65
|
-
@include_received = 0
|
66
|
-
caller = Proc.new { @include_received += 1 }
|
67
|
-
::String.stub :include, caller do
|
68
|
-
HighLine.colorize_strings
|
69
|
-
end
|
70
|
-
assert_equal 1, @include_received
|
71
|
-
end
|
72
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# coding: utf-8
|
3
|
-
|
4
|
-
# tc_highline_string.rb
|
5
|
-
#
|
6
|
-
# Created by Richard LeBer 2011-06-27
|
7
|
-
#
|
8
|
-
# This is Free Software. See LICENSE and COPYING for details.
|
9
|
-
|
10
|
-
require "test_helper"
|
11
|
-
|
12
|
-
require "highline"
|
13
|
-
require "stringio"
|
14
|
-
require "string_methods"
|
15
|
-
|
16
|
-
class TestHighLineString < Minitest::Test
|
17
|
-
def setup
|
18
|
-
HighLine.reset
|
19
|
-
@string = HighLine::String.new("string")
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_string_class
|
23
|
-
# Basic constructor
|
24
|
-
assert_equal HighLine::String, @string.class
|
25
|
-
assert_equal "string", @string
|
26
|
-
|
27
|
-
# Alternative constructor method
|
28
|
-
new_string = HighLine::String("string")
|
29
|
-
assert_equal HighLine::String, new_string.class
|
30
|
-
assert_equal @string, new_string
|
31
|
-
|
32
|
-
# String methods work
|
33
|
-
assert_equal 6, @string.size
|
34
|
-
assert_equal "STRING", @string.upcase
|
35
|
-
end
|
36
|
-
|
37
|
-
include StringMethods
|
38
|
-
|
39
|
-
def test_string_class_is_unchanged
|
40
|
-
assert_raises(::NoMethodError) { "string".color(:blue) }
|
41
|
-
end
|
42
|
-
end
|
data/test/test_style.rb
DELETED
@@ -1,613 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# coding: utf-8
|
3
|
-
|
4
|
-
# tc_style.rb
|
5
|
-
#
|
6
|
-
# Created by Richard LeBer on 2011-06-11.
|
7
|
-
#
|
8
|
-
# This is Free Software. See LICENSE and COPYING for details.
|
9
|
-
|
10
|
-
require "test_helper"
|
11
|
-
|
12
|
-
require "highline"
|
13
|
-
require "stringio"
|
14
|
-
|
15
|
-
class TestStyle < Minitest::Test
|
16
|
-
|
17
|
-
def setup
|
18
|
-
HighLine.reset
|
19
|
-
@input = StringIO.new
|
20
|
-
@output = StringIO.new
|
21
|
-
@terminal = HighLine.new(@input, @output)
|
22
|
-
@style1 = HighLine::Style.new(:name=>:foo, :code=>"\e[99m", :rgb=>[1,2,3])
|
23
|
-
@style2 = HighLine::Style.new(:name=>:lando, :code=>"\e[98m")
|
24
|
-
@style3 = HighLine::Style.new(:name=>[:foo, :lando], :list=>[:foo, :lando])
|
25
|
-
@style4 = HighLine::Style(:rgb_654321)
|
26
|
-
@added_styles_on_setup = 4 # update here if added more styles
|
27
|
-
@added_codes_to_index = 3 # :foo, :lando and :rgb_654321
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_clear_index_reset_styles_to_builtin
|
31
|
-
styles_size_after_setup = HighLine::Style.list.size
|
32
|
-
expected_styles_size = styles_size_after_setup - @added_styles_on_setup
|
33
|
-
|
34
|
-
HighLine::Style.clear_index
|
35
|
-
styles_size_after_clear_index = HighLine::Style.list.size
|
36
|
-
|
37
|
-
assert_equal expected_styles_size, styles_size_after_clear_index
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_clear_index_reset_code_index_to_builtin
|
41
|
-
code_index = HighLine::Style.code_index
|
42
|
-
code_index_array = code_index.map { |code, style_array| style_array }.flatten
|
43
|
-
expected_code_index_array_size = code_index_array.size - @added_codes_to_index
|
44
|
-
|
45
|
-
HighLine::Style.clear_index
|
46
|
-
|
47
|
-
cleared_code_index = HighLine::Style.code_index
|
48
|
-
cleared_code_index_array = cleared_code_index.map { |code, style_array| style_array }.flatten
|
49
|
-
|
50
|
-
assert_equal expected_code_index_array_size, cleared_code_index_array.size
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_style_method
|
54
|
-
# Retrieve a style from an existing Style (no new Style created)
|
55
|
-
new_style = @style1.dup # This will replace @style1 in the indexes
|
56
|
-
s = HighLine.Style(@style1)
|
57
|
-
assert_instance_of HighLine::Style, s
|
58
|
-
assert_same new_style, s # i.e. s===the latest style created, but not the one searched for
|
59
|
-
|
60
|
-
# Retrieve a style from a new Style (no new Style created)
|
61
|
-
s2 = HighLine::Style.new(:name=>:bar, :code=>"\e[97m")
|
62
|
-
s = HighLine.Style(s2)
|
63
|
-
assert_instance_of HighLine::Style, s
|
64
|
-
assert_same s2, s
|
65
|
-
|
66
|
-
# Create a builtin style from an existing ANSI escape string
|
67
|
-
s = HighLine.Style("\e[1m")
|
68
|
-
assert_instance_of HighLine::Style, s
|
69
|
-
assert_nil s.list
|
70
|
-
assert_equal "\e[1m", s.code
|
71
|
-
assert_equal :bold, s.name
|
72
|
-
assert s.builtin
|
73
|
-
|
74
|
-
# Create a builtin style from a new ANSI escape string
|
75
|
-
s = HighLine.Style("\e[96m")
|
76
|
-
assert_instance_of HighLine::Style, s
|
77
|
-
assert_nil s.list
|
78
|
-
assert_equal "\e[96m", s.code
|
79
|
-
assert s.builtin
|
80
|
-
|
81
|
-
# Create a non-builtin style from a string
|
82
|
-
s = HighLine.Style("\e[109m")
|
83
|
-
assert_instance_of HighLine::Style, s
|
84
|
-
assert_nil s.list
|
85
|
-
assert_equal "\e[109m", s.code
|
86
|
-
refute s.builtin
|
87
|
-
|
88
|
-
# Create a builtin style from a symbol
|
89
|
-
s = HighLine.Style(:red)
|
90
|
-
assert_instance_of HighLine::Style, s
|
91
|
-
assert_nil s.list
|
92
|
-
assert_equal :red, s.name
|
93
|
-
assert s.builtin
|
94
|
-
|
95
|
-
# Retrieve an existing style by name (no new Style created)
|
96
|
-
s = HighLine.Style(@style2.name)
|
97
|
-
assert_instance_of HighLine::Style, s
|
98
|
-
assert_same @style2, s
|
99
|
-
|
100
|
-
# See below for color scheme tests
|
101
|
-
|
102
|
-
# Create style from a Hash
|
103
|
-
s = HighLine.Style(:name=>:han, :code=>"blah", :rgb=>'phooey')
|
104
|
-
assert_instance_of HighLine::Style, s
|
105
|
-
assert_equal :han, s.name
|
106
|
-
assert_equal "blah", s.code
|
107
|
-
assert_equal "phooey", s.rgb
|
108
|
-
|
109
|
-
# Create style from an RGB foreground color code
|
110
|
-
s = HighLine.Style(:rgb_1f2e3d)
|
111
|
-
assert_instance_of HighLine::Style, s
|
112
|
-
assert_equal :rgb_1f2e3d, s.name
|
113
|
-
assert_equal "\e[38;5;23m", s.code # Trust me; more testing below
|
114
|
-
assert_equal [31,46,61], s.rgb # 0x1f==31, 0x2e==46, 0x3d=61
|
115
|
-
|
116
|
-
# Create style from an RGB background color code
|
117
|
-
s = HighLine.Style(:on_rgb_1f2e3d)
|
118
|
-
assert_instance_of HighLine::Style, s
|
119
|
-
assert_equal :on_rgb_1f2e3d, s.name
|
120
|
-
assert_equal "\e[48;5;23m", s.code # Trust me; more testing below
|
121
|
-
assert_equal [31,46,61], s.rgb # 0x1f==31, 0x2e==46, 0x3d=61
|
122
|
-
|
123
|
-
# Create a style list
|
124
|
-
s1 = HighLine.Style(:bold, :red)
|
125
|
-
assert_instance_of HighLine::Style, s1
|
126
|
-
assert_equal [:bold, :red], s1.list
|
127
|
-
|
128
|
-
# Find an existing style list
|
129
|
-
s2 = HighLine.Style(:bold, :red)
|
130
|
-
assert_instance_of HighLine::Style, s2
|
131
|
-
assert_same s1, s2
|
132
|
-
|
133
|
-
# Create a style list with nils
|
134
|
-
s1 = HighLine.Style(:underline, nil, :blue)
|
135
|
-
assert_instance_of HighLine::Style, s1
|
136
|
-
assert_equal [:underline, :blue], s1.list
|
137
|
-
|
138
|
-
# Raise an error for an undefined style
|
139
|
-
assert_raises(::NameError) { HighLine.Style(:fubar) }
|
140
|
-
end
|
141
|
-
|
142
|
-
def test_no_color_scheme
|
143
|
-
HighLine.color_scheme = nil
|
144
|
-
assert_raises(::NameError) { HighLine.Style(:critical) }
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_with_color_scheme
|
148
|
-
HighLine.color_scheme = HighLine::SampleColorScheme.new
|
149
|
-
s = HighLine.Style(:critical)
|
150
|
-
assert_instance_of HighLine::Style, s
|
151
|
-
assert_equal :critical, s.name
|
152
|
-
assert_equal [:yellow, :on_red], s.list
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_builtin_foreground_colors_defined
|
156
|
-
HighLine::COLORS.each do |color|
|
157
|
-
style = HighLine.const_get(color+'_STYLE')
|
158
|
-
assert_instance_of HighLine::Style, style
|
159
|
-
assert_equal color.downcase.to_sym, style.name
|
160
|
-
assert style.builtin
|
161
|
-
code = HighLine.const_get(color)
|
162
|
-
assert_instance_of String, code, "Bad code for #{color}"
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
def test_builtin_background_colors_defined
|
167
|
-
HighLine::COLORS.each do |color|
|
168
|
-
style = HighLine.const_get('ON_' + color+'_STYLE')
|
169
|
-
assert_instance_of HighLine::Style, style
|
170
|
-
assert_equal "ON_#{color}".downcase.to_sym, style.name
|
171
|
-
assert style.builtin
|
172
|
-
code = HighLine.const_get('ON_' + color)
|
173
|
-
assert_instance_of String, code, "Bad code for ON_#{color}"
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
def test_builtin_styles_defined
|
178
|
-
HighLine::STYLES.each do |style_constant|
|
179
|
-
style = HighLine.const_get(style_constant+'_STYLE')
|
180
|
-
assert_instance_of HighLine::Style, style
|
181
|
-
assert_equal style_constant.downcase.to_sym, style.name
|
182
|
-
assert style.builtin
|
183
|
-
code = HighLine.const_get(style_constant)
|
184
|
-
assert_instance_of String, code, "Bad code for #{style_constant}"
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
def test_index
|
189
|
-
# Add a Style with a new name and code
|
190
|
-
assert_nil HighLine::Style.list[:s1]
|
191
|
-
assert_nil HighLine::Style.code_index['foo']
|
192
|
-
s1 = HighLine::Style.new(:name=>:s1, :code=>'foo')
|
193
|
-
refute_nil HighLine::Style.list[:s1]
|
194
|
-
assert_same s1, HighLine::Style.list[:s1]
|
195
|
-
assert_equal :s1, HighLine::Style.list[:s1].name
|
196
|
-
assert_equal 'foo', HighLine::Style.list[:s1].code
|
197
|
-
styles = HighLine::Style.list.size
|
198
|
-
codes = HighLine::Style.code_index.size
|
199
|
-
assert_instance_of Array, HighLine::Style.code_index['foo']
|
200
|
-
assert_equal 1, HighLine::Style.code_index['foo'].size
|
201
|
-
assert_same s1, HighLine::Style.code_index['foo'].last
|
202
|
-
assert_equal :s1, HighLine::Style.code_index['foo'].last.name
|
203
|
-
assert_equal 'foo', HighLine::Style.code_index['foo'].last.code
|
204
|
-
|
205
|
-
# Add another Style with a new name and code
|
206
|
-
assert_nil HighLine::Style.list[:s2]
|
207
|
-
assert_nil HighLine::Style.code_index['bar']
|
208
|
-
s2 = HighLine::Style.new(:name=>:s2, :code=>'bar')
|
209
|
-
assert_equal styles+1, HighLine::Style.list.size
|
210
|
-
assert_equal codes+1, HighLine::Style.code_index.size
|
211
|
-
refute_nil HighLine::Style.list[:s2]
|
212
|
-
assert_same s2, HighLine::Style.list[:s2]
|
213
|
-
assert_equal :s2, HighLine::Style.list[:s2].name
|
214
|
-
assert_equal 'bar', HighLine::Style.list[:s2].code
|
215
|
-
assert_instance_of Array, HighLine::Style.code_index['bar']
|
216
|
-
assert_equal 1, HighLine::Style.code_index['bar'].size
|
217
|
-
assert_same s2, HighLine::Style.code_index['bar'].last
|
218
|
-
assert_equal :s2, HighLine::Style.code_index['bar'].last.name
|
219
|
-
assert_equal 'bar', HighLine::Style.code_index['bar'].last.code
|
220
|
-
|
221
|
-
# Add a Style with an existing name
|
222
|
-
s3_before = HighLine::Style.list[:s2]
|
223
|
-
refute_nil HighLine::Style.list[:s2]
|
224
|
-
assert_nil HighLine::Style.code_index['baz']
|
225
|
-
s3 = HighLine::Style.new(:name=>:s2, :code=>'baz')
|
226
|
-
refute_same s2, s3
|
227
|
-
refute_same s3_before, s3
|
228
|
-
assert_equal styles+1, HighLine::Style.list.size
|
229
|
-
assert_equal codes+2, HighLine::Style.code_index.size
|
230
|
-
refute_nil HighLine::Style.list[:s2]
|
231
|
-
assert_same s3, HighLine::Style.list[:s2]
|
232
|
-
refute_same s2, HighLine::Style.list[:s2]
|
233
|
-
assert_equal :s2, HighLine::Style.list[:s2].name
|
234
|
-
assert_equal 'baz', HighLine::Style.list[:s2].code
|
235
|
-
assert_instance_of Array, HighLine::Style.code_index['baz']
|
236
|
-
assert_equal 1, HighLine::Style.code_index['baz'].size
|
237
|
-
assert_same s3, HighLine::Style.code_index['baz'].last
|
238
|
-
assert_equal :s2, HighLine::Style.code_index['baz'].last.name
|
239
|
-
assert_equal 'baz', HighLine::Style.code_index['baz'].last.code
|
240
|
-
|
241
|
-
# Add a Style with an existing code
|
242
|
-
assert_equal 1, HighLine::Style.code_index['baz'].size
|
243
|
-
s4 = HighLine::Style.new(:name=>:s4, :code=>'baz')
|
244
|
-
assert_equal styles+2, HighLine::Style.list.size
|
245
|
-
assert_equal codes+2, HighLine::Style.code_index.size
|
246
|
-
refute_nil HighLine::Style.list[:s4]
|
247
|
-
assert_same s4, HighLine::Style.list[:s4]
|
248
|
-
assert_equal :s4, HighLine::Style.list[:s4].name
|
249
|
-
assert_equal 'baz', HighLine::Style.list[:s4].code
|
250
|
-
assert_equal 2, HighLine::Style.code_index['baz'].size
|
251
|
-
assert_same s3, HighLine::Style.code_index['baz'].first # Unchanged from last time
|
252
|
-
assert_equal :s2, HighLine::Style.code_index['baz'].first.name # Unchanged from last time
|
253
|
-
assert_equal 'baz', HighLine::Style.code_index['baz'].first.code # Unchanged from last time
|
254
|
-
assert_same s4, HighLine::Style.code_index['baz'].last
|
255
|
-
assert_equal :s4, HighLine::Style.code_index['baz'].last.name
|
256
|
-
assert_equal 'baz', HighLine::Style.code_index['baz'].last.code
|
257
|
-
end
|
258
|
-
|
259
|
-
def test_rgb_hex
|
260
|
-
assert_equal "abcdef", HighLine::Style.rgb_hex("abcdef")
|
261
|
-
assert_equal "ABCDEF", HighLine::Style.rgb_hex("AB","CD","EF")
|
262
|
-
assert_equal "010203", HighLine::Style.rgb_hex(1,2,3)
|
263
|
-
assert_equal "123456", HighLine::Style.rgb_hex(18,52,86)
|
264
|
-
end
|
265
|
-
|
266
|
-
def test_rgb_parts
|
267
|
-
assert_equal [1,2,3], HighLine::Style.rgb_parts("010203")
|
268
|
-
assert_equal [18,52,86], HighLine::Style.rgb_parts("123456")
|
269
|
-
end
|
270
|
-
|
271
|
-
def test_rgb
|
272
|
-
s = HighLine::Style.rgb(1, 2, 3)
|
273
|
-
assert_instance_of HighLine::Style, s
|
274
|
-
assert_equal :rgb_010203, s.name
|
275
|
-
assert_equal [1,2,3], s.rgb
|
276
|
-
assert_equal "\e[38;5;16m", s.code
|
277
|
-
|
278
|
-
s = HighLine::Style.rgb("12", "34","56")
|
279
|
-
assert_instance_of HighLine::Style, s
|
280
|
-
assert_equal :rgb_123456, s.name
|
281
|
-
assert_equal [0x12, 0x34, 0x56], s.rgb
|
282
|
-
assert_equal "\e[38;5;24m", s.code
|
283
|
-
|
284
|
-
s = HighLine::Style.rgb("abcdef")
|
285
|
-
assert_instance_of HighLine::Style, s
|
286
|
-
assert_equal :rgb_abcdef, s.name
|
287
|
-
assert_equal [0xab, 0xcd, 0xef], s.rgb
|
288
|
-
assert_equal "\e[38;5;189m", s.code
|
289
|
-
end
|
290
|
-
|
291
|
-
def test_rgb_number
|
292
|
-
# ANSI RGB coding splits 0..255 into equal sixths, and then the
|
293
|
-
# red green and blue are encoded in base 6, plus 16, i.e.
|
294
|
-
# 16 + 36*(red_level) + 6*(green_level) + blue_level,
|
295
|
-
# where each of red_level, green_level, and blue_level are in
|
296
|
-
# the range 0..5
|
297
|
-
|
298
|
-
# This test logic works because 42 is just below 1/6 of 255,
|
299
|
-
# and 43 is just above
|
300
|
-
|
301
|
-
assert_equal 16 + 0*36 + 0*6 + 0, HighLine::Style.rgb_number( 0, 0, 0)
|
302
|
-
assert_equal 16 + 0*36 + 0*6 + 0, HighLine::Style.rgb_number( 0, 0, 42)
|
303
|
-
assert_equal 16 + 0*36 + 0*6 + 1, HighLine::Style.rgb_number( 0, 0, 43)
|
304
|
-
|
305
|
-
assert_equal 16 + 0*36 + 0*6 + 0, HighLine::Style.rgb_number( 0, 42, 0)
|
306
|
-
assert_equal 16 + 0*36 + 0*6 + 0, HighLine::Style.rgb_number( 0, 42, 42)
|
307
|
-
assert_equal 16 + 0*36 + 0*6 + 1, HighLine::Style.rgb_number( 0, 42, 43)
|
308
|
-
|
309
|
-
assert_equal 16 + 0*36 + 1*6 + 0, HighLine::Style.rgb_number( 0, 43, 0)
|
310
|
-
assert_equal 16 + 0*36 + 1*6 + 0, HighLine::Style.rgb_number( 0, 43, 42)
|
311
|
-
assert_equal 16 + 0*36 + 1*6 + 1, HighLine::Style.rgb_number( 0, 43, 43)
|
312
|
-
|
313
|
-
assert_equal 16 + 0*36 + 0*6 + 0, HighLine::Style.rgb_number( 42, 0, 0)
|
314
|
-
assert_equal 16 + 0*36 + 0*6 + 0, HighLine::Style.rgb_number( 42, 0, 42)
|
315
|
-
assert_equal 16 + 0*36 + 0*6 + 1, HighLine::Style.rgb_number( 42, 0, 43)
|
316
|
-
|
317
|
-
assert_equal 16 + 0*36 + 0*6 + 0, HighLine::Style.rgb_number( 42, 42, 0)
|
318
|
-
assert_equal 16 + 0*36 + 0*6 + 0, HighLine::Style.rgb_number( 42, 42, 42)
|
319
|
-
assert_equal 16 + 0*36 + 0*6 + 1, HighLine::Style.rgb_number( 42, 42, 43)
|
320
|
-
|
321
|
-
assert_equal 16 + 0*36 + 1*6 + 0, HighLine::Style.rgb_number( 42, 43, 0)
|
322
|
-
assert_equal 16 + 0*36 + 1*6 + 0, HighLine::Style.rgb_number( 42, 43, 42)
|
323
|
-
assert_equal 16 + 0*36 + 1*6 + 1, HighLine::Style.rgb_number( 42, 43, 43)
|
324
|
-
|
325
|
-
assert_equal 16 + 1*36 + 0*6 + 0, HighLine::Style.rgb_number( 43, 0, 0)
|
326
|
-
assert_equal 16 + 1*36 + 0*6 + 0, HighLine::Style.rgb_number( 43, 0, 42)
|
327
|
-
assert_equal 16 + 1*36 + 0*6 + 1, HighLine::Style.rgb_number( 43, 0, 43)
|
328
|
-
|
329
|
-
assert_equal 16 + 1*36 + 0*6 + 0, HighLine::Style.rgb_number( 43, 42, 0)
|
330
|
-
assert_equal 16 + 1*36 + 0*6 + 0, HighLine::Style.rgb_number( 43, 42, 42)
|
331
|
-
assert_equal 16 + 1*36 + 0*6 + 1, HighLine::Style.rgb_number( 43, 42, 43)
|
332
|
-
|
333
|
-
assert_equal 16 + 1*36 + 1*6 + 0, HighLine::Style.rgb_number( 43, 43, 0)
|
334
|
-
assert_equal 16 + 1*36 + 1*6 + 0, HighLine::Style.rgb_number( 43, 43, 42)
|
335
|
-
assert_equal 16 + 1*36 + 1*6 + 1, HighLine::Style.rgb_number( 43, 43, 43)
|
336
|
-
|
337
|
-
assert_equal 16 + 5*36 + 5*6 + 5, HighLine::Style.rgb_number(255,255,255)
|
338
|
-
end
|
339
|
-
|
340
|
-
def test_ansi_rgb_to_hex
|
341
|
-
assert_equal "000000", HighLine::Style.ansi_rgb_to_hex(16 + 0*36 + 0*6 + 0)
|
342
|
-
assert_equal "000000", HighLine::Style.ansi_rgb_to_hex(16 + 0*36 + 0*6 + 0)
|
343
|
-
assert_equal "00002b", HighLine::Style.ansi_rgb_to_hex(16 + 0*36 + 0*6 + 1)
|
344
|
-
|
345
|
-
assert_equal "000000", HighLine::Style.ansi_rgb_to_hex(16 + 0*36 + 0*6 + 0)
|
346
|
-
assert_equal "000000", HighLine::Style.ansi_rgb_to_hex(16 + 0*36 + 0*6 + 0)
|
347
|
-
assert_equal "00002b", HighLine::Style.ansi_rgb_to_hex(16 + 0*36 + 0*6 + 1)
|
348
|
-
|
349
|
-
assert_equal "002b00", HighLine::Style.ansi_rgb_to_hex(16 + 0*36 + 1*6 + 0)
|
350
|
-
assert_equal "002b00", HighLine::Style.ansi_rgb_to_hex(16 + 0*36 + 1*6 + 0)
|
351
|
-
assert_equal "002b2b", HighLine::Style.ansi_rgb_to_hex(16 + 0*36 + 1*6 + 1)
|
352
|
-
|
353
|
-
assert_equal "000000", HighLine::Style.ansi_rgb_to_hex(16 + 0*36 + 0*6 + 0)
|
354
|
-
assert_equal "000000", HighLine::Style.ansi_rgb_to_hex(16 + 0*36 + 0*6 + 0)
|
355
|
-
assert_equal "00002b", HighLine::Style.ansi_rgb_to_hex(16 + 0*36 + 0*6 + 1)
|
356
|
-
|
357
|
-
assert_equal "000000", HighLine::Style.ansi_rgb_to_hex(16 + 0*36 + 0*6 + 0)
|
358
|
-
assert_equal "000000", HighLine::Style.ansi_rgb_to_hex(16 + 0*36 + 0*6 + 0)
|
359
|
-
assert_equal "00002b", HighLine::Style.ansi_rgb_to_hex(16 + 0*36 + 0*6 + 1)
|
360
|
-
|
361
|
-
assert_equal "002b00", HighLine::Style.ansi_rgb_to_hex(16 + 0*36 + 1*6 + 0)
|
362
|
-
assert_equal "002b00", HighLine::Style.ansi_rgb_to_hex(16 + 0*36 + 1*6 + 0)
|
363
|
-
assert_equal "002b2b", HighLine::Style.ansi_rgb_to_hex(16 + 0*36 + 1*6 + 1)
|
364
|
-
|
365
|
-
assert_equal "2b0000", HighLine::Style.ansi_rgb_to_hex(16 + 1*36 + 0*6 + 0)
|
366
|
-
assert_equal "2b0000", HighLine::Style.ansi_rgb_to_hex(16 + 1*36 + 0*6 + 0)
|
367
|
-
assert_equal "2b002b", HighLine::Style.ansi_rgb_to_hex(16 + 1*36 + 0*6 + 1)
|
368
|
-
|
369
|
-
assert_equal "2b0000", HighLine::Style.ansi_rgb_to_hex(16 + 1*36 + 0*6 + 0)
|
370
|
-
assert_equal "2b0000", HighLine::Style.ansi_rgb_to_hex(16 + 1*36 + 0*6 + 0)
|
371
|
-
assert_equal "2b002b", HighLine::Style.ansi_rgb_to_hex(16 + 1*36 + 0*6 + 1)
|
372
|
-
|
373
|
-
assert_equal "2b2b00", HighLine::Style.ansi_rgb_to_hex(16 + 1*36 + 1*6 + 0)
|
374
|
-
assert_equal "2b2b00", HighLine::Style.ansi_rgb_to_hex(16 + 1*36 + 1*6 + 0)
|
375
|
-
assert_equal "2b2b2b", HighLine::Style.ansi_rgb_to_hex(16 + 1*36 + 1*6 + 1)
|
376
|
-
|
377
|
-
# 0xd5 is the smallest number where n/255.0*6.0 > 5
|
378
|
-
assert_equal "d5d5d5", HighLine::Style.ansi_rgb_to_hex(16 + 5*36 + 5*6 + 5)
|
379
|
-
end
|
380
|
-
|
381
|
-
def test_list
|
382
|
-
list_size = HighLine::Style.list.size
|
383
|
-
# Add a Style with a new name and code
|
384
|
-
assert_nil HighLine::Style.list[:s5]
|
385
|
-
s5 = HighLine::Style.new(:name=>:s5, :code=>'foo')
|
386
|
-
refute_nil HighLine::Style.list[:s5]
|
387
|
-
assert_equal list_size+1, HighLine::Style.list.size
|
388
|
-
refute_nil HighLine::Style.list[:s5]
|
389
|
-
assert_same s5, HighLine::Style.list[:s5]
|
390
|
-
assert_equal :s5, HighLine::Style.list[:s5].name
|
391
|
-
assert_equal 'foo', HighLine::Style.list[:s5].code
|
392
|
-
|
393
|
-
# Add another Style with a new name and code
|
394
|
-
assert_nil HighLine::Style.list[:s6]
|
395
|
-
s6 = HighLine::Style.new(:name=>:s6, :code=>'bar')
|
396
|
-
assert_equal list_size+2, HighLine::Style.list.size
|
397
|
-
refute_nil HighLine::Style.list[:s6]
|
398
|
-
assert_same s6, HighLine::Style.list[:s6]
|
399
|
-
assert_equal :s6, HighLine::Style.list[:s6].name
|
400
|
-
assert_equal 'bar', HighLine::Style.list[:s6].code
|
401
|
-
|
402
|
-
# Add a Style with an existing name
|
403
|
-
s7 = HighLine::Style.new(:name=>:s6, :code=>'baz')
|
404
|
-
assert_equal list_size+2, HighLine::Style.list.size # No net addition to list
|
405
|
-
refute_nil HighLine::Style.list[:s6]
|
406
|
-
assert_same s7, HighLine::Style.list[:s6] # New one replaces old one
|
407
|
-
refute_same s6, HighLine::Style.list[:s6]
|
408
|
-
assert_equal :s6, HighLine::Style.list[:s6].name
|
409
|
-
assert_equal 'baz', HighLine::Style.list[:s6].code
|
410
|
-
end
|
411
|
-
|
412
|
-
def test_code_index
|
413
|
-
list_size = HighLine::Style.code_index.size
|
414
|
-
|
415
|
-
# Add a Style with a new name and code
|
416
|
-
assert_nil HighLine::Style.code_index['chewie']
|
417
|
-
HighLine::Style.new(:name=>:s8, :code=>'chewie')
|
418
|
-
assert_equal list_size+1, HighLine::Style.code_index.size
|
419
|
-
assert_instance_of Array, HighLine::Style.code_index['chewie']
|
420
|
-
assert_equal 1, HighLine::Style.code_index['chewie'].size
|
421
|
-
assert_equal :s8, HighLine::Style.code_index['chewie'].last.name
|
422
|
-
assert_equal 'chewie', HighLine::Style.code_index['chewie'].last.code
|
423
|
-
|
424
|
-
# Add another Style with a new name and code
|
425
|
-
assert_nil HighLine::Style.code_index['c3po']
|
426
|
-
HighLine::Style.new(:name=>:s9, :code=>'c3po')
|
427
|
-
assert_equal list_size+2, HighLine::Style.code_index.size
|
428
|
-
assert_instance_of Array, HighLine::Style.code_index['c3po']
|
429
|
-
assert_equal 1, HighLine::Style.code_index['c3po'].size
|
430
|
-
assert_equal :s9, HighLine::Style.code_index['c3po'].last.name
|
431
|
-
assert_equal 'c3po', HighLine::Style.code_index['c3po'].last.code
|
432
|
-
|
433
|
-
# Add a Style with an existing code
|
434
|
-
assert_equal 1, HighLine::Style.code_index['c3po'].size
|
435
|
-
HighLine::Style.new(:name=>:s10, :code=>'c3po')
|
436
|
-
assert_equal list_size+2, HighLine::Style.code_index.size
|
437
|
-
assert_equal 2, HighLine::Style.code_index['c3po'].size
|
438
|
-
assert_equal :s10, HighLine::Style.code_index['c3po'].last.name
|
439
|
-
assert_equal 'c3po', HighLine::Style.code_index['c3po'].last.code
|
440
|
-
end
|
441
|
-
|
442
|
-
def test_uncolor
|
443
|
-
# Normal color
|
444
|
-
assert_equal "This should be reverse underlined magenta!\n",
|
445
|
-
HighLine::Style.uncolor("This should be \e[7m\e[4m\e[35mreverse underlined magenta\e[0m!\n" )
|
446
|
-
|
447
|
-
# RGB color
|
448
|
-
assert_equal "This should be rgb_906030!\n",
|
449
|
-
HighLine::Style.uncolor("This should be \e[38;5;137mrgb_906030\e[0m!\n" )
|
450
|
-
end
|
451
|
-
|
452
|
-
def test_color
|
453
|
-
assert_equal "\e[99mstring\e[0m", @style1.color("string") # simple style
|
454
|
-
assert_equal "\e[99m\e[98mstring\e[0m", @style3.color("string") # Style list
|
455
|
-
end
|
456
|
-
|
457
|
-
def test_code
|
458
|
-
assert_equal "\e[99m", @style1.code # simple style
|
459
|
-
assert_equal "\e[99m\e[98m", @style3.code # Style list
|
460
|
-
end
|
461
|
-
|
462
|
-
def test_red
|
463
|
-
assert_equal 0x65, @style4.red
|
464
|
-
assert_equal 0, HighLine::Style(:none).red # Probably reliable
|
465
|
-
assert_equal 0, HighLine::Style(:black).red # Probably reliable
|
466
|
-
assert_equal 255, HighLine::Style(:bright_magenta).red # Seems to be reliable
|
467
|
-
assert_equal 255, HighLine::Style(:on_none).red # Probably reliable
|
468
|
-
end
|
469
|
-
|
470
|
-
def test_green
|
471
|
-
assert_equal 0x43, @style4.green
|
472
|
-
assert_equal 0, HighLine::Style(:none).green # Probably reliable
|
473
|
-
assert_equal 0, HighLine::Style(:black).green # Probably reliable
|
474
|
-
assert 240 <= HighLine::Style(:bright_cyan).green # Probably reliable
|
475
|
-
assert_equal 255, HighLine::Style(:on_none).green # Probably reliable
|
476
|
-
end
|
477
|
-
|
478
|
-
def test_blue
|
479
|
-
assert_equal 0x21, @style4.blue
|
480
|
-
assert_equal 0, HighLine::Style(:none).blue # Probably reliable
|
481
|
-
assert_equal 0, HighLine::Style(:black).blue # Probably reliable
|
482
|
-
assert_equal 255, HighLine::Style(:bright_blue).blue # Probably reliable
|
483
|
-
assert_equal 255, HighLine::Style(:on_none).blue # Probably reliable
|
484
|
-
end
|
485
|
-
|
486
|
-
def test_builtin
|
487
|
-
assert HighLine::Style(:red).builtin
|
488
|
-
assert !@style1.builtin
|
489
|
-
end
|
490
|
-
|
491
|
-
def test_variant
|
492
|
-
style1_name = @style1.name
|
493
|
-
style1_code = @style1.code
|
494
|
-
style1_rgb = @style1.rgb
|
495
|
-
|
496
|
-
s1 = @style1.variant(:new_foo1, :code=>'abracadabra')
|
497
|
-
assert_instance_of HighLine::Style, s1
|
498
|
-
refute_same @style1, s1 # This is a copy
|
499
|
-
assert_equal :new_foo1, s1.name # Changed
|
500
|
-
assert_equal 'abracadabra', s1.code # Changed
|
501
|
-
assert_equal [1,2,3], s1.rgb # Unchanged
|
502
|
-
|
503
|
-
s2 = @style1.variant(:new_foo2, :increment=>-15)
|
504
|
-
assert_instance_of HighLine::Style, s2
|
505
|
-
refute_same @style1, s2 # This is a copy
|
506
|
-
assert_equal :new_foo2, s2.name # Changed
|
507
|
-
assert_equal "\e[84m", s2.code # 99 (original code) - 15
|
508
|
-
assert_equal [1,2,3], s2.rgb # Unchanged
|
509
|
-
|
510
|
-
s3 = @style1.variant(:new_foo3, :code=>"\e[55m", :increment=>15)
|
511
|
-
assert_instance_of HighLine::Style, s3
|
512
|
-
refute_same @style1, s3 # This is a copy
|
513
|
-
assert_equal :new_foo3, s3.name # Changed
|
514
|
-
assert_equal "\e[70m", s3.code # 99 (new code) + 15
|
515
|
-
assert_equal [1,2,3], s3.rgb # Unchanged
|
516
|
-
|
517
|
-
s4 = @style1.variant(:new_foo4, :code=>"\e[55m", :increment=>15, :rgb=>"blah")
|
518
|
-
assert_instance_of HighLine::Style, s4
|
519
|
-
refute_same @style1, s4 # This is a copy
|
520
|
-
assert_equal :new_foo4, s4.name # Changed
|
521
|
-
assert_equal "\e[70m", s4.code # 99 (new code) + 15
|
522
|
-
assert_equal 'blah', s4.rgb # Changed
|
523
|
-
|
524
|
-
s5 = @style1.variant(:new_foo5)
|
525
|
-
assert_instance_of HighLine::Style, s5
|
526
|
-
refute_same @style1, s5 # This is a copy
|
527
|
-
assert_equal :new_foo5, s5.name # Changed
|
528
|
-
assert_equal "\e[99m", s5.code # Unchanged
|
529
|
-
assert_equal [1,2,3], s5.rgb # Unchanged
|
530
|
-
|
531
|
-
# No @style1's have been harmed in the running of this test
|
532
|
-
assert_equal style1_name, @style1.name
|
533
|
-
assert_equal style1_code, @style1.code
|
534
|
-
assert_equal style1_rgb, @style1.rgb
|
535
|
-
|
536
|
-
assert_raises(::RuntimeError) { @style3.variant(:new_foo6) } # Can't create a variant of a list style
|
537
|
-
end
|
538
|
-
|
539
|
-
def test_on
|
540
|
-
style1_name = @style1.name
|
541
|
-
style1_code = @style1.code
|
542
|
-
style1_rgb = @style1.rgb
|
543
|
-
|
544
|
-
s1 = @style1.on
|
545
|
-
assert_instance_of HighLine::Style, s1
|
546
|
-
refute_same @style1, s1 # This is a copy
|
547
|
-
assert_equal :on_foo, s1.name # Changed
|
548
|
-
assert_equal "\e[109m", s1.code # Changed
|
549
|
-
assert_equal [1,2,3], s1.rgb # Unchanged
|
550
|
-
|
551
|
-
# No @style1's have been harmed in the running of this test
|
552
|
-
assert_equal style1_name, @style1.name
|
553
|
-
assert_equal style1_code, @style1.code
|
554
|
-
assert_equal style1_rgb, @style1.rgb
|
555
|
-
|
556
|
-
assert_raises(::RuntimeError) { @style3.on } # Can't create a variant of a list style
|
557
|
-
end
|
558
|
-
|
559
|
-
def test_bright
|
560
|
-
style1_name = @style1.name
|
561
|
-
style1_code = @style1.code
|
562
|
-
style1_rgb = @style1.rgb
|
563
|
-
|
564
|
-
s1 = @style1.bright
|
565
|
-
assert_instance_of HighLine::Style, s1
|
566
|
-
refute_same @style1, s1 # This is a copy
|
567
|
-
assert_equal :bright_foo, s1.name # Changed
|
568
|
-
assert_equal "\e[159m", s1.code # Changed
|
569
|
-
assert_equal [129,130,131], s1.rgb # Changed
|
570
|
-
|
571
|
-
# No @style1's have been harmed in the running of this test
|
572
|
-
assert_equal style1_name, @style1.name
|
573
|
-
assert_equal style1_code, @style1.code
|
574
|
-
assert_equal style1_rgb, @style1.rgb
|
575
|
-
|
576
|
-
s2_base = HighLine::Style.new(:name=>:leia, :code=>"\e[92m", :rgb=>[0,0,14])
|
577
|
-
s2 = s2_base.bright
|
578
|
-
assert_instance_of HighLine::Style, s2
|
579
|
-
refute_same s2_base, s2 # This is a copy
|
580
|
-
assert_equal :bright_leia, s2.name # Changed
|
581
|
-
assert_equal "\e[152m", s2.code # Changed
|
582
|
-
assert_equal [0,0,142], s2.rgb # Changed
|
583
|
-
|
584
|
-
s3_base = HighLine::Style.new(:name=>:luke, :code=>"\e[93m", :rgb=>[20,21,0])
|
585
|
-
s3 = s3_base.bright
|
586
|
-
assert_instance_of HighLine::Style, s3
|
587
|
-
refute_same s3_base, s3 # This is a copy
|
588
|
-
assert_equal :bright_luke, s3.name # Changed
|
589
|
-
assert_equal "\e[153m", s3.code # Changed
|
590
|
-
assert_equal [148,149,0], s3.rgb # Changed
|
591
|
-
|
592
|
-
s4_base = HighLine::Style.new(:name=>:r2d2, :code=>"\e[94m", :rgb=>[0,0,0])
|
593
|
-
s4 = s4_base.bright
|
594
|
-
assert_instance_of HighLine::Style, s4
|
595
|
-
refute_same s4_base, s4 # This is a copy
|
596
|
-
assert_equal :bright_r2d2, s4.name # Changed
|
597
|
-
assert_equal "\e[154m", s4.code # Changed
|
598
|
-
assert_equal [128,128,128], s4.rgb # Changed; special case
|
599
|
-
|
600
|
-
assert_raises(::RuntimeError) { @style3.bright } # Can't create a variant of a list style
|
601
|
-
end
|
602
|
-
|
603
|
-
def test_light_do_the_same_as_bright
|
604
|
-
bright_style = @style1.bright
|
605
|
-
light_style = @style1.light
|
606
|
-
|
607
|
-
refute_equal bright_style, light_style
|
608
|
-
assert_equal :bright_foo, bright_style.name
|
609
|
-
assert_equal :light_foo, light_style.name
|
610
|
-
assert_equal bright_style.code, light_style.code
|
611
|
-
assert_equal bright_style.rgb, light_style.rgb
|
612
|
-
end
|
613
|
-
end
|