defmastership 1.0.13 → 1.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/defmastership.gemspec +1 -1
- data/features/export.feature +21 -0
- data/lib/defmastership/comment_filter.rb +1 -34
- data/lib/defmastership/constants.rb +0 -5
- data/lib/defmastership/document.rb +4 -7
- data/lib/defmastership/filters.rb +0 -7
- data/lib/defmastership/parsing_state.rb +1 -1
- data/lib/defmastership/version.rb +1 -1
- data/spec/unit/defmastership/comment_filter_spec.rb +5 -119
- data/spec/unit/defmastership/parsing_state_spec.rb +12 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 942362543576801349518b2d73e49abb5cfb076b246df05a7e28fe86814b506e
|
4
|
+
data.tar.gz: 1a351eadc8b3583df8f31b590225a4b8e5207d7db089b3a62ac644f03fa02c08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6151951967b1d4b0e2108b2b11f101045780d6ec3f8ba4505078dbb1c240f2795bd56cce0f177187c58b2d8dacd3d63c1cfce6ca8969cb5f54d972d32d61e42b
|
7
|
+
data.tar.gz: 6836a23ffae998a9a1b54716941b0e9bb661e81f18a4422ad984af1ee41218b685ba937c108298f8a02cf348af434ddd1138f81c5644017193c5d72d6ad2cbdd
|
data/defmastership.gemspec
CHANGED
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
|
|
34
34
|
s.add_development_dependency('rake', '~> 13')
|
35
35
|
s.add_development_dependency('rdoc', '~> 6')
|
36
36
|
s.add_development_dependency('rspec', '~> 3')
|
37
|
-
s.add_development_dependency('rubocop', '
|
37
|
+
s.add_development_dependency('rubocop', '1.13')
|
38
38
|
s.add_development_dependency('rubocop-rake', '~> 0.5')
|
39
39
|
s.add_development_dependency('rubocop-rspec', '~> 2.0')
|
40
40
|
s.add_development_dependency('simplecov', '~> 0')
|
data/features/export.feature
CHANGED
@@ -116,6 +116,27 @@ Feature: The extract command
|
|
116
116
|
And the stdout should not contain anything
|
117
117
|
And the stderr should not contain anything
|
118
118
|
|
119
|
+
Scenario: Ignore definitions in example block
|
120
|
+
Given a file named "toto.adoc" with:
|
121
|
+
"""
|
122
|
+
[define, requirement, TOTO-0001]
|
123
|
+
--
|
124
|
+
Exemple of multiline requirement.
|
125
|
+
Second line.
|
126
|
+
--
|
127
|
+
----
|
128
|
+
[define, something_else, TOTO-0003]
|
129
|
+
only one line
|
130
|
+
----
|
131
|
+
"""
|
132
|
+
When I successfully run `defmastership export toto.adoc`
|
133
|
+
Then the file "toto.csv" should not contain:
|
134
|
+
"""
|
135
|
+
something_else
|
136
|
+
"""
|
137
|
+
And the stdout should not contain anything
|
138
|
+
And the stderr should not contain anything
|
139
|
+
|
119
140
|
Scenario: Ignore definitions in commment block
|
120
141
|
Given a file named "toto.adoc" with:
|
121
142
|
"""
|
@@ -1,43 +1,10 @@
|
|
1
1
|
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
# Add a class to handled asciidoctor comments
|
5
|
-
module DefMastership
|
6
|
-
attr_reader :comment_filter
|
7
|
-
|
8
|
-
# Kind of proxy that Filters comments fome Asciidoctor document
|
9
|
-
class CommentFilter
|
10
|
-
def initialize
|
11
|
-
@in_multiline_comment = false
|
12
|
-
end
|
13
|
-
|
14
|
-
def accept?(line)
|
15
|
-
case line
|
16
|
-
when DMRegexp::SINGLE_LINE_COMMENT then false
|
17
|
-
when DMRegexp::MULTI_LINE_COMMENT_DELIM
|
18
|
-
@in_multiline_comment ^= true
|
19
|
-
false
|
20
|
-
else !@in_multiline_comment
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
@comment_filter = CommentFilter.new
|
26
|
-
|
27
|
-
def self.reset_comments
|
28
|
-
@comment_filter = CommentFilter.new
|
29
|
-
nil
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.comment_filter
|
33
|
-
@comment_filter
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
4
|
# adding a method to string to figure out if a string is commented or
|
38
5
|
# not.
|
39
6
|
class String
|
40
7
|
def commented?
|
41
|
-
!DefMastership.
|
8
|
+
!match(DefMastership::DMRegexp::SINGLE_LINE_COMMENT).nil?
|
42
9
|
end
|
43
10
|
end
|
@@ -6,8 +6,6 @@ module DefMastership
|
|
6
6
|
module DMRegexp
|
7
7
|
SINGLE_LINE_COMMENT = %r{^//[^/]}.freeze
|
8
8
|
|
9
|
-
MULTI_LINE_COMMENT_DELIM = %r{^////\s*$}.freeze
|
10
|
-
|
11
9
|
DEF_BEFORE_REF = <<~'BEF'
|
12
10
|
^\s*
|
13
11
|
\[\s*define\s*,
|
@@ -41,7 +39,6 @@ module DefMastership
|
|
41
39
|
\s*(?<refname>[\w:_-]+)\s*,
|
42
40
|
\s*\[(?<extrefs>[^\]]+)\]\s*\]/x.freeze
|
43
41
|
BLOCK = /^--\s*$/.freeze
|
44
|
-
LITERAL_BLOCK = /^\.\.\.\.\s*$/.freeze
|
45
42
|
|
46
43
|
IREF_DEF_BEF = 'defs:iref\[\s*'
|
47
44
|
IREF_DEF_AFT = '\s*\]'
|
@@ -72,7 +69,6 @@ module DefMastership
|
|
72
69
|
)
|
73
70
|
|
74
71
|
public_constant :SINGLE_LINE_COMMENT,
|
75
|
-
:MULTI_LINE_COMMENT_DELIM,
|
76
72
|
:DEF_BEFORE_REF,
|
77
73
|
:DEF_AFTER_REF,
|
78
74
|
:DEFINITION,
|
@@ -81,7 +77,6 @@ module DefMastership
|
|
81
77
|
:EREF_CONFIG,
|
82
78
|
:EREF_DEF,
|
83
79
|
:BLOCK,
|
84
|
-
:LITERAL_BLOCK,
|
85
80
|
:IREF_DEF_BEF,
|
86
81
|
:IREF_DEF_AFT,
|
87
82
|
:IREF_DEF,
|
@@ -16,14 +16,16 @@ module DefMastership
|
|
16
16
|
@eref = {}
|
17
17
|
@iref = false
|
18
18
|
@attributes = {}
|
19
|
-
@in_literal = true
|
20
19
|
@variables = {}
|
20
|
+
@parsing_state = ParsingState.new
|
21
21
|
@definition_parser = DefinitionParser.new(self)
|
22
22
|
end
|
23
23
|
|
24
24
|
def parse(lines)
|
25
25
|
lines.reject(&:commented?).each do |line|
|
26
|
-
|
26
|
+
next unless @parsing_state.enabled?(line)
|
27
|
+
|
28
|
+
FILTERS.each do |filter|
|
27
29
|
next unless line.match(filter.regexp)
|
28
30
|
|
29
31
|
line = generate_event(filter.event, Regexp.last_match, line)
|
@@ -49,11 +51,6 @@ module DefMastership
|
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
52
|
-
def code_block_delimiter(_match, line)
|
53
|
-
@in_literal ^= true
|
54
|
-
line
|
55
|
-
end
|
56
|
-
|
57
54
|
def add_new_definition(match, line)
|
58
55
|
definition = Definition.new(match)
|
59
56
|
@labels.merge(definition.labels)
|
@@ -6,12 +6,6 @@ module DefMastership
|
|
6
6
|
Filter = Struct.new(:regexp, :event, :consumed_line)
|
7
7
|
private_constant :Filter
|
8
8
|
|
9
|
-
FILTERS_IN_LITERAL = [
|
10
|
-
Filter.new(DMRegexp::LITERAL_BLOCK, :code_block_delimiter, false),
|
11
|
-
Filter.new(DMRegexp::WHATEVER, :new_line, true)
|
12
|
-
].freeze
|
13
|
-
private_constant :FILTERS_IN_LITERAL
|
14
|
-
|
15
9
|
FILTERS = [
|
16
10
|
Filter.new(DMRegexp::VARIABLE_DEF, :new_variable_def, false),
|
17
11
|
Filter.new(DMRegexp::VARIABLE_USE, :new_variable_use, false),
|
@@ -22,7 +16,6 @@ module DefMastership
|
|
22
16
|
Filter.new(DMRegexp::ATTR_CONFIG, :new_attribute_conf, true),
|
23
17
|
Filter.new(DMRegexp::ATTR_SET, :new_attribute_value, false),
|
24
18
|
Filter.new(DMRegexp::BLOCK, :block_delimiter, true),
|
25
|
-
Filter.new(DMRegexp::LITERAL_BLOCK, :code_block_delimiter, true),
|
26
19
|
Filter.new(DMRegexp::EMPTY_LINE, :empty_line, false),
|
27
20
|
Filter.new(DMRegexp::WHATEVER, :new_line, true)
|
28
21
|
].freeze
|
@@ -3,124 +3,10 @@
|
|
3
3
|
|
4
4
|
require('defmastership')
|
5
5
|
|
6
|
-
RSpec.describe(
|
7
|
-
|
8
|
-
it {
|
9
|
-
|
10
|
-
|
11
|
-
describe '#accept?' do
|
12
|
-
subject(:comment_filter) { described_class.new }
|
13
|
-
|
14
|
-
context 'when no comment' do
|
15
|
-
it do
|
16
|
-
expect(comment_filter.accept?('whatever')).to(be(true))
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'when single line comment' do
|
21
|
-
it do
|
22
|
-
expect(comment_filter.accept?('// whatever')).to(be(false))
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'when bat formated single line comment' do
|
27
|
-
it do
|
28
|
-
expect(comment_filter.accept?('///')).to(be(true))
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'when starting multiline comment' do
|
33
|
-
it do
|
34
|
-
expect(comment_filter.accept?('////')).to(be(false))
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'when multiline comment' do
|
39
|
-
before do
|
40
|
-
comment_filter.accept?('////')
|
41
|
-
end
|
42
|
-
|
43
|
-
it do
|
44
|
-
expect(comment_filter.accept?('whatever')).to(be(false))
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'when exiting multiline comment' do
|
49
|
-
before do
|
50
|
-
comment_filter.accept?('////')
|
51
|
-
comment_filter.accept?('something')
|
52
|
-
end
|
53
|
-
|
54
|
-
it do
|
55
|
-
expect(comment_filter.accept?('////')).to(be(false))
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'when end of multiline comment' do
|
60
|
-
before do
|
61
|
-
comment_filter.accept?('////')
|
62
|
-
comment_filter.accept?('something')
|
63
|
-
comment_filter.accept?('////')
|
64
|
-
end
|
65
|
-
|
66
|
-
it do
|
67
|
-
expect(comment_filter.accept?('whatever')).to(be(true))
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe 'String .commented?' do
|
73
|
-
let(:comment_filter) do
|
74
|
-
instance_double(described_class, 'comment_filter')
|
75
|
-
end
|
76
|
-
|
77
|
-
before do
|
78
|
-
allow(DefMastership).to(
|
79
|
-
receive(:comment_filter)
|
80
|
-
.and_return(comment_filter)
|
81
|
-
)
|
82
|
-
end
|
83
|
-
|
84
|
-
context 'when not .commented?' do
|
85
|
-
before do
|
86
|
-
allow(comment_filter).to(receive(:accept?).with('blabla').and_return(true))
|
87
|
-
'blabla'.commented?
|
88
|
-
end
|
89
|
-
|
90
|
-
it { expect(DefMastership).to(have_received(:comment_filter)) }
|
91
|
-
|
92
|
-
it { expect(comment_filter).to(have_received(:accept?).with('blabla')) }
|
93
|
-
|
94
|
-
it { expect('blabla'.commented?).to(be(false)) }
|
95
|
-
end
|
96
|
-
|
97
|
-
context 'when .commented?' do
|
98
|
-
before do
|
99
|
-
allow(comment_filter).to(
|
100
|
-
receive(:accept?)
|
101
|
-
.with('blabla').and_return(false)
|
102
|
-
)
|
103
|
-
end
|
104
|
-
|
105
|
-
it do
|
106
|
-
expect('blabla'.commented?).to(be(true))
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe '#reset_comments' do
|
112
|
-
before do
|
113
|
-
'////'.commented?
|
114
|
-
end
|
115
|
-
|
116
|
-
it do
|
117
|
-
expect('whatever'.commented?).to(be(true))
|
118
|
-
end
|
119
|
-
|
120
|
-
it do
|
121
|
-
'////'.commented?
|
122
|
-
DefMastership.reset_comments
|
123
|
-
expect('whatever'.commented?).to(be(false))
|
124
|
-
end
|
6
|
+
RSpec.describe(String) do
|
7
|
+
context 'when .commented?' do
|
8
|
+
it { expect('blabla'.commented?).to(be(false)) }
|
9
|
+
it { expect('//blabla'.commented?).to(be(true)) }
|
10
|
+
it { expect('///blabla'.commented?).to(be(false)) }
|
125
11
|
end
|
126
12
|
end
|
@@ -17,6 +17,7 @@ RSpec.describe(DefMastership::ParsingState) do
|
|
17
17
|
it { expect(parsing_state.enabled?("whatever\n")).to(eq(true)) }
|
18
18
|
it { expect(parsing_state.enabled?("----\n")).to(eq(false)) }
|
19
19
|
it { expect(parsing_state.enabled?("....\n")).to(eq(false)) }
|
20
|
+
it { expect(parsing_state.enabled?("////\n")).to(eq(false)) }
|
20
21
|
it { expect(parsing_state.enabled?('....')).to(eq(false)) }
|
21
22
|
end
|
22
23
|
|
@@ -26,9 +27,10 @@ RSpec.describe(DefMastership::ParsingState) do
|
|
26
27
|
it { expect(parsing_state.enabled?("whatever\n")).to(eq(false)) }
|
27
28
|
it { expect(parsing_state.enabled?("----\n")).to(eq(true)) }
|
28
29
|
it { expect(parsing_state.enabled?("....\n")).to(eq(false)) }
|
30
|
+
it { expect(parsing_state.enabled?("////\n")).to(eq(false)) }
|
29
31
|
end
|
30
32
|
|
31
|
-
context 'with intricated disables
|
33
|
+
context 'with intricated disables starting with "...."' do
|
32
34
|
before do
|
33
35
|
["....\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
|
34
36
|
end
|
@@ -37,12 +39,20 @@ RSpec.describe(DefMastership::ParsingState) do
|
|
37
39
|
it { expect(parsing_state.enabled?("....\n")).to(eq(true)) }
|
38
40
|
end
|
39
41
|
|
40
|
-
context 'with intricated disables
|
42
|
+
context 'with intricated disables starting with "----"' do
|
41
43
|
before do
|
42
44
|
["....\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
|
43
45
|
end
|
44
46
|
|
45
47
|
it { expect(parsing_state.enabled?("....\n")).to(eq(true)) }
|
46
48
|
end
|
49
|
+
|
50
|
+
context 'with intricated disables starting with "////"' do
|
51
|
+
before do
|
52
|
+
["////\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
|
53
|
+
end
|
54
|
+
|
55
|
+
it { expect(parsing_state.enabled?("////\n")).to(eq(true)) }
|
56
|
+
end
|
47
57
|
end
|
48
58
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: defmastership
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jérôme Arbez-Gindre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aruba
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: rubocop
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '1.
|
75
|
+
version: '1.13'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '1.
|
82
|
+
version: '1.13'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rubocop-rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|