diff options
-rwxr-xr-x | lib/highline/style.rb | 5 | ||||
-rwxr-xr-x | test/tc_style.rb | 13 |
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/highline/style.rb b/lib/highline/style.rb index 3f83527..92f0b84 100755 --- a/lib/highline/style.rb +++ b/lib/highline/style.rb @@ -54,6 +54,11 @@ class HighLine style end + def self.clear_index + # reset to builtin only styles + @@styles = list.select { |name, style| style.builtin } + end + def self.rgb_hex(*colors) colors.map do |color| color.is_a?(Numeric) ? '%02x'%color : color.to_s diff --git a/test/tc_style.rb b/test/tc_style.rb index cb65878..94689a7 100755 --- a/test/tc_style.rb +++ b/test/tc_style.rb @@ -19,12 +19,23 @@ class TestStyle < Minitest::Test @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 end def teardown - # HighLine::Style.clear_index + HighLine::Style.clear_index end + 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_style_method # Retrieve a style from an existing Style (no new Style created) new_style = @style1.dup # This will replace @style1 in the indexes |