defmastership 1.0.8 → 1.0.13

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: c6fbf5098c8ab70e422d9c158c0a28cd876de25cfd159a131b0ddefc5f1eca86
4
- data.tar.gz: 8717156666df342a45994bb455b0cc58f09fc1da9b31c48cd0d4b36a40c528b6
3
+ metadata.gz: 9e81c3ab45ea06b43ad767d8ab89231e05eacca67dee259a8d968d515da6adb6
4
+ data.tar.gz: bb2abcc00dea06b45b35373eec37923236770310cd70842770be8d1ac92149e7
5
5
  SHA512:
6
- metadata.gz: 6afcfd48186a2f89426e62007dc068711ea36e26a8ecf9b9c56428a351eabb6a89be58872a96de30c9a87ccdc71366e685fd8486469a3465e661ae490c0925be
7
- data.tar.gz: 275587475f39f39bbd311cdf9a0fb1cc9cdcb30c6cf766b44d9b1ff64ac9a8feb2c9117f4903f8eb806b3e73594b6c2e5e63876038483429cabd7eb66fb93575
6
+ metadata.gz: 3df9a3fd838a4600b66690fd30fedcbf28b8e3af6d2afbe8d1ef813ea8b3b163b854f16ff3f219550a24b9624302ea0d32b8a043f90047070425d39e1b017cc4
7
+ data.tar.gz: 5b2b9c5105d548c2cba1571ad36830453bec01664d7ab4edec71a1132b30bb0651dd4d5a197f1d4c13a2a09d0ea9e69b2b0f3af975f0611de32b1cd52737c92d
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
+
@@ -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
  """
@@ -242,3 +242,57 @@ Feature: definition checksum
242
242
  """
243
243
  And the stdout should not contain anything
244
244
  And the stderr should not contain anything
245
+
246
+ Scenario: Checksum keep explicit version in ref modification
247
+ Given a file named "modifications.yml" with:
248
+ """
249
+ ---
250
+ :update_requirement_checksum:
251
+ :type: update_def_checksum
252
+ :config:
253
+ :def_type: requirement
254
+ """
255
+ And a file named "thedoc.adoc" with:
256
+ """
257
+ [define, requirement, TOTO-TEMP-XXX1(toto~abcd1234)]
258
+ --
259
+ the requirement value.
260
+ --
261
+ """
262
+ When I successfully run `defmastership modify --modifications update_requirement_checksum thedoc.adoc`
263
+ Then the stdout should not contain anything
264
+ And the stderr should not contain anything
265
+ And the file "thedoc.adoc" should contain:
266
+ """
267
+ [define, requirement, TOTO-TEMP-XXX1(toto~244eed18)]
268
+ --
269
+ the requirement value.
270
+ --
271
+ """
272
+
273
+ Scenario: Checksum keep explicit version in ref setting
274
+ Given a file named "modifications.yml" with:
275
+ """
276
+ ---
277
+ :update_requirement_checksum:
278
+ :type: update_def_checksum
279
+ :config:
280
+ :def_type: requirement
281
+ """
282
+ And a file named "thedoc.adoc" with:
283
+ """
284
+ [define, requirement, TOTO-TEMP-XXX1(toto)]
285
+ --
286
+ the requirement value.
287
+ --
288
+ """
289
+ When I successfully run `defmastership modify --modifications update_requirement_checksum thedoc.adoc`
290
+ Then the stdout should not contain anything
291
+ And the stderr should not contain anything
292
+ And the file "thedoc.adoc" should contain:
293
+ """
294
+ [define, requirement, TOTO-TEMP-XXX1(toto~244eed18)]
295
+ --
296
+ the requirement value.
297
+ --
298
+ """
@@ -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
+
@@ -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
@@ -20,7 +20,9 @@ module DefMastership
20
20
  (,\s*\[\s*(?<labels>.*?)\s*\])?\s*\]
21
21
  AFT
22
22
 
23
- DEF_VERSION_AND_CHECKSUM = '(\((?<explicit_version>[^~]+)?(?<explicit_checksum>~[[:alnum:]]+)?\))?'
23
+ DEF_VERSION_AND_CHECKSUM = '(?<version_and_checksum>' \
24
+ '\((?<explicit_version>[^~]+)?(?<explicit_checksum>~[[:alnum:]]+)?\)' \
25
+ ')?'
24
26
 
25
27
  DEFINITION = Regexp.new(
26
28
  "#{DEF_BEFORE_REF}(?<reference>[\\w:_-]+)#{DEF_VERSION_AND_CHECKSUM}#{DEF_AFTER_REF}",
@@ -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
@@ -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)
@@ -23,9 +23,8 @@ module DefMastership
23
23
  return line unless match
24
24
  return line unless match[:type] == def_type
25
25
 
26
- explicit_checksum_str = match[:explicit_checksum].nil? ? '' : "(#{match[:explicit_checksum]})"
27
- line.gsub("#{match[:reference]}#{explicit_checksum_str}") do
28
- "#{match[:reference]}(#{@document.ref_to_def(match[:reference]).sha256})"
26
+ line.gsub(Regexp.new("#{match[:reference]}#{DMRegexp::DEF_VERSION_AND_CHECKSUM}")) do
27
+ "#{match[:reference]}(#{match[:explicit_version]}#{@document.ref_to_def(match[:reference]).sha256})"
29
28
  end
30
29
  end
31
30
 
@@ -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.8'
5
+ VERSION = '1.0.13'
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]'))
@@ -0,0 +1,48 @@
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?('....')).to(eq(false)) }
21
+ end
22
+
23
+ context 'when disabled' do
24
+ before { parsing_state.enabled?("----\n") }
25
+
26
+ it { expect(parsing_state.enabled?("whatever\n")).to(eq(false)) }
27
+ it { expect(parsing_state.enabled?("----\n")).to(eq(true)) }
28
+ it { expect(parsing_state.enabled?("....\n")).to(eq(false)) }
29
+ end
30
+
31
+ context 'with intricated disables satrting with "...."' do
32
+ before do
33
+ ["....\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
34
+ end
35
+
36
+ it { expect(parsing_state.enabled?("----\n")).to(eq(false)) }
37
+ it { expect(parsing_state.enabled?("....\n")).to(eq(true)) }
38
+ end
39
+
40
+ context 'with intricated disables satrting with "----"' do
41
+ before do
42
+ ["....\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
43
+ end
44
+
45
+ it { expect(parsing_state.enabled?("....\n")).to(eq(true)) }
46
+ end
47
+ end
48
+ 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
@@ -63,6 +63,16 @@ RSpec.describe(DefMastership::UpdateDefChecksumLineModifier) do
63
63
  expect(linemodifier.replace('[define,requirement,REFERENCE(~bad)]'))
64
64
  .to(eq('[define,requirement,REFERENCE(~abcd1234)]'))
65
65
  end
66
+
67
+ it do
68
+ expect(linemodifier.replace('[define,requirement,REFERENCE(toto~bad)]'))
69
+ .to(eq('[define,requirement,REFERENCE(toto~abcd1234)]'))
70
+ end
71
+
72
+ it do
73
+ expect(linemodifier.replace('[define,requirement,REFERENCE(toto)]'))
74
+ .to(eq('[define,requirement,REFERENCE(toto~abcd1234)]'))
75
+ end
66
76
  end
67
77
  end
68
78
  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.8
4
+ version: 1.0.13
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-11 00:00:00.000000000 Z
11
+ date: 2021-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aruba
@@ -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: