Merge pull request #264 from benbalter/rdoc-readme-support

Add support for detecting licenses in Rdoc-formatted READMEs
This commit is contained in:
Ben Balter 2018-01-23 09:52:20 -05:00 committed by GitHub
commit fd560c01ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 11 deletions

View File

@ -1,21 +1,30 @@
module Licensee
module ProjectFiles
class ReadmeFile < Licensee::ProjectFiles::LicenseFile
EXTENSIONS = %w[md markdown mdown txt rdoc].freeze
SCORES = {
/\AREADME\z/i => 1.0,
/\AREADME\.(md|markdown|mdown|txt)\z/i => 0.9
/\AREADME\z/i => 1.0,
/\AREADME\.(#{Regexp.union(EXTENSIONS).source})\z/i => 0.9
}.freeze
TITLE_REGEX = /licen[sc]e:?/i
UNDERLINE_REGEX = /\n[-=]+/m
CONTENT_REGEX = /^
(?:\#+\sLicen[sc]e # Start of hashes-based license header
|
Licen[sc]e\n[-=]+)$ # Start of underlined license header
(.*?) # License content
(?=^(?:\#+ # Next hashes-based header
|
[^\n]+\n[-=]+) # Next of underlined header
|
\z) # End of file
(?: # Header lookbehind
[\#=]+\s#{TITLE_REGEX} # Start of hashes or rdoc header
|
#{TITLE_REGEX}#{UNDERLINE_REGEX} # Start of underlined header
)$
(.*?) # License content
(?=^ # Header or end of file lookahead
(?:
[\#=]+ # Next hash or rdoc header
|
[^\n]+#{UNDERLINE_REGEX} # Next of underlined header
)
|
\z # End of file
)
/mix
def possible_matchers

View File

@ -11,6 +11,7 @@ RSpec.describe Licensee::ProjectFiles::ReadmeFile do
'README.md' => 0.9,
'readme.txt' => 0.9,
'readme.mdown' => 0.9,
'readme.rdoc' => 0.9,
'LICENSE' => 0.0
}.each do |filename, expected_score|
context "with a file named #{filename}" do
@ -97,6 +98,22 @@ RSpec.describe Licensee::ProjectFiles::ReadmeFile do
expect(license).to eql('hello world')
end
end
context 'With a trailing colon' do
let(:content) { "## License:\n\nhello world" }
it 'returns the license' do
expect(license).to eql('hello world')
end
end
context 'Rdoc' do
let(:content) { "== License:\n\nhello world" }
it 'returns the license' do
expect(license).to eql('hello world')
end
end
end
context 'a license reference' do