This commit is contained in:
Ben Balter 2015-09-01 18:58:02 -04:00
parent b94497a16b
commit 8e5abe96e5
4 changed files with 43 additions and 3 deletions

View File

@ -7,7 +7,7 @@ class Licensee
content = content.gsub(/[[:space:]]+\z/, '')
content = content.gsub(/^#{CopyrightMatcher::REGEX}$/i, '')
content = content.gsub(/[[:space:]]+/, ' ')
content.squeeze(' ')
content.squeeze(' ').strip
end
end
end

View File

@ -0,0 +1,36 @@
require 'helper'
class TestHelper
include Licensee::ContentHelper
end
class TestLicenseeContentHelper < Minitest::Test
def setup
@helper = TestHelper.new
end
def normalize(content)
@helper.normalize_content(content)
end
should "downcase content" do
assert_equal "foo", normalize("Foo")
end
should "strip leading whitespace" do
assert_equal "foo", normalize("\n Foo")
end
should "strip trailing whitespace" do
assert_equal "foo", normalize("Foo \n ")
end
should "strip double spaces" do
assert_equal "foo bar", normalize("Foo bar")
end
should "strip copyrights" do
assert_equal "foo", normalize("Copyright (c) 2015 Ben Balter\nFoo")
end
end

View File

@ -24,7 +24,7 @@ class TestLicenseeLevenshteinMatcher < Minitest::Test
should "calculate length delta" do
isc = Licensee::License.find("isc")
assert_equal 0.0, Licensee::LevenshteinMatcher.new(@mit).length_delta(Licensee::License.find("mit"))
assert_equal 346.0, Licensee::LevenshteinMatcher.new(@mit).length_delta(isc)
assert_equal 347.0, Licensee::LevenshteinMatcher.new(@mit).length_delta(isc)
end
should "round up potential licenses" do

View File

@ -21,11 +21,15 @@ class TestLicenseeProjectFile < Minitest::Test
should "know the path" do
assert_equal "LICENSE", @file.path
end
should "calculate confidence" do
assert_equal 100, @file.confidence
end
should "parse the attribution" do
assert_equal "Copyright (c) 2014 Ben Balter", @file.attribution
end
context "license filename scoring" do
EXPECTATIONS = {