mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Use new color-proximity gem for better visual matching
This commit is contained in:
@@ -23,5 +23,5 @@ Gem::Specification.new do |s|
|
|||||||
s.add_development_dependency 'pry'
|
s.add_development_dependency 'pry'
|
||||||
s.add_development_dependency 'rake'
|
s.add_development_dependency 'rake'
|
||||||
s.add_development_dependency 'yajl-ruby'
|
s.add_development_dependency 'yajl-ruby'
|
||||||
s.add_development_dependency 'color-proximity'
|
s.add_development_dependency 'color-proximity', '~> 0.2.1'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,12 +3,18 @@ require_relative "./helper"
|
|||||||
class TestColorThreshold < Minitest::Test
|
class TestColorThreshold < Minitest::Test
|
||||||
include Linguist
|
include Linguist
|
||||||
|
|
||||||
|
def cut_hash(color)
|
||||||
|
color[1..-1]
|
||||||
|
end
|
||||||
|
|
||||||
def test_color_threshold
|
def test_color_threshold
|
||||||
langs_with_colors = Language.all.reject { |language| language.color.nil? }
|
langs_with_colors = Language.all.reject { |language| language.color.nil? }
|
||||||
cp = ColorProximity.new(10, langs_with_colors.map(&:color))
|
cp = ColorProximity.new(0.02, langs_with_colors.map { |lang| cut_hash(lang.color) })
|
||||||
failing_threshold = langs_with_colors.map do |lang|
|
failing_threshold = langs_with_colors.map do |lang|
|
||||||
state = cp.within_threshold?(lang.color[1..-1])
|
state = cp.past_threshold?(cut_hash(lang.color))
|
||||||
"- #{lang} (#{lang.color}) is close to #{state.last}" unless state.first
|
if !state.first && lang.color != "##{state.last.first}"
|
||||||
|
"- #{lang} (#{lang.color}) is too close to #{state.last}"
|
||||||
|
end
|
||||||
end.compact
|
end.compact
|
||||||
message = "The following languages have failing color thresholds. Please modify the hex color.\n#{failing_threshold.join("\n")}"
|
message = "The following languages have failing color thresholds. Please modify the hex color.\n#{failing_threshold.join("\n")}"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user