comment_extractor 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -9
- data/lib/comment_extractor.rb +1 -1
- data/lib/comment_extractor/configuration.rb +31 -24
- data/lib/comment_extractor/encoding.rb +2 -0
- data/lib/comment_extractor/extractor/concerns/simple_extractor.rb +12 -12
- data/lib/comment_extractor/{extractor_manager.rb → extractors.rb} +7 -9
- data/lib/comment_extractor/file.rb +22 -25
- data/lib/comment_extractor/parser.rb +13 -13
- data/lib/comment_extractor/string_scanner.rb +9 -0
- data/lib/comment_extractor/version.rb +1 -1
- data/spec/comment_extractor/configuration_spec.rb +35 -20
- data/spec/comment_extractor/{extractor_manager_spec.rb → extractors_spec.rb} +11 -11
- data/spec/comment_extractor/file_spec.rb +1 -3
- data/spec/comment_extractor/parser_spec.rb +18 -8
- data/spec/comment_extractor/string_scanner_spec.rb +20 -0
- data/spec/spec_helper.rb +0 -1
- metadata +12 -12
- data/lib/comment_extractor/smart_string_scanner.rb +0 -11
- data/spec/comment_extractor/smart_string_scanner_spec.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26dd72ab6442793761943f54fb4c9763ebbadc21
|
4
|
+
data.tar.gz: cd8e371d7e38412c592bf6a23ab9023b2a043379
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0b73f0e94de1f7cc1b6436fe781aa671192216b6f86a8536619d334161b4a51a1ed042111d1763d3a22f7975c09e7e3ee748d623e5c5c3c44c7ad0fb2de1bfb
|
7
|
+
data.tar.gz: 2f6f6267f30da17410eddba615cc1b8f6b2e8fe295fb6360ac17f54ea012c85072d72ed8bd4608c882413423126580a27b3c082c3e8b1f80aabc84dea534e6fa
|
data/README.md
CHANGED
@@ -47,17 +47,14 @@ end
|
|
47
47
|
require 'comment_extractor'
|
48
48
|
|
49
49
|
file_path = 'path/to/file.rb'
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
comments = extractor.new(content).extract_comments
|
54
|
-
comemnts.is_a?(CommentExtractor::CodeObjects)
|
50
|
+
if extractor = CommentExtractor::Extractors.find_by_filetype('ruby')
|
51
|
+
parser = CommentExtractor::Parser.initialize_with_extractor(file_path, extractor)
|
52
|
+
comments = parser.extract_comments
|
55
53
|
end
|
56
54
|
|
57
55
|
# Other way to find extractor
|
58
|
-
extractor =
|
59
|
-
extractor =
|
60
|
-
extractor = manager.find_extractor_by_filetype('ruby')
|
56
|
+
extractor = CommentExtractor::Extractors.find_by_shebang('#! /usr/local/bin/ruby')
|
57
|
+
extractor = CommentExtractor::Extractors.find_by_filename('path/to/file.rb')
|
61
58
|
```
|
62
59
|
|
63
60
|
#### How to use extractor of specific filetype.
|
@@ -65,7 +62,8 @@ extractor = manager.find_extractor_by_filetype('ruby')
|
|
65
62
|
```ruby
|
66
63
|
require 'comment_extractor/extractor/d'
|
67
64
|
|
68
|
-
|
65
|
+
# Remove shebang and encoding content
|
66
|
+
content = CommentExtractor::File.open('path/to/file.d', 'r') { |f| f.read_content }
|
69
67
|
comments = CommentExtractor::Extractor::D.new(content).extract_comments
|
70
68
|
```
|
71
69
|
|
data/lib/comment_extractor.rb
CHANGED
@@ -2,7 +2,7 @@ require 'comment_extractor/code_object'
|
|
2
2
|
require 'comment_extractor/configuration'
|
3
3
|
require 'comment_extractor/encoding'
|
4
4
|
require 'comment_extractor/extractor'
|
5
|
-
require 'comment_extractor/
|
5
|
+
require 'comment_extractor/extractors'
|
6
6
|
require 'comment_extractor/file'
|
7
7
|
require 'comment_extractor/parser'
|
8
8
|
require 'comment_extractor/version'
|
@@ -1,44 +1,51 @@
|
|
1
|
-
require 'comment_extractor/
|
1
|
+
require 'comment_extractor/extractors'
|
2
2
|
require 'comment_extractor/extractor/text'
|
3
3
|
|
4
4
|
module CommentExtractor
|
5
5
|
class Configuration
|
6
|
-
@@required_attributes = {}
|
7
|
-
|
8
6
|
def initialize(attributes = {})
|
7
|
+
required_attributes = self.class.required_attributes.dup
|
8
|
+
|
9
9
|
attributes.each do |key, value|
|
10
|
-
|
11
|
-
send(
|
10
|
+
required_attributes.delete(key)
|
11
|
+
send("#{key}=", value)
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
unless required_attributes.empty?
|
15
|
+
keys = required_attributes.keys.map { |v| ":#{v}" }.join(', ')
|
16
|
+
raise ArgumentError, "Unable to initialize #{keys} without attribute"
|
16
17
|
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
@extractors = Extractors.default_extractors
|
20
|
+
@default_extractor = Extractor::Text
|
21
|
+
@use_default_extractor = true
|
21
22
|
end
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
class << self
|
25
|
+
def add_setting(name, opts={})
|
26
|
+
attr_accessor name
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
define_predicating_for(name) if opts.delete(:predicate)
|
29
|
+
define_required_attribute(name) if opts.delete(:required)
|
30
|
+
end
|
29
31
|
|
30
|
-
|
32
|
+
def required_attributes
|
33
|
+
@required_attributes ||= {}
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
31
37
|
|
32
|
-
|
33
|
-
|
34
|
-
|
38
|
+
def define_required_attribute(*names)
|
39
|
+
names.each do |name|
|
40
|
+
required_attributes[name] = nil
|
41
|
+
end
|
35
42
|
end
|
36
|
-
end
|
37
43
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
44
|
+
def define_predicating_for(*names)
|
45
|
+
names.each do |name|
|
46
|
+
define_method "#{name}?" do
|
47
|
+
!!send(name)
|
48
|
+
end
|
42
49
|
end
|
43
50
|
end
|
44
51
|
end
|
@@ -1,6 +1,4 @@
|
|
1
|
-
require 'comment_extractor/
|
2
|
-
|
3
|
-
using CommentExtractor::SmartStringScanner
|
1
|
+
require 'comment_extractor/string_scanner'
|
4
2
|
|
5
3
|
class CommentExtractor::Extractor
|
6
4
|
module Concerns
|
@@ -34,6 +32,7 @@ class CommentExtractor::Extractor
|
|
34
32
|
|
35
33
|
def comment(start_with: nil, end_with: nil, type: ONE_LINER_COMMENT)
|
36
34
|
@comment_regexp ||= []
|
35
|
+
# Check required attributes
|
37
36
|
raise ArgumentError unless [type, start_with].all?
|
38
37
|
|
39
38
|
definition = { start_with: build_regexp(start_with), type: type, end_with: end_with }
|
@@ -41,6 +40,7 @@ class CommentExtractor::Extractor
|
|
41
40
|
if type == BLOCK_COMMENT
|
42
41
|
definition[:end_with] = build_regexp(end_with, Regexp::MULTILINE)
|
43
42
|
end
|
43
|
+
|
44
44
|
@comment_regexp << definition
|
45
45
|
end
|
46
46
|
|
@@ -51,13 +51,13 @@ class CommentExtractor::Extractor
|
|
51
51
|
|
52
52
|
def define_bracket(bracket, options = 0)
|
53
53
|
start_regexp = build_regexp(bracket)
|
54
|
-
|
54
|
+
end_regexp = if bracket.is_a?(Regexp)
|
55
55
|
join_regexp(/(?<!\\)/, bracket)
|
56
56
|
else
|
57
57
|
/(?<!\\)#{bracket}/
|
58
58
|
end
|
59
|
-
|
60
|
-
append_bracket(start_regexp,
|
59
|
+
end_regexp = Regexp.new(end_regexp.source, options)
|
60
|
+
append_bracket(start_regexp, end_regexp)
|
61
61
|
end
|
62
62
|
|
63
63
|
def define_regexp_bracket
|
@@ -129,8 +129,9 @@ class CommentExtractor::Extractor
|
|
129
129
|
end_with = definition[:end_with]
|
130
130
|
next unless scanner.scan(start_with)
|
131
131
|
|
132
|
-
|
133
|
-
|
132
|
+
end_with_source = /.*?/.source + end_with.source
|
133
|
+
end_with_regexp = Regexp.new(end_with_source, end_with.options)
|
134
|
+
return scanner.scan(end_with_regexp)
|
134
135
|
end
|
135
136
|
|
136
137
|
nil
|
@@ -167,18 +168,17 @@ class CommentExtractor::Extractor
|
|
167
168
|
line_number = scanner.current_line
|
168
169
|
comment = scanner.scan(/^.*$/)
|
169
170
|
metadata = { type: ONE_LINER_COMMENT }
|
170
|
-
comment_object = build_comment(line_number, comment, **metadata)
|
171
171
|
|
172
|
-
code_objects <<
|
172
|
+
code_objects << build_comment(line_number, comment, **metadata)
|
173
173
|
end
|
174
174
|
|
175
175
|
def identify_multi_line_comment(regexp)
|
176
176
|
line_no = scanner.current_line
|
177
177
|
stop_regexp = Regexp.new(/.*?/.source + regexp.source, regexp.options)
|
178
|
-
|
178
|
+
block_comment = scanner.scan(stop_regexp)
|
179
179
|
|
180
180
|
remove_tail_regexp = Regexp.new(regexp.source + /$/.source)
|
181
|
-
comments =
|
181
|
+
comments = block_comment.sub(remove_tail_regexp, '').split("\n")
|
182
182
|
comments.each_with_index do |comment, index|
|
183
183
|
metadata = { type: BLOCK_COMMENT }
|
184
184
|
code_objects << build_comment(line_no + index, comment, metadata)
|
@@ -2,10 +2,8 @@ require 'comment_extractor'
|
|
2
2
|
require 'comment_extractor/extractor'
|
3
3
|
require 'comment_extractor/file'
|
4
4
|
|
5
|
-
using CommentExtractor::DetectableSchemeFile
|
6
|
-
|
7
5
|
module CommentExtractor
|
8
|
-
module
|
6
|
+
module Extractors
|
9
7
|
class << self
|
10
8
|
def default_extractors
|
11
9
|
%i[
|
@@ -39,11 +37,11 @@ module CommentExtractor
|
|
39
37
|
|
40
38
|
extractor = nil
|
41
39
|
if shebang = File.shebang(file_path)
|
42
|
-
extractor =
|
40
|
+
extractor = find_by_shebang(shebang)
|
43
41
|
end
|
44
42
|
|
45
43
|
unless extractor
|
46
|
-
extractor =
|
44
|
+
extractor = find_by_filename(file_path)
|
47
45
|
end
|
48
46
|
|
49
47
|
if ::CommentExtractor.configuration.use_default_extractor
|
@@ -63,8 +61,8 @@ module CommentExtractor
|
|
63
61
|
defined_extractor_finders.concat(keys)
|
64
62
|
|
65
63
|
keys.each do |key|
|
66
|
-
define_singleton_method "
|
67
|
-
|
64
|
+
define_singleton_method "find_by_#{key}" do |value|
|
65
|
+
find_by(key, value)
|
68
66
|
end
|
69
67
|
end
|
70
68
|
end
|
@@ -77,7 +75,7 @@ module CommentExtractor
|
|
77
75
|
self
|
78
76
|
end
|
79
77
|
|
80
|
-
def
|
78
|
+
def find_by(key, value)
|
81
79
|
case key
|
82
80
|
when :filename, :shebang
|
83
81
|
# Regexp optimization which can find value O(1)
|
@@ -152,7 +150,7 @@ module CommentExtractor
|
|
152
150
|
end
|
153
151
|
end
|
154
152
|
|
155
|
-
# define :
|
153
|
+
# define :find_by_shebang, :find_by_filename
|
156
154
|
define_extractor_finder_by *Extractor::SCHAME_ACCESSOR_NAMES
|
157
155
|
end
|
158
156
|
end
|
@@ -1,42 +1,39 @@
|
|
1
1
|
require 'comment_extractor/encoding'
|
2
2
|
|
3
3
|
module CommentExtractor
|
4
|
-
|
4
|
+
class File < ::File
|
5
5
|
THRESHOLD_BINARY = 0.3
|
6
6
|
|
7
|
-
|
8
|
-
attr_accessor :content, :shebang
|
7
|
+
attr_accessor :content, :shebang
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
shebang_path
|
16
|
-
end
|
9
|
+
def self.shebang(path)
|
10
|
+
if File.extname(path).empty?
|
11
|
+
line = File.open(path) { |f| f.gets }
|
12
|
+
if /\A#!\s*(?<shebang_path>.+)/ =~ line
|
13
|
+
shebang_path
|
17
14
|
end
|
18
15
|
end
|
16
|
+
end
|
19
17
|
|
20
|
-
|
21
|
-
|
18
|
+
def self.binary?(file_path)
|
19
|
+
header = File.read(file_path, File.stat(file_path).blksize) || nil
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
21
|
+
if header.nil? || header.empty?
|
22
|
+
false
|
23
|
+
else
|
24
|
+
chars = header.chars
|
25
|
+
(chars.grep(' '..'~').size / chars.size.to_f) <= THRESHOLD_BINARY
|
29
26
|
end
|
27
|
+
end
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
if File.shebang(self.path)
|
35
|
-
self.gets # Remove shebang
|
36
|
-
end
|
29
|
+
def read_content
|
30
|
+
return if File.binary?(self.path)
|
37
31
|
|
38
|
-
|
32
|
+
if File.shebang(self.path)
|
33
|
+
self.gets # Remove shebang
|
39
34
|
end
|
35
|
+
|
36
|
+
CommentExtractor::Encoding.encode(self.read) || ''
|
40
37
|
end
|
41
38
|
end
|
42
39
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'comment_extractor/file'
|
2
|
-
require 'comment_extractor/
|
3
|
-
|
4
|
-
using CommentExtractor::DetectableSchemeFile
|
2
|
+
require 'comment_extractor/extractors'
|
5
3
|
|
6
4
|
module CommentExtractor
|
7
5
|
class Parser
|
@@ -17,17 +15,19 @@ module CommentExtractor
|
|
17
15
|
raise TypeError, "#{@extractor} should be a instance of #{Extractor}"
|
18
16
|
end
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
content = File.open(file_path, 'r') { |f| f.read_content }
|
24
|
-
|
25
|
-
# Initialize parser
|
26
|
-
code_objects = CodeObjects.new(file: file_path)
|
27
|
-
instance_of_extractor = extractor.new(content, code_objects)
|
28
|
-
new(instance_of_extractor)
|
29
|
-
end
|
18
|
+
def self.for(file_path)
|
19
|
+
if extractor = Extractors.can_extract(file_path)
|
20
|
+
self.initialize_with_extractor(file_path, extractor)
|
30
21
|
end
|
31
22
|
end
|
23
|
+
|
24
|
+
def self.initialize_with_extractor(file_path, extractor)
|
25
|
+
content = File.open(file_path, 'r') { |f| f.read_content }
|
26
|
+
|
27
|
+
# Initialize parser
|
28
|
+
code_objects = CodeObjects.new(file: file_path)
|
29
|
+
instance_of_extractor = extractor.new(content, code_objects)
|
30
|
+
new(instance_of_extractor)
|
31
|
+
end
|
32
32
|
end
|
33
33
|
end
|
@@ -3,32 +3,48 @@ require 'comment_extractor/configuration'
|
|
3
3
|
|
4
4
|
module CommentExtractor
|
5
5
|
describe Configuration do
|
6
|
+
before do
|
7
|
+
# Initializes class variables
|
8
|
+
@required_attributes = described_class.instance_variable_set(:@required_attributes, {})
|
9
|
+
|
10
|
+
described_class.instance_variable_set(:@required_attributes, {})
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
# Restores class variables
|
15
|
+
described_class.instance_variable_set(:@required_attributes, @required_attributes)
|
16
|
+
end
|
17
|
+
|
6
18
|
describe '.new' do
|
7
19
|
subject { CommentExtractor::Configuration.new(options) }
|
8
|
-
let(:options) { {
|
20
|
+
let(:options) { {} }
|
9
21
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
22
|
+
context 'given valid attributes' do
|
23
|
+
it 'sets attributes to default value' do
|
24
|
+
expect(subject.extractors).to eql Extractors.default_extractors
|
25
|
+
expect(subject.default_extractor).to eql Extractor::Text
|
26
|
+
expect(subject.use_default_extractor).to be_truthy
|
27
|
+
end
|
14
28
|
end
|
15
|
-
end
|
16
29
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
Configuration.class_variable_set(:@@required_attributes, {})
|
30
|
+
context 'given invalid attributes' do
|
31
|
+
before do
|
32
|
+
described_class.add_setting :required_attribute, required: true
|
33
|
+
end
|
22
34
|
|
23
|
-
|
35
|
+
it "raises 'Unable to initialize :key without attribute' as #{ArgumentError}" do
|
36
|
+
expect { subject }.to raise_error(ArgumentError)
|
37
|
+
end
|
24
38
|
end
|
39
|
+
end
|
25
40
|
|
26
|
-
|
27
|
-
|
28
|
-
|
41
|
+
describe '.add_setting' do
|
42
|
+
subject { described_class.new(option_of_initialization) }
|
43
|
+
|
44
|
+
before do
|
45
|
+
described_class.send(:add_setting, name, option_of_setting)
|
29
46
|
end
|
30
47
|
|
31
|
-
subject { Configuration.new(option_of_initialization) }
|
32
48
|
let(:name) { :setting_name }
|
33
49
|
let(:option_of_setting) { {} }
|
34
50
|
let(:option_of_initialization) { {} }
|
@@ -53,12 +69,11 @@ module CommentExtractor
|
|
53
69
|
context 'given required option' do
|
54
70
|
let(:option_of_setting) { { required: true } }
|
55
71
|
|
56
|
-
context 'when
|
57
|
-
|
58
|
-
it { expect { subject }.to raise_error(message) }
|
72
|
+
context 'when to initialize configuration without required attribute' do
|
73
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
59
74
|
end
|
60
75
|
|
61
|
-
context 'when
|
76
|
+
context 'when to initialize configuration with required attribute' do
|
62
77
|
let(:option_of_initialization) { { name => true } }
|
63
78
|
it { expect { subject }.to_not raise_error }
|
64
79
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'comment_extractor/
|
2
|
+
require 'comment_extractor/extractors'
|
3
3
|
|
4
4
|
module CommentExtractor
|
5
|
-
describe
|
5
|
+
describe Extractors do
|
6
6
|
after do
|
7
7
|
if described_class.instance_variable_defined?(:@extractors)
|
8
8
|
described_class.send(:remove_instance_variable, :@extractors)
|
@@ -74,22 +74,22 @@ module CommentExtractor
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
describe '.
|
78
|
-
subject { described_class.
|
77
|
+
describe '.find_by_shebang' do
|
78
|
+
subject { described_class.find_by_shebang(test_value) }
|
79
79
|
let(:registed_value) { '#! /usr/local/ruby' }
|
80
80
|
|
81
81
|
it_behaves_like 'trying to find extractor'
|
82
82
|
end
|
83
83
|
|
84
|
-
describe '.
|
85
|
-
subject { described_class.
|
84
|
+
describe '.find_by_filename' do
|
85
|
+
subject { described_class.find_by_filename(test_value) }
|
86
86
|
let(:registed_value) { 'path/to/file.rb' }
|
87
87
|
|
88
88
|
it_behaves_like 'trying to find extractor'
|
89
89
|
end
|
90
90
|
|
91
|
-
describe '.
|
92
|
-
subject { described_class.
|
91
|
+
describe '.find_by_filetype' do
|
92
|
+
subject { described_class.find_by_filetype('key') }
|
93
93
|
|
94
94
|
it 'finds ExtractorKlass by matching file type' do
|
95
95
|
should eql 'value'
|
@@ -133,9 +133,9 @@ module CommentExtractor
|
|
133
133
|
before do
|
134
134
|
allow(::CommentExtractor).to receive(:configuration).
|
135
135
|
and_return(stub_configuration)
|
136
|
-
allow(
|
136
|
+
allow(Extractors).to receive(:find_by_shebang).
|
137
137
|
and_return(nil)
|
138
|
-
allow(
|
138
|
+
allow(Extractors).to receive(:find_by_filename).
|
139
139
|
and_return(nil)
|
140
140
|
end
|
141
141
|
|
@@ -169,7 +169,7 @@ module CommentExtractor
|
|
169
169
|
subject { registered_extractors }
|
170
170
|
|
171
171
|
let(:described_method) { described_class.send(:initialize_extractors!) }
|
172
|
-
let(:default_extractors) {
|
172
|
+
let(:default_extractors) { Extractors.default_extractors }
|
173
173
|
|
174
174
|
it 'initializes extractors' do
|
175
175
|
expect(subject).to be_nil
|
@@ -2,10 +2,8 @@ require 'spec_helper'
|
|
2
2
|
require 'comment_extractor/file'
|
3
3
|
require 'tempfile'
|
4
4
|
|
5
|
-
using CommentExtractor::DetectableSchemeFile
|
6
|
-
|
7
5
|
module CommentExtractor
|
8
|
-
describe
|
6
|
+
describe File do
|
9
7
|
let(:file) { File.new(file_path) }
|
10
8
|
let(:asset_dir) { File.expand_path('../../assets', __FILE__) }
|
11
9
|
let(:binary_path) { "#{asset_dir}/binary_file" }
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'comment_extractor/parser'
|
3
3
|
|
4
|
-
using CommentExtractor::DetectableSchemeFile
|
5
|
-
|
6
4
|
module CommentExtractor
|
7
5
|
describe Parser do
|
8
6
|
let(:expected_comments) { [] }
|
@@ -36,16 +34,17 @@ module CommentExtractor
|
|
36
34
|
end
|
37
35
|
|
38
36
|
describe 'ClassMethods' do
|
37
|
+
let(:file_path) { __FILE__ }
|
38
|
+
|
39
39
|
describe '.for' do
|
40
40
|
subject { described_class.for(file_path) }
|
41
|
-
let(:file_path) { __FILE__ }
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
42
|
+
before do
|
43
|
+
allow(Extractors).to receive(:can_extract).
|
44
|
+
and_return(stub_extractor)
|
45
|
+
end
|
48
46
|
|
47
|
+
context 'when extractor is found' do
|
49
48
|
it 'initializes extractor' do
|
50
49
|
expect(subject).to be_an_instance_of described_class
|
51
50
|
extractor = subject.extractor
|
@@ -55,6 +54,17 @@ module CommentExtractor
|
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
57
|
+
describe '.initialize_with_extractor' do
|
58
|
+
subject { described_class.initialize_with_extractor(file_path, stub_extractor) }
|
59
|
+
|
60
|
+
context 'when extractor is found' do
|
61
|
+
it 'initializes extractor' do
|
62
|
+
expect(subject).to be_an_instance_of described_class
|
63
|
+
expect(subject.extractor).to be_an_instance_of stub_extractor
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
58
68
|
describe '.new' do
|
59
69
|
subject { described_class.new(stub_extractor) }
|
60
70
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'comment_extractor/string_scanner'
|
3
|
+
|
4
|
+
module CommentExtractor
|
5
|
+
describe StringScanner do
|
6
|
+
let(:scanner) { StringScanner.new("...\n...") }
|
7
|
+
|
8
|
+
describe '#current_line' do
|
9
|
+
it 'returns current line number' do
|
10
|
+
expect(scanner.current_line).to eql 1
|
11
|
+
|
12
|
+
scanner.scan(/^.*$/) # Scanning one line
|
13
|
+
expect(scanner.current_line).to eql 1
|
14
|
+
|
15
|
+
scanner.scan(/\n/) # Go to next line
|
16
|
+
expect(scanner.current_line).to eql 2
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -13,7 +13,6 @@ require 'rspec/comment_extractor'
|
|
13
13
|
RSpec.configure do |config|
|
14
14
|
config.order = 'random'
|
15
15
|
config.run_all_when_everything_filtered = true
|
16
|
-
config.show_failures_in_pending_blocks = true
|
17
16
|
config.raise_errors_for_deprecations!
|
18
17
|
config.include RSpec::CommentExtractor::ExtractorExampleGroup, type: :extractor, example_group: {
|
19
18
|
file_path: Regexp.compile(%w[spec comment_extractor extractor .*.rb].join('[\\\/]'))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: comment_extractor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alpaca-tc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: haml
|
@@ -25,13 +25,13 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rdoc
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
|
-
type: :
|
34
|
+
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -124,10 +124,10 @@ files:
|
|
124
124
|
- lib/comment_extractor/extractor/tex.rb
|
125
125
|
- lib/comment_extractor/extractor/text.rb
|
126
126
|
- lib/comment_extractor/extractor/yaml.rb
|
127
|
-
- lib/comment_extractor/
|
127
|
+
- lib/comment_extractor/extractors.rb
|
128
128
|
- lib/comment_extractor/file.rb
|
129
129
|
- lib/comment_extractor/parser.rb
|
130
|
-
- lib/comment_extractor/
|
130
|
+
- lib/comment_extractor/string_scanner.rb
|
131
131
|
- lib/comment_extractor/version.rb
|
132
132
|
- spec/assets/binary_file
|
133
133
|
- spec/assets/shebang_file
|
@@ -224,11 +224,11 @@ files:
|
|
224
224
|
- spec/comment_extractor/extractor/tex_spec.rb
|
225
225
|
- spec/comment_extractor/extractor/text_spec.rb
|
226
226
|
- spec/comment_extractor/extractor/yaml_spec.rb
|
227
|
-
- spec/comment_extractor/extractor_manager_spec.rb
|
228
227
|
- spec/comment_extractor/extractor_spec.rb
|
228
|
+
- spec/comment_extractor/extractors_spec.rb
|
229
229
|
- spec/comment_extractor/file_spec.rb
|
230
230
|
- spec/comment_extractor/parser_spec.rb
|
231
|
-
- spec/comment_extractor/
|
231
|
+
- spec/comment_extractor/string_scanner_spec.rb
|
232
232
|
- spec/comment_extractor/version_spec.rb
|
233
233
|
- spec/comment_extractor_spec.rb
|
234
234
|
- spec/spec_helper.rb
|
@@ -356,11 +356,11 @@ test_files:
|
|
356
356
|
- spec/comment_extractor/extractor/tex_spec.rb
|
357
357
|
- spec/comment_extractor/extractor/text_spec.rb
|
358
358
|
- spec/comment_extractor/extractor/yaml_spec.rb
|
359
|
-
- spec/comment_extractor/extractor_manager_spec.rb
|
360
359
|
- spec/comment_extractor/extractor_spec.rb
|
360
|
+
- spec/comment_extractor/extractors_spec.rb
|
361
361
|
- spec/comment_extractor/file_spec.rb
|
362
362
|
- spec/comment_extractor/parser_spec.rb
|
363
|
-
- spec/comment_extractor/
|
363
|
+
- spec/comment_extractor/string_scanner_spec.rb
|
364
364
|
- spec/comment_extractor/version_spec.rb
|
365
365
|
- spec/comment_extractor_spec.rb
|
366
366
|
- spec/spec_helper.rb
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'comment_extractor/smart_string_scanner'
|
3
|
-
|
4
|
-
using CommentExtractor::SmartStringScanner
|
5
|
-
|
6
|
-
module CommentExtractor
|
7
|
-
describe SmartStringScanner do
|
8
|
-
let(:scanner) { StringScanner.new("...\n...") }
|
9
|
-
|
10
|
-
describe 'refines #current_line' do
|
11
|
-
context 'when scanner has already used' do
|
12
|
-
it 'returns current line number' do
|
13
|
-
expect(scanner.current_line).to eql 1
|
14
|
-
|
15
|
-
scanner.scan(/^.*$/) # Scanning one line
|
16
|
-
expect(scanner.current_line).to eql 1
|
17
|
-
|
18
|
-
scanner.scan(/\n/) # Go to next line
|
19
|
-
expect(scanner.current_line).to eql 2
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|