mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 09:40:21 +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 'rake'
|
||||
s.add_development_dependency 'yajl-ruby'
|
||||
s.add_development_dependency 'color-proximity'
|
||||
s.add_development_dependency 'color-proximity', '~> 0.2.1'
|
||||
end
|
||||
|
||||
@@ -3,12 +3,18 @@ require_relative "./helper"
|
||||
class TestColorThreshold < Minitest::Test
|
||||
include Linguist
|
||||
|
||||
def cut_hash(color)
|
||||
color[1..-1]
|
||||
end
|
||||
|
||||
def test_color_threshold
|
||||
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|
|
||||
state = cp.within_threshold?(lang.color[1..-1])
|
||||
"- #{lang} (#{lang.color}) is close to #{state.last}" unless state.first
|
||||
state = cp.past_threshold?(cut_hash(lang.color))
|
||||
if !state.first && lang.color != "##{state.last.first}"
|
||||
"- #{lang} (#{lang.color}) is too close to #{state.last}"
|
||||
end
|
||||
end.compact
|
||||
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