mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 09:40:21 +00:00
Add test for detecting color proximity
This commit is contained in:
@@ -23,4 +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'
|
||||
end
|
||||
|
||||
@@ -2,6 +2,7 @@ require "bundler/setup"
|
||||
require "minitest/autorun"
|
||||
require "mocha/setup"
|
||||
require "linguist"
|
||||
require 'color-proximity'
|
||||
|
||||
def fixtures_path
|
||||
File.expand_path("../fixtures", __FILE__)
|
||||
|
||||
20
test/test_color_threshold.rb
Normal file
20
test/test_color_threshold.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
require_relative "./helper"
|
||||
|
||||
class TestColorThreshold < Minitest::Test
|
||||
include Linguist
|
||||
|
||||
def test_color_threshold
|
||||
langs_with_colors = Language.all.reject { |language| language.color.nil? }
|
||||
cp = ColorProximity.new(20, langs_with_colors.map(&:color))
|
||||
failing_threshold = []
|
||||
langs_with_colors.each do |lang|
|
||||
state = cp.within_threshold?(lang.color[1..-1])
|
||||
unless state.first
|
||||
failing_threshold << [lang, state.last]
|
||||
end
|
||||
end
|
||||
message = "The following languages have failing color thresholds. Please modify the hex color.\n#{failing_threshold}"
|
||||
|
||||
assert failing_threshold.empty?, message
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user