defmastership 1.0.9 → 1.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9dd61d32bacab380bbfc110df15fd6617b38540aa5bc8eb14bd5b2736e657b7c
4
- data.tar.gz: 1ec7bc921411173863b71ba0c3f4164829ac2efbe0689c321830f632a3333f64
3
+ metadata.gz: 942362543576801349518b2d73e49abb5cfb076b246df05a7e28fe86814b506e
4
+ data.tar.gz: 1a351eadc8b3583df8f31b590225a4b8e5207d7db089b3a62ac644f03fa02c08
5
5
  SHA512:
6
- metadata.gz: e8dcebcb309fd755a339ab702f7c07c65387e5a961400518661d70e9421911630652855a10ad647ac6155b9686665927fde8315a8efb71e3a2913a8db32fbcd5
7
- data.tar.gz: 83e28e54b372de48cc554b8f532e659817453e905f3c6634071b3e280f23fba2431119353af9bdd6b23b97a6d6bf8a2b9a261b39e70591f27be45a3b04dce19b
6
+ metadata.gz: 6151951967b1d4b0e2108b2b11f101045780d6ec3f8ba4505078dbb1c240f2795bd56cce0f177187c58b2d8dacd3d63c1cfce6ca8969cb5f54d972d32d61e42b
7
+ data.tar.gz: 6836a23ffae998a9a1b54716941b0e9bb661e81f18a4422ad984af1ee41218b685ba937c108298f8a02cf348af434ddd1138f81c5644017193c5d72d6ad2cbdd
data/.rubocop.yml CHANGED
@@ -62,3 +62,7 @@ RSpec/FilePath :
62
62
 
63
63
  RSpec/NestedGroups:
64
64
  Max: 4
65
+
66
+ Layout/RedundantLineBreak:
67
+ Enabled: false
68
+
@@ -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', '~> 1.3')
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')
@@ -36,6 +36,39 @@ Feature: The changeref command
36
36
  [define, requirement, TOTO-0123]
37
37
  """
38
38
 
39
+ Scenario: Change a definition with explicit checksum and version
40
+ Given a file named "modifications.yml" with:
41
+ """
42
+ ---
43
+ :toto:
44
+ :type: change_ref
45
+ :config:
46
+ :from_regexp: TOTO-TEMP-[X\d]{4}
47
+ :to_template: TOTO-%<next_ref>04d
48
+ :next_ref: 123
49
+ """
50
+ And a file named "thedoc.adoc" with:
51
+ """
52
+ [define, requirement, TOTO-TEMP-XXX1(a~12345678)]
53
+ """
54
+ When I successfully run `defmastership modify --modifications toto thedoc.adoc`
55
+ Then the stdout should not contain anything
56
+ And the stderr should not contain anything
57
+ And the file "modifications.yml" should contain:
58
+ """
59
+ ---
60
+ :toto:
61
+ :type: change_ref
62
+ :config:
63
+ :from_regexp: TOTO-TEMP-[X\d]{4}
64
+ :to_template: TOTO-%<next_ref>04d
65
+ :next_ref: 124
66
+ """
67
+ And the file "thedoc.adoc" should contain:
68
+ """
69
+ [define, requirement, TOTO-0123(a~12345678)]
70
+ """
71
+
39
72
  Scenario: Change two definitions
40
73
  Given a file named "modifications.yml" with:
41
74
  """
@@ -22,3 +22,183 @@ Feature: definitions version
22
22
  And the stdout should not contain anything
23
23
  And the stderr should not contain anything
24
24
 
25
+ Scenario: Set initial explicit version when definition has changed
26
+ Given a file named "ref_doc.adoc" with:
27
+ """
28
+ [define, requirement, TOTO-0001]
29
+ --
30
+ initial text.
31
+ --
32
+ """
33
+ Given a file named "thedoc.adoc" with:
34
+ """
35
+ [define, requirement, TOTO-0001(whatever)]
36
+ --
37
+ modified text.
38
+ --
39
+ """
40
+ And a file named "modifications.yml" with:
41
+ """
42
+ ---
43
+ :update_requirement_version:
44
+ :type: update_def_version
45
+ :config:
46
+ :def_type: requirement
47
+ :first_version: a
48
+ :ref_document: ./ref_doc.adoc
49
+ """
50
+ When I successfully run `defmastership modify --modifications update_requirement_version thedoc.adoc`
51
+ And the stdout should not contain anything
52
+ And the stderr should not contain anything
53
+ Then the file "thedoc.adoc" should contain:
54
+ """
55
+ [define, requirement, TOTO-0001(a)]
56
+ --
57
+ modified text.
58
+ --
59
+ """
60
+
61
+ Scenario: Do not set initial explicit version when definition has NOT changed
62
+ Given a file named "ref_doc.adoc" with:
63
+ """
64
+ [define, requirement, TOTO-0001]
65
+ --
66
+ initial text.
67
+ --
68
+ """
69
+ Given a file named "thedoc.adoc" with:
70
+ """
71
+ [define, requirement, TOTO-0001(whatever)]
72
+ --
73
+ initial text.
74
+ --
75
+ """
76
+ And a file named "modifications.yml" with:
77
+ """
78
+ ---
79
+ :update_requirement_version:
80
+ :type: update_def_version
81
+ :config:
82
+ :def_type: requirement
83
+ :first_version: a
84
+ :ref_document: ./ref_doc.adoc
85
+ """
86
+ When I successfully run `defmastership modify --modifications update_requirement_version thedoc.adoc`
87
+ And the stdout should not contain anything
88
+ And the stderr should not contain anything
89
+ Then the file "thedoc.adoc" should contain:
90
+ """
91
+ [define, requirement, TOTO-0001]
92
+ --
93
+ initial text.
94
+ --
95
+ """
96
+
97
+ Scenario: Set initial explicit version when definition has changed and ref is not an initial version
98
+ Given a file named "ref_doc.adoc" with:
99
+ """
100
+ [define, requirement, TOTO-0001(3)]
101
+ --
102
+ initial text.
103
+ --
104
+ """
105
+ Given a file named "thedoc.adoc" with:
106
+ """
107
+ [define, requirement, TOTO-0001(whatever)]
108
+ --
109
+ modified text.
110
+ --
111
+ """
112
+ And a file named "modifications.yml" with:
113
+ """
114
+ ---
115
+ :update_requirement_version:
116
+ :type: update_def_version
117
+ :config:
118
+ :def_type: requirement
119
+ :first_version: 1
120
+ :ref_document: ./ref_doc.adoc
121
+ """
122
+ When I successfully run `defmastership modify --modifications update_requirement_version thedoc.adoc`
123
+ And the stdout should not contain anything
124
+ And the stderr should not contain anything
125
+ Then the file "thedoc.adoc" should contain:
126
+ """
127
+ [define, requirement, TOTO-0001(4)]
128
+ --
129
+ modified text.
130
+ --
131
+ """
132
+
133
+ Scenario: No initial explicit version when definition is new
134
+ Given a file named "ref_doc.adoc" with:
135
+ """
136
+ [define, requirement, TOTO-0002]
137
+ --
138
+ initial text.
139
+ --
140
+ """
141
+ Given a file named "thedoc.adoc" with:
142
+ """
143
+ [define, requirement, TOTO-0001(whatever)]
144
+ --
145
+ modified text.
146
+ --
147
+ """
148
+ And a file named "modifications.yml" with:
149
+ """
150
+ ---
151
+ :update_requirement_version:
152
+ :type: update_def_version
153
+ :config:
154
+ :def_type: requirement
155
+ :first_version: 1
156
+ :ref_document: ./ref_doc.adoc
157
+ """
158
+ When I successfully run `defmastership modify --modifications update_requirement_version thedoc.adoc`
159
+ And the stdout should not contain anything
160
+ And the stderr should not contain anything
161
+ Then the file "thedoc.adoc" should contain:
162
+ """
163
+ [define, requirement, TOTO-0001]
164
+ --
165
+ modified text.
166
+ --
167
+ """
168
+
169
+ Scenario: update explicit version whith explicit checksum
170
+ Given a file named "ref_doc.adoc" with:
171
+ """
172
+ [define, requirement, TOTO-0001]
173
+ --
174
+ initial text.
175
+ --
176
+ """
177
+ Given a file named "thedoc.adoc" with:
178
+ """
179
+ [define, requirement, TOTO-0001(whatever~abcd1234)]
180
+ --
181
+ modified text.
182
+ --
183
+ """
184
+ And a file named "modifications.yml" with:
185
+ """
186
+ ---
187
+ :update_requirement_version:
188
+ :type: update_def_version
189
+ :config:
190
+ :def_type: requirement
191
+ :first_version: a
192
+ :ref_document: ./ref_doc.adoc
193
+ """
194
+ When I successfully run `defmastership modify --modifications update_requirement_version thedoc.adoc`
195
+ And the stdout should not contain anything
196
+ And the stderr should not contain anything
197
+ Then the file "thedoc.adoc" should contain:
198
+ """
199
+ [define, requirement, TOTO-0001(a~abcd1234)]
200
+ --
201
+ modified text.
202
+ --
203
+ """
204
+
@@ -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
  """
@@ -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')
@@ -25,3 +26,6 @@ require('defmastership/rename_included_files_line_modifier')
25
26
 
26
27
  require('defmastership/update_def_checksum_modifier')
27
28
  require('defmastership/update_def_checksum_line_modifier')
29
+
30
+ require('defmastership/update_def_version_modifier')
31
+ require('defmastership/update_def_version_line_modifier')
@@ -28,7 +28,7 @@ module DefMastership
28
28
  to_template: '',
29
29
  next_ref: 0
30
30
  }
31
- @in_literal = false
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 in_literal(line)
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
 
@@ -66,21 +66,17 @@ module DefMastership
66
66
  regexp_str =
67
67
  "(?<before>#{REGEXP_FROM[const][:before]})" \
68
68
  "(?<from>#{from})" \
69
+ "#{DMRegexp::DEF_VERSION_AND_CHECKSUM}" \
69
70
  "(?<after>#{REGEXP_FROM[const][:after]})"
70
71
  Regexp.new(regexp_str, Regexp::EXTENDED)
71
72
  end
72
73
 
73
74
  def text_with(match, replacement)
74
- match[:before] + replacement + match[:after]
75
+ match[:before] + replacement + (match[:version_and_checksum] || '') + match[:after]
75
76
  end
76
77
 
77
78
  def hmerge(match)
78
79
  @config.merge(match.names.map(&:to_sym).zip(match.captures).to_h)
79
80
  end
80
-
81
- def in_literal(line)
82
- @in_literal ^= true if line.chomp == '....'
83
- @in_literal
84
- end
85
81
  end
86
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.comment_filter.accept?(self)
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*,
@@ -20,7 +18,9 @@ module DefMastership
20
18
  (,\s*\[\s*(?<labels>.*?)\s*\])?\s*\]
21
19
  AFT
22
20
 
23
- DEF_VERSION_AND_CHECKSUM = '(\((?<explicit_version>[^~]+)?(?<explicit_checksum>~[[:alnum:]]+)?\))?'
21
+ DEF_VERSION_AND_CHECKSUM = '(?<version_and_checksum>' \
22
+ '\((?<explicit_version>[^~]+)?(?<explicit_checksum>~[[:alnum:]]+)?\)' \
23
+ ')?'
24
24
 
25
25
  DEFINITION = Regexp.new(
26
26
  "#{DEF_BEFORE_REF}(?<reference>[\\w:_-]+)#{DEF_VERSION_AND_CHECKSUM}#{DEF_AFTER_REF}",
@@ -39,7 +39,6 @@ module DefMastership
39
39
  \s*(?<refname>[\w:_-]+)\s*,
40
40
  \s*\[(?<extrefs>[^\]]+)\]\s*\]/x.freeze
41
41
  BLOCK = /^--\s*$/.freeze
42
- LITERAL_BLOCK = /^\.\.\.\.\s*$/.freeze
43
42
 
44
43
  IREF_DEF_BEF = 'defs:iref\[\s*'
45
44
  IREF_DEF_AFT = '\s*\]'
@@ -70,7 +69,6 @@ module DefMastership
70
69
  )
71
70
 
72
71
  public_constant :SINGLE_LINE_COMMENT,
73
- :MULTI_LINE_COMMENT_DELIM,
74
72
  :DEF_BEFORE_REF,
75
73
  :DEF_AFTER_REF,
76
74
  :DEFINITION,
@@ -79,7 +77,6 @@ module DefMastership
79
77
  :EREF_CONFIG,
80
78
  :EREF_DEF,
81
79
  :BLOCK,
82
- :LITERAL_BLOCK,
83
80
  :IREF_DEF_BEF,
84
81
  :IREF_DEF_AFT,
85
82
  :IREF_DEF,
@@ -31,7 +31,7 @@ module DefMastership
31
31
  end
32
32
 
33
33
  def sha256
34
- "~#{Digest::SHA2.new(256).hexdigest(value).split(//).last(8).join}"
34
+ "~#{Digest::SHA2.new(256).hexdigest(value).chars.last(8).join}"
35
35
  end
36
36
 
37
37
  def wrong_explicit_checksum
@@ -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
- (@in_literal ? FILTERS : FILTERS_IN_LITERAL).each do |filter|
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
@@ -0,0 +1,23 @@
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
+ line = line.dup.chomp
13
+ if ['....', '----', '////'].include?(line)
14
+ if @last_disabling_line == line
15
+ @last_disabling_line = nil
16
+ elsif @last_disabling_line.nil?
17
+ @last_disabling_line = line
18
+ end
19
+ end
20
+ @last_disabling_line.nil?
21
+ end
22
+ end
23
+ end
@@ -96,7 +96,7 @@ module DefMastership
96
96
 
97
97
  filename.gsub!("{#{varname}}", @variables[varname.to_sym])
98
98
  end
99
- filename
99
+ filename.chomp
100
100
  end
101
101
 
102
102
  def complete_regexp_from(from)
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module DefMastership
5
- # Update definition checksum wih calculated one
5
+ # Update definition checksum with calculated one
6
6
  class UpdateDefChecksumModifier < ModifierBase
7
7
  def replacements
8
8
  %i[replace]
@@ -0,0 +1,58 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ module DefMastership
5
+ # modify one line after another
6
+ class UpdateDefVersionLineModifier < LineModifierBase
7
+ attr_accessor :document, :ref_document
8
+
9
+ def self.from_config(hash)
10
+ new.from_config(hash)
11
+ end
12
+
13
+ def initialize
14
+ super
15
+ @config = {
16
+ def_type: '',
17
+ ref_document: '',
18
+ first_version: ''
19
+ }
20
+ end
21
+
22
+ def replace(line)
23
+ match = matched?(line)
24
+
25
+ return line unless match
26
+ return line unless match[:type] == def_type
27
+
28
+ version_and_checksum = ''
29
+ if match[:explicit_checksum] || version_string(match)
30
+ version_and_checksum = "(#{version_string(match)}#{match[:explicit_checksum]})"
31
+ end
32
+
33
+ line.gsub(Regexp.new("#{match[:reference]}#{DMRegexp::DEF_VERSION_AND_CHECKSUM}")) do
34
+ "#{match[:reference]}#{version_and_checksum}"
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def matched?(line)
41
+ return if line.commented?
42
+ return unless line =~ DMRegexp::DEFINITION
43
+
44
+ Regexp.last_match
45
+ end
46
+
47
+ def version_string(match)
48
+ ref_definition = @ref_document.ref_to_def(match[:reference])
49
+ definition = @document.ref_to_def(match[:reference])
50
+
51
+ return if ref_definition.nil?
52
+ return ref_definition.explicit_version if definition.sha256 == ref_definition.sha256
53
+
54
+ ref_version = @ref_document.ref_to_def(match[:reference]).explicit_version
55
+ ref_version.nil? ? @config[:first_version] : ref_version.next
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,25 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ module DefMastership
5
+ # Update definition version if the definition has change since
6
+ # reference document
7
+ class UpdateDefVersionModifier < ModifierBase
8
+ def replacements
9
+ %i[replace]
10
+ end
11
+
12
+ def new_line_modifier(config, adoc_texts)
13
+ document = Document.new
14
+ adoc_texts.each do |adoc_file, _|
15
+ document.parse_file_with_preprocessor(adoc_file)
16
+ end
17
+ ref_document = Document.new
18
+ ref_document.parse_file_with_preprocessor(config[:ref_document])
19
+ line_modifier = UpdateDefVersionLineModifier.from_config(config)
20
+ line_modifier.document = document
21
+ line_modifier.ref_document = ref_document
22
+ line_modifier
23
+ end
24
+ end
25
+ end
@@ -2,6 +2,6 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module DefMastership
5
- VERSION = '1.0.9'
5
+ VERSION = '1.0.14'
6
6
  public_constant :VERSION
7
7
  end
@@ -217,6 +217,21 @@ RSpec.describe(DefMastership::ChangeRefLineModifier) do
217
217
  .to(eq('[define, whatever, TUTU]'))
218
218
  end
219
219
 
220
+ it do
221
+ expect(refchanger.replace(:refdef, '[define, whatever, TEMP(a~12345678)]'))
222
+ .to(eq('[define, whatever, TUTU(a~12345678)]'))
223
+ end
224
+
225
+ it do
226
+ expect(refchanger.replace(:refdef, '[define, whatever, TEMP(~12345678)]'))
227
+ .to(eq('[define, whatever, TUTU(~12345678)]'))
228
+ end
229
+
230
+ it do
231
+ expect(refchanger.replace(:refdef, '[define, whatever, TEMP(a)]'))
232
+ .to(eq('[define, whatever, TUTU(a)]'))
233
+ end
234
+
220
235
  it do
221
236
  refchanger.replace(:refdef, '[define, whatever, TEMP]')
222
237
  expect(refchanger.replace(:irefs, 'defs:iref[TEMP]'))
@@ -3,124 +3,10 @@
3
3
 
4
4
  require('defmastership')
5
5
 
6
- RSpec.describe(DefMastership::CommentFilter) do
7
- describe '.new' do
8
- it { is_expected.not_to(be(nil)) }
9
- end
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
@@ -0,0 +1,58 @@
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 starting' do
17
+ it { expect(parsing_state.enabled?("whatever\n")).to(eq(true)) }
18
+ it { expect(parsing_state.enabled?("----\n")).to(eq(false)) }
19
+ it { expect(parsing_state.enabled?("....\n")).to(eq(false)) }
20
+ it { expect(parsing_state.enabled?("////\n")).to(eq(false)) }
21
+ it { expect(parsing_state.enabled?('....')).to(eq(false)) }
22
+ end
23
+
24
+ context 'when disabled' do
25
+ before { parsing_state.enabled?("----\n") }
26
+
27
+ it { expect(parsing_state.enabled?("whatever\n")).to(eq(false)) }
28
+ it { expect(parsing_state.enabled?("----\n")).to(eq(true)) }
29
+ it { expect(parsing_state.enabled?("....\n")).to(eq(false)) }
30
+ it { expect(parsing_state.enabled?("////\n")).to(eq(false)) }
31
+ end
32
+
33
+ context 'with intricated disables starting with "...."' do
34
+ before do
35
+ ["....\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
36
+ end
37
+
38
+ it { expect(parsing_state.enabled?("----\n")).to(eq(false)) }
39
+ it { expect(parsing_state.enabled?("....\n")).to(eq(true)) }
40
+ end
41
+
42
+ context 'with intricated disables starting with "----"' do
43
+ before do
44
+ ["....\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
45
+ end
46
+
47
+ it { expect(parsing_state.enabled?("....\n")).to(eq(true)) }
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
57
+ end
58
+ end
@@ -110,32 +110,32 @@ RSpec.describe(DefMastership::RenameIncludedFilesLineModifier) do
110
110
  end
111
111
 
112
112
  it do
113
- expect(includeschanger.replace('include::orig[]'))
114
- .to(eq('include::dest[]'))
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('include::orig[]')
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('include::orig[]')
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('include::toto/orig[]'))
129
- .to(eq('include::toto/dest[]'))
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('include::toto/orig[]')
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('include::toto/orig[]')
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
@@ -0,0 +1,127 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('defmastership')
5
+
6
+ RSpec.describe(DefMastership::UpdateDefVersionLineModifier) do
7
+ subject(:linemodifier) { described_class.new }
8
+
9
+ describe '.new' do
10
+ it { is_expected.not_to(be(nil)) }
11
+ it { is_expected.to(have_attributes(def_type: '')) }
12
+ it { is_expected.to(have_attributes(changes: [])) }
13
+ it { expect { linemodifier.user_defined_attribute }.to(raise_error(NoMethodError)) }
14
+ end
15
+
16
+ describe '.from_config' do
17
+ subject(:linemodifier) do
18
+ described_class.from_config(
19
+ def_type: 'requirement',
20
+ first_version: 'a'
21
+ )
22
+ end
23
+
24
+ it { is_expected.not_to(be(nil)) }
25
+ it { is_expected.to(have_attributes(def_type: 'requirement')) }
26
+ it { is_expected.to(have_attributes(first_version: 'a')) }
27
+ it { is_expected.to(have_attributes(document: nil)) }
28
+ it { is_expected.to(have_attributes(ref_document: nil)) }
29
+ end
30
+
31
+ describe '#replace' do
32
+ subject(:linemodifier) do
33
+ described_class.from_config(
34
+ def_type: 'requirement',
35
+ first_version: 'a'
36
+ )
37
+ end
38
+
39
+ let(:document) { instance_double(DefMastership::Document, 'document') }
40
+ let(:ref_document) { instance_double(DefMastership::Document, 'ref_document') }
41
+ let(:definition) { instance_double(DefMastership::Definition, 'definition') }
42
+ let(:ref_definition) { instance_double(DefMastership::Definition, 'ref_definitions') }
43
+
44
+ before do
45
+ linemodifier.document = document
46
+ linemodifier.ref_document = ref_document
47
+ allow(File).to(receive(:rename))
48
+ end
49
+
50
+ context 'when definition has not the good type' do
51
+ it do
52
+ expect(linemodifier.replace('[define,req,REFERENCE]'))
53
+ .to(eq('[define,req,REFERENCE]'))
54
+ end
55
+ end
56
+
57
+ context 'when definition has the good type' do
58
+ before do
59
+ allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
60
+ allow(definition).to(receive(:sha256).and_return('~abcd1234'))
61
+ end
62
+
63
+ context 'when definition has NOT changed' do
64
+ before do
65
+ allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(ref_definition))
66
+ allow(ref_definition).to(receive(:sha256).and_return('~abcd1234'))
67
+ end
68
+
69
+ it do
70
+ allow(ref_definition).to(receive(:explicit_version).and_return(nil))
71
+ expect(linemodifier.replace('[define,requirement,REFERENCE]'))
72
+ .to(eq('[define,requirement,REFERENCE]'))
73
+ end
74
+
75
+ it do
76
+ allow(ref_definition).to(receive(:explicit_version).and_return('c'))
77
+ expect(linemodifier.replace('[define,requirement,REFERENCE]'))
78
+ .to(eq('[define,requirement,REFERENCE(c)]'))
79
+ end
80
+
81
+ it do
82
+ allow(ref_definition).to(receive(:explicit_version).and_return('c'))
83
+ expect(linemodifier.replace('[define,requirement,REFERENCE(tyty~1234)]'))
84
+ .to(eq('[define,requirement,REFERENCE(c~1234)]'))
85
+ end
86
+ end
87
+
88
+ context 'when definition has changed' do
89
+ before do
90
+ allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(ref_definition))
91
+ allow(ref_definition).to(receive(:sha256).and_return('~4321aaaa'))
92
+ end
93
+
94
+ [
95
+ [nil, '', '(a)'],
96
+ ['c', '', '(d)'],
97
+ ['c', '(tyty~1234)', '(d~1234)'],
98
+ ['2', '', '(3)'],
99
+ ['1222', '', '(1223)'],
100
+ ['abb', '', '(abc)']
101
+ ].each do |ref, from, to|
102
+ it do
103
+ allow(ref_definition).to(receive(:explicit_version).and_return(ref))
104
+ expect(linemodifier.replace("[define,requirement,REFERENCE#{from}]"))
105
+ .to(eq("[define,requirement,REFERENCE#{to}]"))
106
+ end
107
+ end
108
+ end
109
+
110
+ context 'when definition is new' do
111
+ before do
112
+ allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(nil))
113
+ end
114
+
115
+ it do
116
+ expect(linemodifier.replace('[define,requirement,REFERENCE(whatever)]'))
117
+ .to(eq('[define,requirement,REFERENCE]'))
118
+ end
119
+
120
+ it do
121
+ expect(linemodifier.replace('[define,requirement,REFERENCE(~1234)]'))
122
+ .to(eq('[define,requirement,REFERENCE(~1234)]'))
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,80 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('defmastership')
5
+
6
+ RSpec.describe(DefMastership::UpdateDefVersionModifier) do
7
+ subject(:modifier) do
8
+ described_class.new(
9
+ ref_document: 'ref.adoc'
10
+ )
11
+ end
12
+
13
+ let(:adoc_texts) do
14
+ {
15
+ 'file1.adoc' => "file1 line1\nfile1 line2",
16
+ 'file2.adoc' => "file2 line1\nfile2 line2"
17
+ }
18
+ end
19
+
20
+ describe '.new' do
21
+ it { is_expected.not_to(be(nil)) }
22
+ it { is_expected.to(have_attributes(config: { ref_document: 'ref.adoc' })) }
23
+ it { is_expected.to(have_attributes(changes: [])) }
24
+ end
25
+
26
+ describe '#do_modifications' do
27
+ let(:line_modifier) { instance_double(DefMastership::UpdateDefVersionLineModifier, 'lineModifier') }
28
+ let(:document) { instance_double(DefMastership::Document, 'document') }
29
+ let(:ref_document) { instance_double(DefMastership::Document, 'ref_document') }
30
+
31
+ before do
32
+ allow(DefMastership::UpdateDefVersionLineModifier).to(
33
+ receive(:from_config).with(ref_document: 'ref.adoc').and_return(line_modifier)
34
+ )
35
+ allow(DefMastership::Document).to(receive(:new).and_return(document, ref_document))
36
+ allow(document).to(receive(:parse_file_with_preprocessor))
37
+ allow(ref_document).to(receive(:parse_file_with_preprocessor))
38
+ allow(line_modifier).to(receive(:'document=').with(document))
39
+ allow(line_modifier).to(receive(:'ref_document=').with(ref_document))
40
+ allow(line_modifier).to(receive(:replace).with("file1 line1\n").and_return("new file1 line1\n"))
41
+ allow(line_modifier).to(receive(:replace).with('file1 line2').and_return('new file1 line2'))
42
+ allow(line_modifier).to(receive(:replace).with("file2 line1\n").and_return("new file2 line1\n"))
43
+ allow(line_modifier).to(receive(:replace).with('file2 line2').and_return('new file2 line2'))
44
+ allow(line_modifier).to(receive(:config).and_return(ref_document: 'ref.adoc'))
45
+ allow(line_modifier).to(receive(:changes).and_return([%w[from1 to1], %w[from2 to2]]))
46
+ end
47
+
48
+ context 'when detailed expectations' do
49
+ before { modifier.do_modifications(adoc_texts) }
50
+
51
+ it do
52
+ expect(DefMastership::UpdateDefVersionLineModifier).to(
53
+ have_received(:from_config).with(ref_document: 'ref.adoc')
54
+ )
55
+ end
56
+
57
+ it { expect(document).to(have_received(:parse_file_with_preprocessor).with('file1.adoc')) }
58
+ it { expect(document).to(have_received(:parse_file_with_preprocessor).with('file2.adoc')) }
59
+ it { expect(ref_document).to(have_received(:parse_file_with_preprocessor).with('ref.adoc')) }
60
+ it { expect(line_modifier).to(have_received(:'document=').with(document)) }
61
+ it { expect(line_modifier).to(have_received(:'ref_document=').with(ref_document)) }
62
+ it { expect(line_modifier).to(have_received(:replace).with("file1 line1\n")) }
63
+ it { expect(line_modifier).to(have_received(:replace).with('file1 line2')) }
64
+ it { expect(line_modifier).to(have_received(:replace).with("file2 line1\n")) }
65
+ it { expect(line_modifier).to(have_received(:replace).with('file2 line2')) }
66
+ it { expect(line_modifier).to(have_received(:config)) }
67
+ it { expect(line_modifier).to(have_received(:changes)) }
68
+ it { is_expected.to(have_attributes(config: { ref_document: 'ref.adoc' })) }
69
+ it { is_expected.to(have_attributes(changes: [%w[from1 to1], %w[from2 to2]])) }
70
+ end
71
+
72
+ it do
73
+ expected_adoc = {
74
+ 'file1.adoc' => "new file1 line1\nnew file1 line2",
75
+ 'file2.adoc' => "new file2 line1\nnew file2 line2"
76
+ }
77
+ expect(modifier.do_modifications(adoc_texts)).to(eq(expected_adoc))
78
+ end
79
+ end
80
+ 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.9
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-03-24 00:00:00.000000000 Z
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.3'
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.3'
82
+ version: '1.13'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rubocop-rake
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -216,10 +216,13 @@ 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
222
223
  - lib/defmastership/update_def_checksum_modifier.rb
224
+ - lib/defmastership/update_def_version_line_modifier.rb
225
+ - lib/defmastership/update_def_version_modifier.rb
223
226
  - lib/defmastership/version.rb
224
227
  - spec/spec_helper.rb
225
228
  - spec/unit/defmastership/batch_modifier_spec.rb
@@ -232,10 +235,13 @@ files:
232
235
  - spec/unit/defmastership/definition_parser_spec.rb
233
236
  - spec/unit/defmastership/definition_spec.rb
234
237
  - spec/unit/defmastership/document_spec.rb
238
+ - spec/unit/defmastership/parsing_state_spec.rb
235
239
  - spec/unit/defmastership/rename_included_files_line_modifier_spec.rb
236
240
  - spec/unit/defmastership/rename_included_files_modifier_spec.rb
237
241
  - spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb
238
242
  - spec/unit/defmastership/update_def_checksum_modifier_spec.rb
243
+ - spec/unit/defmastership/update_def_version_line_modifier_spec.rb
244
+ - spec/unit/defmastership/update_def_version_modifier_spec.rb
239
245
  - spec/unit/defmastership_spec.rb
240
246
  homepage: https://gitlab.com/jjag/defmastership/
241
247
  licenses: