add rdoc support

This commit is contained in:
Ben Balter 2018-01-22 12:35:08 -05:00
parent a7ffc53237
commit 9bef23a7f6
No known key found for this signature in database
GPG Key ID: DBB67C246AD356C4
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