Skip to content

Commit

Permalink
Face::FaceConfig -> Face::Config
Browse files Browse the repository at this point in the history
  • Loading branch information
hasumikin committed Oct 14, 2023
1 parent 389ff41 commit c3f92f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/reline/face.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Reline::Face
}
}.freeze

class FaceConfig
class Config
def initialize(name, &block)
@name = name
block.call(self)
Expand Down Expand Up @@ -111,15 +111,15 @@ def rgb_expression?(color)

CONFIGS = {}

private_constant :SGR_PARAMETERS, :FaceConfig, :CONFIGS
private_constant :SGR_PARAMETERS, :Config, :CONFIGS

def self.[](name)
CONFIGS[name]
end

def self.config(name, override = true, &block)
return if CONFIGS[name] && !override
CONFIGS[name] = FaceConfig.new(name, &block)
CONFIGS[name] = Config.new(name, &block)
end

end
Expand Down
20 changes: 10 additions & 10 deletions test/reline/test_face.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,43 +83,43 @@ def test_invalid_background_name
end

def test_private_constants
[:SGR_PARAMETER, :FaceConfig, :CONFIGS].each do |name|
[:SGR_PARAMETER, :Config, :CONFIGS].each do |name|
assert_equal false, Reline::Face.constants.include?(name)
end
end
end

class FaceConfigTest < self
class ConfigTest < self
def setup
@face_config = Reline::Face.const_get(:FaceConfig).new(:my_config) { }
@config = Reline::Face.const_get(:Config).new(:my_config) { }
end

def test_rgb?
assert_equal true, @face_config.send(:rgb_expression?, "#FFFFFF")
assert_equal true, @config.send(:rgb_expression?, "#FFFFFF")
end

def test_invalid_rgb?
assert_equal false, @face_config.send(:rgb_expression?, "FFFFFF")
assert_equal false, @face_config.send(:rgb_expression?, "#FFFFF")
assert_equal false, @config.send(:rgb_expression?, "FFFFFF")
assert_equal false, @config.send(:rgb_expression?, "#FFFFF")
end

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

def test_format_to_sgr_with_single_style
assert_equal(
"\e[37;41;1m",
@face_config.send(:format_to_sgr, foreground: :white, background: :red, style: :bold)
@config.send(:format_to_sgr, foreground: :white, background: :red, style: :bold)
)
end

def test_sgr_rgb
assert_equal "38;2;255;255;255", @face_config.send(:sgr_rgb, :foreground, "#ffffff")
assert_equal "48;2;18;52;86", @face_config.send(:sgr_rgb, :background, "#123456")
assert_equal "38;2;255;255;255", @config.send(:sgr_rgb, :foreground, "#ffffff")
assert_equal "48;2;18;52;86", @config.send(:sgr_rgb, :background, "#123456")
end
end
end

0 comments on commit c3f92f1

Please sign in to comment.