mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Merge pull request #2298 from github/add-proximity-test
Add proximity test for colors
This commit is contained in:
@@ -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__)
|
||||
|
||||
23
test/test_color_proximity.rb
Normal file
23
test/test_color_proximity.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
require_relative "./helper"
|
||||
|
||||
class TestColorProximity < Minitest::Test
|
||||
include Linguist
|
||||
|
||||
def cut_hash(color)
|
||||
color[1..-1] if color.start_with?('#')
|
||||
end
|
||||
|
||||
def test_color_proximity
|
||||
langs_with_colors = Language.all.reject { |language| language.color.nil? }
|
||||
cp = ColorProximity.new(0.05, langs_with_colors.map { |lang| cut_hash(lang.color) })
|
||||
failing_threshold = langs_with_colors.map do |lang|
|
||||
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 #{failing_threshold.length} languages have failing color thresholds. Please modify the hex color.\n#{failing_threshold.join("\n")}"
|
||||
|
||||
assert failing_threshold.empty?, message
|
||||
end
|
||||
end
|
||||
@@ -286,9 +286,9 @@ class TestLanguage < Minitest::Test
|
||||
|
||||
def test_color
|
||||
assert_equal '#701516', Language['Ruby'].color
|
||||
assert_equal '#3581ba', Language['Python'].color
|
||||
assert_equal '#3572A5', Language['Python'].color
|
||||
assert_equal '#f1e05a', Language['JavaScript'].color
|
||||
assert_equal '#31859c', Language['TypeScript'].color
|
||||
assert_equal '#2b7489', Language['TypeScript'].color
|
||||
assert_equal '#3d9970', Language['LSL'].color
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user