defmastership 1.0.15 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 615339b09506e076db9c98a773e115daaa9914bafebef1029af8c4c9e8266dc0
4
- data.tar.gz: 14b7cf352d495dc847cdd9fbdfff6abd821ebc0e6a8f6f2334ecb16c7bc87de2
3
+ metadata.gz: 01a97f896ec1b0b88f80686290f5a0bf639ae7caeb4e4c48035e13221d3f21e2
4
+ data.tar.gz: 75d68f34285d4babe217a678204681399ef7aa11679810eb00a5eb95eb9771d8
5
5
  SHA512:
6
- metadata.gz: ebd3eb769920a15442d8a048e55b5fb124aa4a5c2916a85378d5d9f07c20b29b160c94b12e783d5d4a4f89f9aa5d80342065d533b66c6972de74eb1adaecbc59
7
- data.tar.gz: ad72f426a240eda86b517a9d5e7bd8f28cc037acef3a7a391880a2e9c4e4432309a962b810086aed081c97bdc63a2fd4709dd4de261828e520bd93649b7cb55e
6
+ metadata.gz: 2926efd086db703c7a4e03b516c833a237ffa4d484492af6e70f3ae54bd4de30e50abe7cd15bdc8330b62ed46b6ddc04e474790a9e33b6260bc58ecde2113bc7
7
+ data.tar.gz: 5849049e21fc4882f957d09b0068769a26140327700caf88698595e2688f37b1467cc5b962d279d39c945ce6d187447d9ef6d90d1c26828bd7e841dfc08a30e2
@@ -130,7 +130,7 @@ Feature: The extract command
130
130
  ----
131
131
  """
132
132
  When I successfully run `defmastership export toto.adoc`
133
- Then the file "toto.csv" should contain:
133
+ Then the file "toto.csv" should not contain:
134
134
  """
135
135
  something_else
136
136
  """
@@ -312,3 +312,72 @@ Feature: The extract command
312
312
  """
313
313
  And the stdout should not contain anything
314
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
@@ -22,15 +22,11 @@ module DefMastership
22
22
  end
23
23
 
24
24
  def parse(lines)
25
- lines.reject(&:commented?).each do |line|
26
- next unless @parsing_state.enabled?(line)
27
-
28
- FILTERS.each do |filter|
29
- next unless line.match(filter.regexp)
30
-
31
- line = generate_event(filter.event, Regexp.last_match, line)
32
-
33
- 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)
34
30
  end
35
31
  end
36
32
  end
@@ -113,6 +109,16 @@ module DefMastership
113
109
 
114
110
  private
115
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
+
116
122
  def generate_event(event, match, line)
117
123
  if respond_to?(event)
118
124
  line = public_send(event, match, line)
@@ -9,8 +9,10 @@ module DefMastership
9
9
  end
10
10
 
11
11
  def enabled?(line)
12
+ return false if line.match(DMRegexp::SINGLE_LINE_COMMENT)
13
+
12
14
  line = line.dup.chomp
13
- if ['....', '////'].include?(line)
15
+ if ['....', '----', '////'].include?(line)
14
16
  if @last_disabling_line == line
15
17
  @last_disabling_line = nil
16
18
  elsif @last_disabling_line.nil?
@@ -2,6 +2,6 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module DefMastership
5
- VERSION = '1.0.15'
5
+ VERSION = '1.0.16'
6
6
  public_constant :VERSION
7
7
  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
  [
@@ -13,33 +13,47 @@ RSpec.describe(DefMastership::ParsingState) do
13
13
  end
14
14
 
15
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
+
16
20
  context 'when starting' do
17
21
  it { expect(parsing_state.enabled?("whatever\n")).to(eq(true)) }
22
+ it { expect(parsing_state.enabled?("----\n")).to(eq(false)) }
18
23
  it { expect(parsing_state.enabled?("....\n")).to(eq(false)) }
19
24
  it { expect(parsing_state.enabled?("////\n")).to(eq(false)) }
20
25
  it { expect(parsing_state.enabled?('....')).to(eq(false)) }
21
26
  end
22
27
 
23
28
  context 'when disabled' do
24
- before { parsing_state.enabled?("....\n") }
29
+ before { parsing_state.enabled?("----\n") }
25
30
 
26
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)) }
27
34
  it { expect(parsing_state.enabled?("////\n")).to(eq(false)) }
28
- it { expect(parsing_state.enabled?("....\n")).to(eq(true)) }
29
35
  end
30
36
 
31
37
  context 'with intricated disables starting with "...."' do
32
38
  before do
33
- ["....\n", "////\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
39
+ ["....\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
34
40
  end
35
41
 
36
42
  it { expect(parsing_state.enabled?("----\n")).to(eq(false)) }
37
43
  it { expect(parsing_state.enabled?("....\n")).to(eq(true)) }
38
44
  end
39
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
+
40
54
  context 'with intricated disables starting with "////"' do
41
55
  before do
42
- ["////\n", "....\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
56
+ ["////\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
43
57
  end
44
58
 
45
59
  it { expect(parsing_state.enabled?("////\n")).to(eq(true)) }
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.15
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-05-06 00:00:00.000000000 Z
11
+ date: 2021-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aruba