better regex

This commit is contained in:
Ben Balter 2015-03-07 16:20:19 -05:00
parent 46d70aa17d
commit 8e6a9543a7
2 changed files with 6 additions and 6 deletions

View File

@ -1,10 +1,10 @@
class Licensee
class CopyrightMatcher < Matcher
REGEX = /\A(Copyright )?(©|\(c\)) \d{4}(.*)\n?\z/i
REGEX = /\A(Copyright|Copyright ©|Copyright \(c\)) \d{4}.*?\n?\z/i
def match
no_license if file.content_normalized =~ REGEX
no_license if file.content.strip =~ REGEX
end
def confidence

View File

@ -16,15 +16,15 @@ class TestLicenseeCopyrightMatcher < Minitest::Test
assert_equal 100, Licensee::CopyrightMatcher.new(@file).confidence
end
should "match (C) copyright notices" do
text = "(C) 2015 Ben Balter"
should "match Copyright (C) copyright notices" do
text = "Copyright (C) 2015 Ben Balter"
blob = FakeBlob.new(text)
file = Licensee::LicenseFile.new(blob)
assert_equal "no-license", Licensee::CopyrightMatcher.match(file).key
end
should "match © copyright notices" do
text = "© 2015 Ben Balter"
should "match Copyright © copyright notices" do
text = "copyright © 2015 Ben Balter"
blob = FakeBlob.new(text)
file = Licensee::LicenseFile.new(blob)
assert_equal "no-license", Licensee::CopyrightMatcher.match(file).key