diff --git a/lib/licensee/content_helper.rb b/lib/licensee/content_helper.rb index 7fa21c5..ab5043d 100644 --- a/lib/licensee/content_helper.rb +++ b/lib/licensee/content_helper.rb @@ -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 diff --git a/test/test_licensee_content_helper.rb b/test/test_licensee_content_helper.rb new file mode 100644 index 0000000..39d15aa --- /dev/null +++ b/test/test_licensee_content_helper.rb @@ -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 diff --git a/test/test_licensee_levenshtein_matcher.rb b/test/test_licensee_levenshtein_matcher.rb index 0f1664d..5f239e4 100644 --- a/test/test_licensee_levenshtein_matcher.rb +++ b/test/test_licensee_levenshtein_matcher.rb @@ -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 diff --git a/test/test_licensee_project_file.rb b/test/test_licensee_project_file.rb index ba59f07..3636a1d 100644 --- a/test/test_licensee_project_file.rb +++ b/test/test_licensee_project_file.rb @@ -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 = {