defmastership 1.0.11 → 1.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/defmastership.gemspec +1 -1
- data/features/export.feature +90 -0
- data/features/rename_included_files.feature +4 -0
- data/lib/defmastership.rb +1 -0
- data/lib/defmastership/change_ref_line_modifier.rb +4 -9
- data/lib/defmastership/comment_filter.rb +1 -34
- data/lib/defmastership/constants.rb +0 -5
- data/lib/defmastership/definition.rb +1 -1
- data/lib/defmastership/document.rb +16 -13
- data/lib/defmastership/filters.rb +0 -7
- data/lib/defmastership/parsing_state.rb +25 -0
- data/lib/defmastership/rename_included_files_line_modifier.rb +1 -1
- data/lib/defmastership/version.rb +1 -1
- data/spec/unit/defmastership/comment_filter_spec.rb +5 -119
- data/spec/unit/defmastership/document_spec.rb +43 -0
- data/spec/unit/defmastership/parsing_state_spec.rb +62 -0
- data/spec/unit/defmastership/rename_included_files_line_modifier_spec.rb +8 -8
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01a97f896ec1b0b88f80686290f5a0bf639ae7caeb4e4c48035e13221d3f21e2
|
4
|
+
data.tar.gz: 75d68f34285d4babe217a678204681399ef7aa11679810eb00a5eb95eb9771d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2926efd086db703c7a4e03b516c833a237ffa4d484492af6e70f3ae54bd4de30e50abe7cd15bdc8330b62ed46b6ddc04e474790a9e33b6260bc58ecde2113bc7
|
7
|
+
data.tar.gz: 5849049e21fc4882f957d09b0068769a26140327700caf88698595e2688f37b1467cc5b962d279d39c945ce6d187447d9ef6d90d1c26828bd7e841dfc08a30e2
|
data/.rubocop.yml
CHANGED
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
|
"""
|
@@ -291,3 +312,72 @@ Feature: The extract command
|
|
291
312
|
"""
|
292
313
|
And the stdout should not contain anything
|
293
314
|
And the stderr should not contain anything
|
315
|
+
|
316
|
+
Scenario: Extract one definition with example in it
|
317
|
+
Given a file named "toto.adoc" with:
|
318
|
+
"""
|
319
|
+
[define, requirement, TOTO-0001]
|
320
|
+
--
|
321
|
+
[example]
|
322
|
+
----
|
323
|
+
[define, requirement, TOTO-002]
|
324
|
+
not a real definition
|
325
|
+
----
|
326
|
+
--
|
327
|
+
"""
|
328
|
+
When I successfully run `defmastership export toto.adoc`
|
329
|
+
Then the file "toto.csv" should contain:
|
330
|
+
"""
|
331
|
+
Type,Reference,Value,Checksum
|
332
|
+
requirement,TOTO-0001,"[example]
|
333
|
+
----
|
334
|
+
[define, requirement, TOTO-002]
|
335
|
+
not a real definition
|
336
|
+
----",~8f20a443
|
337
|
+
"""
|
338
|
+
And the stdout should not contain anything
|
339
|
+
And the stderr should not contain anything
|
340
|
+
|
341
|
+
Scenario: Extract one definition with single line comment in it
|
342
|
+
Given a file named "toto.adoc" with:
|
343
|
+
"""
|
344
|
+
[define, requirement, TOTO-0001]
|
345
|
+
--
|
346
|
+
// comment
|
347
|
+
--
|
348
|
+
"""
|
349
|
+
When I successfully run `defmastership export toto.adoc`
|
350
|
+
Then the file "toto.csv" should contain:
|
351
|
+
"""
|
352
|
+
Type,Reference,Value,Checksum
|
353
|
+
requirement,TOTO-0001,// comment,~b0b506c3
|
354
|
+
"""
|
355
|
+
And the stdout should not contain anything
|
356
|
+
And the stderr should not contain anything
|
357
|
+
|
358
|
+
Scenario: Extract one definition with multi line comment or literal in it
|
359
|
+
Given a file named "toto.adoc" with:
|
360
|
+
"""
|
361
|
+
[define, requirement, TOTO-0001]
|
362
|
+
--
|
363
|
+
////
|
364
|
+
multiline comment
|
365
|
+
////
|
366
|
+
....
|
367
|
+
literal
|
368
|
+
....
|
369
|
+
--
|
370
|
+
"""
|
371
|
+
When I successfully run `defmastership export toto.adoc`
|
372
|
+
Then the file "toto.csv" should contain:
|
373
|
+
"""
|
374
|
+
Type,Reference,Value,Checksum
|
375
|
+
requirement,TOTO-0001,"////
|
376
|
+
multiline comment
|
377
|
+
////
|
378
|
+
....
|
379
|
+
literal
|
380
|
+
....",~7eb3c490
|
381
|
+
"""
|
382
|
+
And the stdout should not contain anything
|
383
|
+
And the stderr should not contain anything
|
@@ -73,7 +73,9 @@ Feature: The rename_included_files command
|
|
73
73
|
:any: one
|
74
74
|
:path: two
|
75
75
|
[define, requirement, TOTO-WHATEVER-123]
|
76
|
+
--
|
76
77
|
include::{any}_{path}/one_file.png[]
|
78
|
+
--
|
77
79
|
"""
|
78
80
|
And a directory named "one_two"
|
79
81
|
And an empty file named "one_two/one_file.png"
|
@@ -85,7 +87,9 @@ Feature: The rename_included_files command
|
|
85
87
|
:any: one
|
86
88
|
:path: two
|
87
89
|
[define, requirement, TOTO-WHATEVER-123]
|
90
|
+
--
|
88
91
|
include::{any}_{path}/TOTO-WHATEVER-123_one_file.png[]
|
92
|
+
--
|
89
93
|
"""
|
90
94
|
And the file "one_two/one_file.png" should not exist
|
91
95
|
And the file "one_two/TOTO-WHATEVER-123_one_file.png" should exist
|
data/lib/defmastership.rb
CHANGED
@@ -6,6 +6,7 @@ require('defmastership/version')
|
|
6
6
|
# Add requires for other files you add to your project here, so
|
7
7
|
# you just need to require this one file in your bin file
|
8
8
|
require('defmastership/constants')
|
9
|
+
require('defmastership/parsing_state')
|
9
10
|
require('defmastership/definition')
|
10
11
|
require('defmastership/definition_parser')
|
11
12
|
require('defmastership/filters')
|
@@ -28,7 +28,7 @@ module DefMastership
|
|
28
28
|
to_template: '',
|
29
29
|
next_ref: 0
|
30
30
|
}
|
31
|
-
@
|
31
|
+
@parsing_state = ParsingState.new
|
32
32
|
end
|
33
33
|
|
34
34
|
def replace(method, line)
|
@@ -36,10 +36,10 @@ module DefMastership
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def replace_refdef(line)
|
39
|
-
if
|
40
|
-
line
|
41
|
-
else
|
39
|
+
if @parsing_state.enabled?(line)
|
42
40
|
do_replace_refdef(line)
|
41
|
+
else
|
42
|
+
line
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -78,10 +78,5 @@ module DefMastership
|
|
78
78
|
def hmerge(match)
|
79
79
|
@config.merge(match.names.map(&:to_sym).zip(match.captures).to_h)
|
80
80
|
end
|
81
|
-
|
82
|
-
def in_literal(line)
|
83
|
-
@in_literal ^= true if line.chomp == '....'
|
84
|
-
@in_literal
|
85
|
-
end
|
86
81
|
end
|
87
82
|
end
|
@@ -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,19 +16,17 @@ 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
|
-
lines.
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
break if filter.consumed_line
|
25
|
+
lines.each do |line|
|
26
|
+
if @parsing_state.enabled?(line)
|
27
|
+
apply_filters(line)
|
28
|
+
else
|
29
|
+
generate_event(:new_line, nil, line)
|
32
30
|
end
|
33
31
|
end
|
34
32
|
end
|
@@ -49,11 +47,6 @@ module DefMastership
|
|
49
47
|
end
|
50
48
|
end
|
51
49
|
|
52
|
-
def code_block_delimiter(_match, line)
|
53
|
-
@in_literal ^= true
|
54
|
-
line
|
55
|
-
end
|
56
|
-
|
57
50
|
def add_new_definition(match, line)
|
58
51
|
definition = Definition.new(match)
|
59
52
|
@labels.merge(definition.labels)
|
@@ -116,6 +109,16 @@ module DefMastership
|
|
116
109
|
|
117
110
|
private
|
118
111
|
|
112
|
+
def apply_filters(line)
|
113
|
+
FILTERS.each do |filter|
|
114
|
+
next unless line.match(filter.regexp)
|
115
|
+
|
116
|
+
line = generate_event(filter.event, Regexp.last_match, line)
|
117
|
+
|
118
|
+
break if filter.consumed_line
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
119
122
|
def generate_event(event, match, line)
|
120
123
|
if respond_to?(event)
|
121
124
|
line = public_send(event, match, line)
|
@@ -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
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module DefMastership
|
5
|
+
# Allow to know if we need to parse the line or simply ignore it
|
6
|
+
class ParsingState
|
7
|
+
def initialize
|
8
|
+
@last_disabling_line = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def enabled?(line)
|
12
|
+
return false if line.match(DMRegexp::SINGLE_LINE_COMMENT)
|
13
|
+
|
14
|
+
line = line.dup.chomp
|
15
|
+
if ['....', '----', '////'].include?(line)
|
16
|
+
if @last_disabling_line == line
|
17
|
+
@last_disabling_line = nil
|
18
|
+
elsif @last_disabling_line.nil?
|
19
|
+
@last_disabling_line = line
|
20
|
+
end
|
21
|
+
end
|
22
|
+
@last_disabling_line.nil?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -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
|
@@ -115,6 +115,49 @@ RSpec.describe(DefMastership::Document) do
|
|
115
115
|
it { expect(definition).to(have_received(:<<).with('b')) }
|
116
116
|
end
|
117
117
|
|
118
|
+
context 'when complete definition with content including ----' do
|
119
|
+
let(:input_lines) do
|
120
|
+
[
|
121
|
+
'[define, requirement, TOTO-0001]',
|
122
|
+
'--',
|
123
|
+
'----',
|
124
|
+
'a',
|
125
|
+
'b',
|
126
|
+
'----',
|
127
|
+
'--',
|
128
|
+
'not included'
|
129
|
+
]
|
130
|
+
end
|
131
|
+
|
132
|
+
before do
|
133
|
+
allow(definition).to(receive(:<<).and_return(definition))
|
134
|
+
document.parse(input_lines)
|
135
|
+
end
|
136
|
+
|
137
|
+
it { expect(definition).to(have_received(:<<).twice.with('----')) }
|
138
|
+
it { expect(definition).to(have_received(:<<).with('a')) }
|
139
|
+
it { expect(definition).to(have_received(:<<).with('b')) }
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'when complete definition with single line comment' do
|
143
|
+
let(:input_lines) do
|
144
|
+
[
|
145
|
+
'[define, requirement, TOTO-0001]',
|
146
|
+
'--',
|
147
|
+
'// comment',
|
148
|
+
'--',
|
149
|
+
'not included'
|
150
|
+
]
|
151
|
+
end
|
152
|
+
|
153
|
+
before do
|
154
|
+
allow(definition).to(receive(:<<).and_return(definition))
|
155
|
+
document.parse(input_lines)
|
156
|
+
end
|
157
|
+
|
158
|
+
it { expect(definition).to(have_received(:<<).with('// comment')) }
|
159
|
+
end
|
160
|
+
|
118
161
|
context 'when definition with one paragraph' do
|
119
162
|
let(:input_lines) do
|
120
163
|
[
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require('defmastership')
|
5
|
+
|
6
|
+
RSpec.describe(DefMastership::ParsingState) do
|
7
|
+
subject(:parsing_state) do
|
8
|
+
described_class.new
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.new' do
|
12
|
+
it { is_expected.not_to(be(nil)) }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#enabled_with?' do
|
16
|
+
context 'when single line commment' do
|
17
|
+
it { expect(parsing_state.enabled?("//whatever\n")).to(eq(false)) }
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when starting' do
|
21
|
+
it { expect(parsing_state.enabled?("whatever\n")).to(eq(true)) }
|
22
|
+
it { expect(parsing_state.enabled?("----\n")).to(eq(false)) }
|
23
|
+
it { expect(parsing_state.enabled?("....\n")).to(eq(false)) }
|
24
|
+
it { expect(parsing_state.enabled?("////\n")).to(eq(false)) }
|
25
|
+
it { expect(parsing_state.enabled?('....')).to(eq(false)) }
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when disabled' do
|
29
|
+
before { parsing_state.enabled?("----\n") }
|
30
|
+
|
31
|
+
it { expect(parsing_state.enabled?("whatever\n")).to(eq(false)) }
|
32
|
+
it { expect(parsing_state.enabled?("----\n")).to(eq(true)) }
|
33
|
+
it { expect(parsing_state.enabled?("....\n")).to(eq(false)) }
|
34
|
+
it { expect(parsing_state.enabled?("////\n")).to(eq(false)) }
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'with intricated disables starting with "...."' do
|
38
|
+
before do
|
39
|
+
["....\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
|
40
|
+
end
|
41
|
+
|
42
|
+
it { expect(parsing_state.enabled?("----\n")).to(eq(false)) }
|
43
|
+
it { expect(parsing_state.enabled?("....\n")).to(eq(true)) }
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'with intricated disables starting with "----"' do
|
47
|
+
before do
|
48
|
+
["....\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
|
49
|
+
end
|
50
|
+
|
51
|
+
it { expect(parsing_state.enabled?("....\n")).to(eq(true)) }
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'with intricated disables starting with "////"' do
|
55
|
+
before do
|
56
|
+
["////\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
|
57
|
+
end
|
58
|
+
|
59
|
+
it { expect(parsing_state.enabled?("////\n")).to(eq(true)) }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -110,32 +110,32 @@ RSpec.describe(DefMastership::RenameIncludedFilesLineModifier) do
|
|
110
110
|
end
|
111
111
|
|
112
112
|
it do
|
113
|
-
expect(includeschanger.replace(
|
114
|
-
.to(eq(
|
113
|
+
expect(includeschanger.replace("include::orig[]\n"))
|
114
|
+
.to(eq("include::dest[]\n"))
|
115
115
|
end
|
116
116
|
|
117
117
|
it do
|
118
|
-
includeschanger.replace(
|
118
|
+
includeschanger.replace("include::orig[]\n")
|
119
119
|
expect(File).to(have_received(:rename).with('orig', 'dest'))
|
120
120
|
end
|
121
121
|
|
122
122
|
it do
|
123
|
-
includeschanger.replace(
|
123
|
+
includeschanger.replace("include::orig[]\n")
|
124
124
|
expect(includeschanger).to(have_attributes(changes: [%w[orig dest]]))
|
125
125
|
end
|
126
126
|
|
127
127
|
it do
|
128
|
-
expect(includeschanger.replace(
|
129
|
-
.to(eq(
|
128
|
+
expect(includeschanger.replace("include::toto/orig[]\n"))
|
129
|
+
.to(eq("include::toto/dest[]\n"))
|
130
130
|
end
|
131
131
|
|
132
132
|
it do
|
133
|
-
includeschanger.replace(
|
133
|
+
includeschanger.replace("include::toto/orig[]\n")
|
134
134
|
expect(File).to(have_received(:rename).with('toto/orig', 'toto/dest'))
|
135
135
|
end
|
136
136
|
|
137
137
|
it do
|
138
|
-
includeschanger.replace(
|
138
|
+
includeschanger.replace("include::toto/orig[]\n")
|
139
139
|
expect(includeschanger).to(have_attributes(changes: [%w[toto/orig toto/dest]]))
|
140
140
|
end
|
141
141
|
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.16
|
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-
|
11
|
+
date: 2021-05-07 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
|
@@ -216,6 +216,7 @@ files:
|
|
216
216
|
- lib/defmastership/filters.rb
|
217
217
|
- lib/defmastership/line_modifier_base.rb
|
218
218
|
- lib/defmastership/modifier_base.rb
|
219
|
+
- lib/defmastership/parsing_state.rb
|
219
220
|
- lib/defmastership/rename_included_files_line_modifier.rb
|
220
221
|
- lib/defmastership/rename_included_files_modifier.rb
|
221
222
|
- lib/defmastership/update_def_checksum_line_modifier.rb
|
@@ -234,6 +235,7 @@ files:
|
|
234
235
|
- spec/unit/defmastership/definition_parser_spec.rb
|
235
236
|
- spec/unit/defmastership/definition_spec.rb
|
236
237
|
- spec/unit/defmastership/document_spec.rb
|
238
|
+
- spec/unit/defmastership/parsing_state_spec.rb
|
237
239
|
- spec/unit/defmastership/rename_included_files_line_modifier_spec.rb
|
238
240
|
- spec/unit/defmastership/rename_included_files_modifier_spec.rb
|
239
241
|
- spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb
|