licensee 6.1.1 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +2 -2
- data/bin/licensee +7 -4
- data/lib/licensee.rb +25 -22
- data/lib/licensee/content_helper.rb +5 -4
- data/lib/licensee/license.rb +56 -45
- data/lib/licensee/matchers/copyright_matcher.rb +2 -2
- data/lib/licensee/matchers/dice_matcher.rb +7 -4
- data/lib/licensee/matchers/exact_matcher.rb +2 -2
- data/lib/licensee/matchers/gemspec_matcher.rb +5 -2
- data/lib/licensee/matchers/npm_bower_matcher.rb +5 -2
- data/lib/licensee/matchers/package_matcher.rb +2 -2
- data/lib/licensee/project.rb +21 -96
- data/lib/licensee/project_file.rb +6 -7
- data/lib/licensee/project_files/license_file.rb +3 -3
- data/lib/licensee/project_files/package_info.rb +7 -7
- data/lib/licensee/project_files/readme.rb +24 -0
- data/lib/licensee/projects/fs_project.rb +32 -0
- data/lib/licensee/projects/git_project.rb +55 -0
- data/lib/licensee/version.rb +2 -2
- data/test/fixtures/bower-with-readme/README.md +1 -0
- data/test/fixtures/bower-with-readme/bower.json +3 -0
- data/test/functions.rb +23 -12
- data/test/helper.rb +5 -0
- data/test/test_licensee.rb +9 -8
- data/test/test_licensee_bin.rb +11 -5
- data/test/test_licensee_copyright_matcher.rb +23 -23
- data/test/test_licensee_dice_matcher.rb +5 -5
- data/test/test_licensee_exact_matcher.rb +4 -4
- data/test/test_licensee_gemspec_matcher.rb +4 -4
- data/test/test_licensee_license.rb +82 -70
- data/test/test_licensee_license_file.rb +30 -28
- data/test/test_licensee_npm_bower_matcher.rb +11 -11
- data/test/test_licensee_package_info.rb +8 -7
- data/test/test_licensee_project.rb +45 -37
- data/test/test_licensee_project_file.rb +9 -9
- data/test/test_licensee_readme.rb +47 -0
- data/test/test_licensee_vendor.rb +10 -7
- data/vendor/choosealicense.com/_licenses/afl-3.0.txt +0 -3
- data/vendor/choosealicense.com/_licenses/agpl-3.0.txt +5 -5
- data/vendor/choosealicense.com/_licenses/apache-2.0.txt +1 -2
- data/vendor/choosealicense.com/_licenses/artistic-2.0.txt +14 -13
- data/vendor/choosealicense.com/_licenses/bsd-2-clause.txt +2 -3
- data/vendor/choosealicense.com/_licenses/bsd-3-clause-clear.txt +0 -6
- data/vendor/choosealicense.com/_licenses/bsd-3-clause.txt +2 -4
- data/vendor/choosealicense.com/_licenses/cc0-1.0.txt +2 -1
- data/vendor/choosealicense.com/_licenses/epl-1.0.txt +2 -1
- data/vendor/choosealicense.com/_licenses/eupl-1.1.txt +345 -0
- data/vendor/choosealicense.com/_licenses/gpl-2.0.txt +5 -5
- data/vendor/choosealicense.com/_licenses/gpl-3.0.txt +5 -4
- data/vendor/choosealicense.com/_licenses/isc.txt +1 -2
- data/vendor/choosealicense.com/_licenses/lgpl-2.1.txt +5 -6
- data/vendor/choosealicense.com/_licenses/lgpl-3.0.txt +8 -8
- data/vendor/choosealicense.com/_licenses/lppl-1.3c.txt +445 -0
- data/vendor/choosealicense.com/_licenses/mit.txt +1 -1
- data/vendor/choosealicense.com/_licenses/mpl-2.0.txt +2 -1
- data/vendor/choosealicense.com/_licenses/ms-pl.txt +0 -1
- data/vendor/choosealicense.com/_licenses/ms-rl.txt +1 -1
- data/vendor/choosealicense.com/_licenses/ofl-1.1.txt +1 -2
- data/vendor/choosealicense.com/_licenses/osl-3.0.txt +1 -3
- data/vendor/choosealicense.com/_licenses/unlicense.txt +1 -2
- data/vendor/choosealicense.com/_licenses/wtfpl.txt +0 -2
- metadata +33 -11
- data/vendor/choosealicense.com/_licenses/no-license.txt +0 -25
data/test/helper.rb
CHANGED
data/test/test_licensee.rb
CHANGED
@@ -1,27 +1,28 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestLicensee < Minitest::Test
|
4
|
-
should
|
4
|
+
should 'know the licenses' do
|
5
5
|
assert_equal Array, Licensee.licenses.class
|
6
6
|
assert_equal 15, Licensee.licenses.size
|
7
|
-
assert_equal
|
7
|
+
assert_equal 26, Licensee.licenses(hidden: true).size
|
8
8
|
assert_equal Licensee::License, Licensee.licenses.first.class
|
9
9
|
end
|
10
10
|
|
11
11
|
should "detect a project's license" do
|
12
|
-
assert_equal
|
12
|
+
assert_equal 'mit', Licensee.license(fixture_path('licenses.git')).key
|
13
13
|
end
|
14
14
|
|
15
|
-
should
|
16
|
-
|
15
|
+
should 'init a project' do
|
16
|
+
project = Licensee.project(fixture_path('licenses.git'))
|
17
|
+
assert_equal Licensee::GitProject, project.class
|
17
18
|
end
|
18
19
|
|
19
|
-
context
|
20
|
-
should
|
20
|
+
context 'confidence threshold' do
|
21
|
+
should 'return the confidence threshold' do
|
21
22
|
assert_equal 90, Licensee.confidence_threshold
|
22
23
|
end
|
23
24
|
|
24
|
-
should
|
25
|
+
should 'let the user override the confidence threshold' do
|
25
26
|
Licensee.confidence_threshold = 50
|
26
27
|
assert_equal 50, Licensee.confidence_threshold
|
27
28
|
Licensee.confidence_threshold = 90
|
data/test/test_licensee_bin.rb
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestLicenseeBin < Minitest::Test
|
4
|
-
should
|
5
|
-
root = File.expand_path
|
4
|
+
should 'work via commandline' do
|
5
|
+
root = File.expand_path '..', File.dirname(__FILE__)
|
6
6
|
Dir.chdir root
|
7
|
-
stdout,stderr,status = Open3.capture3("#{root}/bin/licensee")
|
8
|
-
|
9
|
-
|
7
|
+
stdout, stderr, status = Open3.capture3("#{root}/bin/licensee")
|
8
|
+
|
9
|
+
msg = "expected #{stdout} to include `License: MIT`"
|
10
|
+
assert stdout.include?('License: MIT'), msg
|
11
|
+
|
12
|
+
msg = "expected #{stdout} to include `Matched file: LICENSE.md`"
|
13
|
+
assert stdout.include?('License file: LICENSE.md'), msg
|
14
|
+
|
10
15
|
assert_equal 0, status
|
16
|
+
assert stderr.empty?
|
11
17
|
end
|
12
18
|
end
|
@@ -2,51 +2,51 @@
|
|
2
2
|
require 'helper'
|
3
3
|
|
4
4
|
class TestLicenseeCopyrightMatchers < Minitest::Test
|
5
|
-
should
|
6
|
-
text =
|
5
|
+
should 'match the license' do
|
6
|
+
text = 'Copyright 2015 Ben Balter'
|
7
7
|
file = Licensee::Project::LicenseFile.new(text)
|
8
|
-
assert_equal
|
8
|
+
assert_equal 'no-license', Licensee::Matchers::Copyright.new(file).match.key
|
9
9
|
end
|
10
10
|
|
11
|
-
should
|
12
|
-
text =
|
11
|
+
should 'know the match confidence' do
|
12
|
+
text = 'Copyright 2015 Ben Balter'
|
13
13
|
file = Licensee::Project::LicenseFile.new(text)
|
14
14
|
assert_equal 100, Licensee::Matchers::Copyright.new(file).confidence
|
15
15
|
end
|
16
16
|
|
17
|
-
should
|
18
|
-
text =
|
17
|
+
should 'match Copyright (C) copyright notices' do
|
18
|
+
text = 'Copyright (C) 2015 Ben Balter'
|
19
19
|
file = Licensee::Project::LicenseFile.new(text)
|
20
|
-
assert_equal
|
20
|
+
assert_equal 'no-license', Licensee::Matchers::Copyright.new(file).match.key
|
21
21
|
end
|
22
22
|
|
23
|
-
should
|
24
|
-
text =
|
23
|
+
should 'match Copyright © copyright notices' do
|
24
|
+
text = 'copyright © 2015 Ben Balter'
|
25
25
|
file = Licensee::Project::LicenseFile.new(text)
|
26
|
-
assert_equal
|
26
|
+
assert_equal 'no-license', Licensee::Matchers::Copyright.new(file).match.key
|
27
27
|
end
|
28
28
|
|
29
|
-
should
|
30
|
-
text = File.open(Licensee::License.find(
|
29
|
+
should 'not false positive' do
|
30
|
+
text = File.open(Licensee::License.find('mit').path).read.split('---').last
|
31
31
|
file = Licensee::Project::LicenseFile.new(text)
|
32
32
|
assert_equal nil, Licensee::Matchers::Copyright.new(file).match
|
33
33
|
end
|
34
34
|
|
35
|
-
should
|
36
|
-
text =
|
35
|
+
should 'handle UTF-8 encoded copyright notices' do
|
36
|
+
text = 'Copyright (c) 2010-2014 Simon Hürlimann'
|
37
37
|
file = Licensee::Project::LicenseFile.new(text)
|
38
|
-
assert_equal
|
38
|
+
assert_equal 'no-license', Licensee::Matchers::Copyright.new(file).match.key
|
39
39
|
end
|
40
40
|
|
41
|
-
should
|
42
|
-
text = "Copyright \xC2\xA92015 Ben Balter`".force_encoding(
|
41
|
+
should 'handle ASCII-8BIT encoded copyright notices' do
|
42
|
+
text = "Copyright \xC2\xA92015 Ben Balter`".force_encoding('ASCII-8BIT')
|
43
43
|
file = Licensee::Project::LicenseFile.new(text)
|
44
|
-
assert_equal
|
44
|
+
assert_equal 'no-license', Licensee::Matchers::Copyright.new(file).match.key
|
45
45
|
end
|
46
46
|
|
47
|
-
should
|
48
|
-
text =
|
47
|
+
should 'match comma, separated dates' do
|
48
|
+
text = 'Copyright (c) 2003, 2004 Ben Balter'
|
49
49
|
file = Licensee::Project::LicenseFile.new(text)
|
50
|
-
assert_equal
|
50
|
+
assert_equal 'no-license', Licensee::Matchers::Copyright.new(file).match.key
|
51
51
|
end
|
52
|
-
|
52
|
+
end
|
@@ -2,20 +2,20 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TestLicenseeDiceMatchers < Minitest::Test
|
4
4
|
def setup
|
5
|
-
text = license_from_path(Licensee::License.find(
|
5
|
+
text = license_from_path(Licensee::License.find('mit').path)
|
6
6
|
@mit = Licensee::Project::LicenseFile.new(text)
|
7
7
|
end
|
8
8
|
|
9
|
-
should
|
10
|
-
assert_equal
|
9
|
+
should 'match the license' do
|
10
|
+
assert_equal 'mit', Licensee::Matchers::Dice.new(@mit).match.key
|
11
11
|
end
|
12
12
|
|
13
|
-
should
|
13
|
+
should 'know the match confidence' do
|
14
14
|
matcher = Licensee::Matchers::Dice.new(@mit)
|
15
15
|
assert matcher.confidence > 95, "#{matcher.confidence} < 95"
|
16
16
|
end
|
17
17
|
|
18
|
-
should
|
18
|
+
should 'calculate max delta' do
|
19
19
|
assert_equal 83.7, Licensee::Matchers::Dice.new(@mit).max_delta
|
20
20
|
end
|
21
21
|
end
|
@@ -2,15 +2,15 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TestLicenseeExactMatchers < Minitest::Test
|
4
4
|
def setup
|
5
|
-
text = File.open(Licensee::License.find(
|
5
|
+
text = File.open(Licensee::License.find('mit').path).read.split('---').last
|
6
6
|
@mit = Licensee::Project::LicenseFile.new(text)
|
7
7
|
end
|
8
8
|
|
9
|
-
should
|
10
|
-
assert_equal
|
9
|
+
should 'match the license' do
|
10
|
+
assert_equal 'mit', Licensee::Matchers::Exact.new(@mit).match.key
|
11
11
|
end
|
12
12
|
|
13
|
-
should
|
13
|
+
should 'know the match confidence' do
|
14
14
|
assert_equal 100, Licensee::Matchers::Exact.new(@mit).confidence
|
15
15
|
end
|
16
16
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestLicenseeGemspecMatchers < Minitest::Test
|
4
|
-
should
|
5
|
-
root = File.expand_path
|
4
|
+
should 'detect its own license' do
|
5
|
+
root = File.expand_path '../', File.dirname(__FILE__)
|
6
6
|
project = Licensee::GitProject.new(root, detect_packages: true)
|
7
7
|
matcher = Licensee::Matchers::Gemspec.new(project.package_file)
|
8
|
-
assert_equal
|
9
|
-
assert_equal
|
8
|
+
assert_equal 'mit', matcher.send(:license_property)
|
9
|
+
assert_equal 'mit', matcher.match.key
|
10
10
|
end
|
11
11
|
end
|
@@ -1,119 +1,127 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestLicenseeLicense < Minitest::Test
|
4
|
-
|
5
4
|
def setup
|
6
|
-
@license = Licensee::License.new
|
5
|
+
@license = Licensee::License.new 'MIT'
|
7
6
|
end
|
8
7
|
|
9
|
-
should
|
8
|
+
should 'read the license body' do
|
10
9
|
assert @license.body
|
11
|
-
|
10
|
+
msg = "Expected the following to contain MIT:\n#{@license.body}"
|
11
|
+
assert @license.text =~ /MIT/, msg
|
12
12
|
end
|
13
13
|
|
14
|
-
should
|
15
|
-
license = Licensee::License.new
|
14
|
+
should 'read the license body if it contains `---`' do
|
15
|
+
license = Licensee::License.new 'MIT'
|
16
16
|
content = "---\nfoo: bar\n---\nSome license\n---------\nsome text\n"
|
17
17
|
license.instance_variable_set(:@raw_content, content)
|
18
18
|
assert_equal "Some license\n---------\nsome text\n", license.body
|
19
19
|
end
|
20
20
|
|
21
|
-
should
|
22
|
-
assert_equal
|
21
|
+
should 'read the license meta' do
|
22
|
+
assert_equal 'MIT License', @license.meta['title']
|
23
23
|
end
|
24
24
|
|
25
|
-
should
|
26
|
-
|
25
|
+
should 'know the license path' do
|
26
|
+
path = File.expand_path('./vendor/choosealicense.com/_licenses/mit.txt')
|
27
|
+
assert_equal path, @license.path
|
27
28
|
end
|
28
29
|
|
29
|
-
should
|
30
|
-
assert_equal
|
30
|
+
should 'know the license name' do
|
31
|
+
assert_equal 'MIT License', @license.name
|
31
32
|
end
|
32
33
|
|
33
|
-
should
|
34
|
-
expected =
|
35
|
-
assert_equal expected, Licensee::License.find(
|
34
|
+
should 'know the license nickname' do
|
35
|
+
expected = 'GNU AGPLv3'
|
36
|
+
assert_equal expected, Licensee::License.find('agpl-3.0').nickname
|
36
37
|
end
|
37
38
|
|
38
|
-
should
|
39
|
-
assert_equal
|
39
|
+
should 'know the license ID' do
|
40
|
+
assert_equal 'mit', @license.key
|
40
41
|
end
|
41
42
|
|
42
|
-
should
|
43
|
-
assert_equal
|
43
|
+
should 'know the other license' do
|
44
|
+
assert_equal 'other', Licensee::License.find_by_key('other').key
|
44
45
|
end
|
45
46
|
|
46
|
-
should
|
47
|
-
assert @license == Licensee::License.new(
|
48
|
-
refute @license == Licensee::License.new(
|
49
|
-
refute @license
|
47
|
+
should 'know license equality' do
|
48
|
+
assert @license == Licensee::License.new('MIT')
|
49
|
+
refute @license == Licensee::License.new('ISC')
|
50
|
+
refute @license.nil?
|
50
51
|
end
|
51
52
|
|
52
|
-
should
|
53
|
+
should 'know if the license is featured' do
|
53
54
|
assert @license.featured?
|
54
55
|
assert_equal TrueClass, @license.featured?.class
|
55
|
-
refute Licensee::License.new(
|
56
|
-
assert_equal FalseClass, Licensee::License.new(
|
56
|
+
refute Licensee::License.new('cc0-1.0').featured?
|
57
|
+
assert_equal FalseClass, Licensee::License.new('cc0-1.0').featured?.class
|
57
58
|
end
|
58
59
|
|
59
|
-
should
|
60
|
-
license = Licensee::License.new(
|
60
|
+
should 'inject default meta without overriding' do
|
61
|
+
license = Licensee::License.new('cc0-1.0')
|
61
62
|
|
62
|
-
assert license.meta.
|
63
|
-
assert_equal false, license.meta[
|
63
|
+
assert license.meta.key? 'featured'
|
64
|
+
assert_equal false, license.meta['featured']
|
64
65
|
|
65
|
-
assert license.meta.
|
66
|
-
assert_equal false, license.meta[
|
66
|
+
assert license.meta.key? 'hidden'
|
67
|
+
assert_equal false, license.meta['hidden']
|
67
68
|
|
68
|
-
assert license.meta.
|
69
|
-
assert_equal true, license.meta[
|
69
|
+
assert license.meta.key? 'variant'
|
70
|
+
assert_equal true, license.meta['variant']
|
70
71
|
end
|
71
72
|
|
72
|
-
should
|
73
|
+
should 'know when the license is hidden' do
|
73
74
|
refute @license.hidden?
|
74
|
-
assert Licensee::License.new(
|
75
|
-
assert Licensee::License.new(
|
75
|
+
assert Licensee::License.new('ofl-1.1').hidden?
|
76
|
+
assert Licensee::License.new('no-license').hidden?
|
76
77
|
end
|
77
78
|
|
78
|
-
should
|
79
|
+
should 'parse the license parts' do
|
79
80
|
assert_equal 3, @license.send(:parts).size
|
80
81
|
end
|
81
82
|
|
82
|
-
should
|
83
|
-
assert_equal
|
83
|
+
should 'build the license URL' do
|
84
|
+
assert_equal 'http://choosealicense.com/licenses/mit/', @license.url
|
84
85
|
end
|
85
86
|
|
86
|
-
should
|
87
|
+
should 'return all licenses' do
|
87
88
|
assert_equal Array, Licensee::License.all.class
|
88
89
|
assert Licensee::License.all.size > 3
|
89
90
|
end
|
90
91
|
|
91
|
-
should
|
92
|
-
assert_equal
|
92
|
+
should 'strip leading newlines from the license' do
|
93
|
+
assert_equal 'T', @license.body[0]
|
93
94
|
end
|
94
95
|
|
95
|
-
should
|
96
|
-
assert_raises(Licensee::InvalidLicense)
|
96
|
+
should 'fail loudly for invalid licenses' do
|
97
|
+
assert_raises(Licensee::InvalidLicense) do
|
98
|
+
Licensee::License.new('foo').name
|
99
|
+
end
|
97
100
|
end
|
98
101
|
|
99
102
|
should "support 'other' licenses" do
|
100
|
-
license = Licensee::License.new(
|
103
|
+
license = Licensee::License.new('other')
|
101
104
|
assert_equal nil, license.content
|
102
|
-
assert_equal
|
105
|
+
assert_equal 'Other', license.name
|
103
106
|
refute license.featured?
|
104
107
|
end
|
105
108
|
|
106
|
-
should
|
107
|
-
assert_equal
|
109
|
+
should 'know the license hash' do
|
110
|
+
assert_equal 'fb278496ea4663dfcf41ed672eb7e56eb70de798', @license.hash
|
108
111
|
end
|
109
112
|
|
110
|
-
describe
|
111
|
-
should
|
112
|
-
expected =
|
113
|
-
|
114
|
-
expected
|
115
|
-
|
116
|
-
|
113
|
+
describe 'name without version' do
|
114
|
+
should 'strip the version from the license name' do
|
115
|
+
expected = 'GNU Affero General Public License'
|
116
|
+
name = Licensee::License.find('agpl-3.0').name_without_version
|
117
|
+
assert_equal expected, name
|
118
|
+
|
119
|
+
expected = 'GNU General Public License'
|
120
|
+
name = Licensee::License.find('gpl-2.0').name_without_version
|
121
|
+
assert_equal expected, name
|
122
|
+
|
123
|
+
name = Licensee::License.find('gpl-3.0').name_without_version
|
124
|
+
assert_equal expected, name
|
117
125
|
end
|
118
126
|
|
119
127
|
Licensee.licenses.each do |license|
|
@@ -123,30 +131,34 @@ class TestLicenseeLicense < Minitest::Test
|
|
123
131
|
end
|
124
132
|
end
|
125
133
|
|
126
|
-
describe
|
127
|
-
should
|
134
|
+
describe 'class methods' do
|
135
|
+
should 'know license names' do
|
128
136
|
assert_equal Array, Licensee::License.keys.class
|
129
|
-
assert_equal
|
137
|
+
assert_equal 26, Licensee::License.keys.size
|
130
138
|
end
|
131
139
|
|
132
|
-
should
|
140
|
+
should 'load the licenses' do
|
133
141
|
assert_equal Array, Licensee::License.all.class
|
134
142
|
assert_equal 15, Licensee::License.all.size
|
135
143
|
assert_equal Licensee::License, Licensee::License.all.first.class
|
136
144
|
end
|
137
145
|
|
138
|
-
should
|
139
|
-
assert_equal
|
140
|
-
assert_equal
|
141
|
-
assert_equal
|
146
|
+
should 'find a license' do
|
147
|
+
assert_equal 'mit', Licensee::License.find('mit').key
|
148
|
+
assert_equal 'mit', Licensee::License.find('MIT').key
|
149
|
+
assert_equal 'mit', Licensee::License['mit'].key
|
142
150
|
end
|
143
151
|
|
144
|
-
should
|
145
|
-
assert_equal
|
146
|
-
assert_equal 3, Licensee::License.all(:
|
147
|
-
assert_equal 12, Licensee::License.all(:
|
148
|
-
|
149
|
-
|
152
|
+
should 'filter the licenses' do
|
153
|
+
assert_equal 26, Licensee::License.all(hidden: true).size
|
154
|
+
assert_equal 3, Licensee::License.all(featured: true).size
|
155
|
+
assert_equal 12, Licensee::License.all(featured: false).size
|
156
|
+
|
157
|
+
licenses = Licensee::License.all(featured: false, hidden: true)
|
158
|
+
assert_equal 23, licenses.size
|
159
|
+
|
160
|
+
licenses = Licensee::License.all(featured: false, hidden: false)
|
161
|
+
assert_equal 12, licenses.size
|
150
162
|
end
|
151
163
|
end
|
152
164
|
end
|
@@ -2,54 +2,56 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TestLicenseeLicenseFile < Minitest::Test
|
4
4
|
def setup
|
5
|
-
@repo = Rugged::Repository.new(fixture_path(
|
6
|
-
|
5
|
+
@repo = Rugged::Repository.new(fixture_path('licenses.git'))
|
6
|
+
ref = 'bcb552d06d9cf1cd4c048a6d3bf716849c2216cc'
|
7
|
+
blob, = Rugged::Blob.to_buffer(@repo, ref)
|
7
8
|
@file = Licensee::Project::LicenseFile.new(blob)
|
8
9
|
end
|
9
10
|
|
10
|
-
context
|
11
|
-
should
|
12
|
-
assert_equal
|
11
|
+
context 'content' do
|
12
|
+
should 'parse the attribution' do
|
13
|
+
assert_equal 'Copyright (c) 2014 Ben Balter', @file.attribution
|
13
14
|
end
|
14
15
|
|
15
|
-
should
|
16
|
+
should 'not choke on non-UTF-8 licenses' do
|
16
17
|
text = "\x91License\x93".force_encoding('windows-1251')
|
17
18
|
file = Licensee::Project::LicenseFile.new(text)
|
18
19
|
assert_equal nil, file.attribution
|
19
20
|
end
|
20
21
|
|
21
|
-
should
|
22
|
+
should 'create the wordset' do
|
22
23
|
assert_equal 93, @file.wordset.count
|
23
|
-
assert_equal
|
24
|
+
assert_equal 'the', @file.wordset.first
|
24
25
|
end
|
25
26
|
|
26
|
-
should
|
27
|
-
assert_equal
|
27
|
+
should 'create the hash' do
|
28
|
+
assert_equal 'fb278496ea4663dfcf41ed672eb7e56eb70de798', @file.hash
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
31
|
-
context
|
32
|
+
context 'license filename scoring' do
|
32
33
|
EXPECTATIONS = {
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
}
|
34
|
+
'license' => 1.0,
|
35
|
+
'LICENCE' => 1.0,
|
36
|
+
'unLICENSE' => 1.0,
|
37
|
+
'unlicence' => 1.0,
|
38
|
+
'license.md' => 0.9,
|
39
|
+
'LICENSE.md' => 0.9,
|
40
|
+
'license.txt' => 0.9,
|
41
|
+
'COPYING' => 0.8,
|
42
|
+
'copyRIGHT' => 0.8,
|
43
|
+
'COPYRIGHT.txt' => 0.8,
|
44
|
+
'LICENSE.php' => 0.7,
|
45
|
+
'LICENSE-MIT' => 0.5,
|
46
|
+
'MIT-LICENSE.txt' => 0.5,
|
47
|
+
'mit-license-foo.md' => 0.5,
|
48
|
+
'README.txt' => 0.0
|
49
|
+
}.freeze
|
49
50
|
|
50
51
|
EXPECTATIONS.each do |filename, expected|
|
51
52
|
should "score a license named `#{filename}` as `#{expected}`" do
|
52
|
-
|
53
|
+
score = Licensee::Project::LicenseFile.name_score(filename)
|
54
|
+
assert_equal expected, score
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|