Skip to content

Commit

Permalink
Test Reline::Face without mocking
Browse files Browse the repository at this point in the history
Because `test-unit-rr` is not a default gem, using it would break CRuby's
CI.
  • Loading branch information
st0012 committed Nov 6, 2023
1 parent fdc1d3b commit 4f8759e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ end
gem 'bundler'
gem 'rake'
gem 'test-unit'
gem 'test-unit-rr'

gem 'racc'

gem "irb"
1 change: 0 additions & 1 deletion test/reline/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

require 'reline'
require 'test/unit'
require 'test/unit/rr'

begin
require 'rbconfig'
Expand Down
18 changes: 6 additions & 12 deletions test/reline/test_face.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,6 @@ def setup
@config = Reline::Face.const_get(:Config).new(:my_config) { }
end

def test_the_order_of_define_values_should_be_preserved
any_instance_of(Reline::Face.const_get(:Config)) do |config|
mock(config).format_to_sgr(
[[:foreground, :blue], [:style, [:bold, :italicized]], [:background, :red]]
)
end
Reline::Face.config(:my_config) do |face|
face.define :default, foreground: :blue, style: [:bold, :italicized], background: :red
end
end

def test_rgb?
assert_equal true, @config.send(:rgb_expression?, "#FFFFFF")
end
Expand All @@ -171,11 +160,16 @@ def test_invalid_rgb?
assert_equal false, @config.send(:rgb_expression?, "#FFFFF")
end

def test_format_to_sgr
def test_format_to_sgr_preserves_order
assert_equal(
"#{RESET_SGR}\e[37;41;1;3m",
@config.send(:format_to_sgr, foreground: :white, background: :red, style: [:bold, :italicized])
)

assert_equal(
"#{RESET_SGR}\e[37;1;3;41m",
@config.send(:format_to_sgr, foreground: :white, style: [:bold, :italicized], background: :red)
)
end

def test_format_to_sgr_with_reset
Expand Down

0 comments on commit 4f8759e

Please sign in to comment.