metanorma-standoc 1.6.4 → 1.6.5

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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/lib/asciidoctor/standoc/base.rb +8 -16
  3. data/lib/asciidoctor/standoc/basicdoc.rng +32 -0
  4. data/lib/asciidoctor/standoc/cleanup.rb +1 -1
  5. data/lib/asciidoctor/standoc/cleanup_ref.rb +17 -24
  6. data/lib/asciidoctor/standoc/cleanup_terms.rb +3 -0
  7. data/lib/asciidoctor/standoc/converter.rb +3 -0
  8. data/lib/asciidoctor/standoc/isodoc.rng +15 -0
  9. data/lib/asciidoctor/standoc/macros.rb +19 -63
  10. data/lib/asciidoctor/standoc/macros_terms.rb +82 -0
  11. data/lib/asciidoctor/standoc/ref.rb +12 -21
  12. data/lib/asciidoctor/standoc/table.rb +12 -0
  13. data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +86 -0
  14. data/lib/metanorma/standoc/version.rb +1 -1
  15. data/spec/asciidoctor-standoc/blocks_spec.rb +8 -8
  16. data/spec/asciidoctor-standoc/cleanup_sections_spec.rb +6 -6
  17. data/spec/asciidoctor-standoc/cleanup_spec.rb +70 -9
  18. data/spec/asciidoctor-standoc/macros_plantuml_spec.rb +307 -0
  19. data/spec/asciidoctor-standoc/macros_spec.rb +228 -277
  20. data/spec/asciidoctor-standoc/section_spec.rb +11 -11
  21. data/spec/asciidoctor-standoc/table_spec.rb +86 -0
  22. data/spec/fixtures/diagram_definitions.lutaml +4 -4
  23. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +49 -49
  24. data/spec/vcr_cassettes/isobib_get_123.yml +14 -14
  25. data/spec/vcr_cassettes/isobib_get_123_1.yml +28 -28
  26. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +37 -37
  27. data/spec/vcr_cassettes/isobib_get_123_2001.yml +14 -14
  28. data/spec/vcr_cassettes/isobib_get_124.yml +14 -14
  29. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +8 -8
  30. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +51 -61
  31. metadata +5 -2
@@ -0,0 +1,307 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Asciidoctor::Standoc do
4
+ it "processes the PlantUML macro" do
5
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)).gsub(%r{plantuml/plantuml[^./]+\.}, "plantuml/_."))).to be_equivalent_to xmlpp(<<~"OUTPUT")
6
+ #{ASCIIDOC_BLANK_HDR}
7
+
8
+ [plantuml]
9
+ ....
10
+ @startuml
11
+ Alice -> Bob: Authentication Request
12
+ Bob --> Alice: Authentication Response
13
+
14
+ Alice -> Bob: Another authentication Request
15
+ Alice <-- Bob: another authentication Response
16
+ @enduml
17
+ ....
18
+
19
+ [plantuml]
20
+ ....
21
+ Alice -> Bob: Authentication Request
22
+ Bob --> Alice: Authentication Response
23
+
24
+ Alice -> Bob: Another authentication Request
25
+ Alice <-- Bob: another authentication Response
26
+ ....
27
+
28
+ [plantuml]
29
+ ....
30
+ @startuml filename
31
+ Alice -> Bob: Authentication Request
32
+ Bob --> Alice: Authentication Response
33
+
34
+ Alice -> Bob: Another authentication Request
35
+ Alice <-- Bob: another authentication Response
36
+ @enduml
37
+ ....
38
+ INPUT
39
+ #{BLANK_HDR}
40
+ <sections><figure id="_">
41
+ <image src="plantuml/_.png" id="_" mimetype="image/png" height="auto" width="auto"/>
42
+ </figure>
43
+ <figure id="_">
44
+ <image src="plantuml/_.png" id="_" mimetype="image/png" height="auto" width="auto"/>
45
+ </figure>
46
+ <figure id="_">
47
+ <image src="plantuml/filename.png" id="_" mimetype="image/png" height="auto" width="auto"/>
48
+ </figure>
49
+ </sections>
50
+
51
+ </standard-document>
52
+ OUTPUT
53
+ end
54
+
55
+ it "processes the PlantUML macro with imagesdir" do
56
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)).gsub(%r{spec/assets/[^./]+\.}, "spec/assets/_."))).to be_equivalent_to xmlpp(<<~"OUTPUT")
57
+ = Document title
58
+ Author
59
+ :docfile: test.adoc
60
+ :nodoc:
61
+ :novalid:
62
+ :no-isobib:
63
+ :imagesdir: spec/assets
64
+
65
+ [plantuml]
66
+ ....
67
+ @startuml
68
+ Alice -> Bob: Authentication Request
69
+ Bob --> Alice: Authentication Response
70
+
71
+ Alice -> Bob: Another authentication Request
72
+ Alice <-- Bob: another authentication Response
73
+ @enduml
74
+ ....
75
+ INPUT
76
+ #{BLANK_HDR}
77
+ <sections>
78
+ <figure id="_">
79
+ <image src="spec/assets/_.png" id="_" mimetype="image/png" height="auto" width="auto"/>
80
+ </figure>
81
+ </sections>
82
+ </standard-document>
83
+ OUTPUT
84
+ end
85
+
86
+ context 'when lutaml_diagram' do
87
+ let(:input) do
88
+ <<~"OUTPUT"
89
+ = Document title
90
+ Author
91
+ :docfile: test.adoc
92
+ :nodoc:
93
+ :novalid:
94
+ :no-isobib:
95
+ :imagesdir: spec/assets
96
+
97
+ [lutaml_diagram]
98
+ ....
99
+ diagram MyView {
100
+ fontname "Arial"
101
+ title "my diagram"
102
+ class Foo {}
103
+ }
104
+ ....
105
+ OUTPUT
106
+ end
107
+ let(:output) do
108
+ <<~"OUTPUT"
109
+ #{BLANK_HDR}
110
+ <sections>
111
+ <figure id="_">
112
+ <image src="spec/assets/_.png" id="_" mimetype="image/png" height="auto" width="auto"/>
113
+ </figure>
114
+ </sections>
115
+ </standard-document>
116
+ OUTPUT
117
+ end
118
+
119
+ it "processes the lutaml_diagram" do
120
+ expect(
121
+ xmlpp(
122
+ strip_guid(Asciidoctor.convert(input, backend: :standoc, header_footer: true))
123
+ .gsub(%r{".+spec\/assets\/lutaml\/[^.\/]+\.}, %q("spec/assets/_.))))
124
+ .to(be_equivalent_to xmlpp(output))
125
+ end
126
+ end
127
+
128
+ context 'when lutaml_uml_attributes_table' do
129
+ let(:example_file) { fixtures_path("diagram_definitions.lutaml") }
130
+ let(:input) do
131
+ <<~"OUTPUT"
132
+ = Document title
133
+ Author
134
+ :docfile: test.adoc
135
+ :nodoc:
136
+ :novalid:
137
+ :no-isobib:
138
+ :imagesdir: spec/assets
139
+
140
+ [lutaml_uml_attributes_table,#{example_file},AttributeProfile]
141
+ OUTPUT
142
+ end
143
+ let(:output) do
144
+ <<~"OUTPUT"
145
+ #{BLANK_HDR}
146
+ <sections>
147
+ <clause id='_' inline-header='false' obligation='normative'>
148
+ <title>AttributeProfile</title>
149
+ <table id='_'>
150
+ <name>AttributeProfile attributes</name>
151
+ <thead>
152
+ <tr>
153
+ <th valign='top' align='left'>Name</th>
154
+ <th valign='top' align='left'>Definition</th>
155
+ <th valign='top' align='left'>Mandatory/ Optional/ Conditional</th>
156
+ <th valign='top' align='left'>Max Occur</th>
157
+ <th valign='top' align='left'>Data Type</th>
158
+ </tr>
159
+ </thead>
160
+ <tbody>
161
+ <tr>
162
+ <td valign='top' align='left'>addressClassProfile</td>
163
+ <td valign='top' align='left'>TODO: enum ‘s definition</td>
164
+ <td valign='top' align='left'>O</td>
165
+ <td valign='top' align='left'>1</td>
166
+ <td valign='top' align='left'>
167
+ <tt>CharacterString</tt>
168
+ </td>
169
+ </tr>
170
+ <tr>
171
+ <td valign='top' align='left'>imlicistAttributeProfile</td>
172
+ <td valign='top' align='left'>this is attribute definition with multiply lines</td>
173
+ <td valign='top' align='left'>O</td>
174
+ <td valign='top' align='left'>1</td>
175
+ <td valign='top' align='left'>
176
+ <tt>CharacterString</tt>
177
+ </td>
178
+ </tr>
179
+ </tbody>
180
+ </table>
181
+ </clause>
182
+ </sections>
183
+ </standard-document>
184
+ OUTPUT
185
+ end
186
+
187
+ it "processes the lutaml_uml_attributes_table macro" do
188
+ expect(
189
+ xmlpp(
190
+ strip_guid(Asciidoctor.convert(input, backend: :standoc, header_footer: true))))
191
+ .to(be_equivalent_to(xmlpp(output)))
192
+ end
193
+ end
194
+
195
+ it "processes the PlantUML macro with PlantUML disabled" do
196
+ mock_plantuml_disabled
197
+ expect { Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) }.to output(%r{PlantUML not installed}).to_stderr
198
+ #{ASCIIDOC_BLANK_HDR}
199
+
200
+ [plantuml]
201
+ ....
202
+ @startuml
203
+ Alice -> Bob: Authentication Request
204
+ Bob --> Alice: Authentication Response
205
+
206
+ Alice -> Bob: Another authentication Request
207
+ Alice <-- Bob: another authentication Response
208
+ @enduml
209
+ ....
210
+ INPUT
211
+
212
+ mock_plantuml_disabled
213
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
214
+ #{ASCIIDOC_BLANK_HDR}
215
+
216
+ [plantuml]
217
+ ....
218
+ @startuml
219
+ Alice -> Bob: Authentication Request
220
+ Bob --> Alice: Authentication Response
221
+
222
+ Alice -> Bob: Another authentication Request
223
+ Alice <-- Bob: another authentication Response
224
+ @enduml
225
+ ....
226
+ INPUT
227
+ #{BLANK_HDR}
228
+ <sections>
229
+ <sourcecode id="_" lang="plantuml">@startuml
230
+ Alice -&gt; Bob: Authentication Request
231
+ Bob --&gt; Alice: Authentication Response
232
+
233
+ Alice -&gt; Bob: Another authentication Request
234
+ Alice &lt;-- Bob: another authentication Response
235
+ @enduml</sourcecode>
236
+ </sections>
237
+ </standard-document>
238
+ OUTPUT
239
+ end
240
+
241
+ it "processes the PlantUML macro with localdir unwritable" do
242
+ mock_localdir_unwritable
243
+ expect { Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) }.to output(%r{not writable for PlantUML}).to_stderr
244
+ #{ASCIIDOC_BLANK_HDR}
245
+
246
+ [plantuml]
247
+ ....
248
+ @startuml
249
+ Alice -> Bob: Authentication Request
250
+ Bob --> Alice: Authentication Response
251
+
252
+ Alice -> Bob: Another authentication Request
253
+ Alice <-- Bob: another authentication Response
254
+ @enduml
255
+ ....
256
+ INPUT
257
+
258
+ mock_localdir_unwritable
259
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
260
+ #{ASCIIDOC_BLANK_HDR}
261
+
262
+ [plantuml]
263
+ ....
264
+ @startuml
265
+ Alice -> Bob: Authentication Request
266
+ Bob --> Alice: Authentication Response
267
+
268
+ Alice -> Bob: Another authentication Request
269
+ Alice <-- Bob: another authentication Response
270
+ @enduml
271
+ ....
272
+ INPUT
273
+ #{BLANK_HDR}
274
+ <sections>
275
+ <sourcecode id="_" lang="plantuml">@startuml
276
+ Alice -&gt; Bob: Authentication Request
277
+ Bob --&gt; Alice: Authentication Response
278
+
279
+ Alice -&gt; Bob: Another authentication Request
280
+ Alice &lt;-- Bob: another authentication Response
281
+ @enduml</sourcecode>
282
+ </sections>
283
+ </standard-document>
284
+ OUTPUT
285
+ end
286
+
287
+ private
288
+
289
+ def mock_plantuml_disabled
290
+ expect(Asciidoctor::Standoc::PlantUMLBlockMacroBackend).to receive(:plantuml_installed?) do
291
+ raise "PlantUML not installed"
292
+ false
293
+ end
294
+ end
295
+
296
+ def mock_localdir_unwritable
297
+ expect(Asciidoctor::Standoc::Utils).to receive(:localdir) do
298
+ "/"
299
+ end.exactly(2).times
300
+ end
301
+
302
+ def mock_localdir_unwritable
303
+ expect(File).to receive(:writable?) do
304
+ false
305
+ end
306
+ end
307
+ end
@@ -44,6 +44,45 @@ RSpec.describe Asciidoctor::Standoc do
44
44
  OUTPUT
45
45
  end
46
46
 
47
+ it "processes the Asciidoctor::Standoc index macros" do
48
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
49
+ #{ASCIIDOC_BLANK_HDR}
50
+ index:also[]
51
+ index:see[A]
52
+ index:also[B,C~x~]
53
+ index:see[D,_E_,F]
54
+ index:also[G,H,I,J]
55
+ index:see[K,L,M,N,O]
56
+ INPUT
57
+ #{BLANK_HDR}
58
+ <sections>
59
+ <p id='_'>
60
+ <index-xref also='true'>
61
+ <primary>B</primary>
62
+ <target>
63
+ C
64
+ <sub>x</sub>
65
+ </target>
66
+ </index-xref>
67
+ <index-xref also='false'>
68
+ <primary>D</primary>
69
+ <secondary>
70
+ <em>E</em>
71
+ </secondary>
72
+ <target>F</target>
73
+ </index-xref>
74
+ <index-xref also='true'>
75
+ <primary>G</primary>
76
+ <secondary>H</secondary>
77
+ <tertiary>I</tertiary>
78
+ <target>J</target>
79
+ </index-xref>
80
+ </p>
81
+ </sections>
82
+ </standard-document>
83
+ OUTPUT
84
+ end
85
+
47
86
  it "processes the Asciidoctor::Standoc variant macros" do
48
87
  expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
49
88
  #{ASCIIDOC_BLANK_HDR}
@@ -329,13 +368,11 @@ OUTPUT
329
368
  <formula id='_'>
330
369
  <stem type='MathML'>
331
370
  <math xmlns='http://www.w3.org/1998/Math/MathML'>
332
- <mover>
371
+ <mover accent="true">
333
372
  <mrow>
334
373
  <mi>X</mi>
335
374
  </mrow>
336
- <mrow>
337
375
  <mo>¯</mo>
338
- </mrow>
339
376
  </mover>
340
377
  <mo>′</mo>
341
378
  <mo>=</mo>
@@ -508,309 +545,223 @@ OUTPUT
508
545
  OUTPUT
509
546
  end
510
547
 
511
- it "processes the PlantUML macro" do
512
- expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)).gsub(%r{plantuml/plantuml[^./]+\.}, "plantuml/_."))).to be_equivalent_to xmlpp(<<~"OUTPUT")
513
- #{ASCIIDOC_BLANK_HDR}
514
-
515
- [plantuml]
516
- ....
517
- @startuml
518
- Alice -> Bob: Authentication Request
519
- Bob --> Alice: Authentication Response
520
-
521
- Alice -> Bob: Another authentication Request
522
- Alice <-- Bob: another authentication Response
523
- @enduml
524
- ....
525
-
526
- [plantuml]
527
- ....
528
- Alice -> Bob: Authentication Request
529
- Bob --> Alice: Authentication Response
530
-
531
- Alice -> Bob: Another authentication Request
532
- Alice <-- Bob: another authentication Response
533
- ....
534
-
535
- [plantuml]
536
- ....
537
- @startuml filename
538
- Alice -> Bob: Authentication Request
539
- Bob --> Alice: Authentication Response
540
-
541
- Alice -> Bob: Another authentication Request
542
- Alice <-- Bob: another authentication Response
543
- @enduml
544
- ....
545
- INPUT
546
- #{BLANK_HDR}
547
- <sections><figure id="_">
548
- <image src="plantuml/_.png" id="_" mimetype="image/png" height="auto" width="auto"/>
549
- </figure>
550
- <figure id="_">
551
- <image src="plantuml/_.png" id="_" mimetype="image/png" height="auto" width="auto"/>
552
- </figure>
553
- <figure id="_">
554
- <image src="plantuml/filename.png" id="_" mimetype="image/png" height="auto" width="auto"/>
555
- </figure>
556
- </sections>
557
-
558
- </standard-document>
559
- OUTPUT
560
- end
561
-
562
- it "processes the PlantUML macro with imagesdir" do
563
- expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)).gsub(%r{spec/assets/[^./]+\.}, "spec/assets/_."))).to be_equivalent_to xmlpp(<<~"OUTPUT")
564
- = Document title
565
- Author
566
- :docfile: test.adoc
567
- :nodoc:
568
- :novalid:
569
- :no-isobib:
570
- :imagesdir: spec/assets
571
-
572
- [plantuml]
573
- ....
574
- @startuml
575
- Alice -> Bob: Authentication Request
576
- Bob --> Alice: Authentication Response
577
-
578
- Alice -> Bob: Another authentication Request
579
- Alice <-- Bob: another authentication Response
580
- @enduml
581
- ....
582
- INPUT
583
- #{BLANK_HDR}
584
- <sections>
585
- <figure id="_">
586
- <image src="spec/assets/_.png" id="_" mimetype="image/png" height="auto" width="auto"/>
587
- </figure>
588
- </sections>
589
- </standard-document>
590
- OUTPUT
548
+ describe 'term inline macros' do
549
+ subject(:convert) do
550
+ xmlpp(
551
+ strip_guid(
552
+ Asciidoctor.convert(
553
+ input, backend: :standoc, header_footer: true)))
591
554
  end
592
-
593
- context 'when lutaml_diagram' do
594
555
  let(:input) do
595
- <<~"OUTPUT"
596
- = Document title
597
- Author
598
- :docfile: test.adoc
599
- :nodoc:
600
- :novalid:
601
- :no-isobib:
602
- :imagesdir: spec/assets
603
-
604
- [lutaml_diagram]
605
- ....
606
- diagram MyView {
607
- fontname "Arial"
608
- title "my diagram"
609
- class Foo {}
610
- }
611
- ....
612
- OUTPUT
613
- end
614
- let(:output) do
615
- <<~"OUTPUT"
616
- #{BLANK_HDR}
617
- <sections>
618
- <figure id="_">
619
- <image src="spec/assets/_.png" id="_" mimetype="image/png" height="auto" width="auto"/>
620
- </figure>
621
- </sections>
622
- </standard-document>
623
- OUTPUT
624
- end
556
+ <<~XML
557
+ #{ASCIIDOC_BLANK_HDR}
558
+ == Terms and Definitions
625
559
 
626
- it "processes the lutaml_diagram" do
627
- expect(
628
- xmlpp(
629
- strip_guid(Asciidoctor.convert(input, backend: :standoc, header_footer: true))
630
- .gsub(%r{".+spec\/assets\/lutaml\/[^.\/]+\.}, %q("spec/assets/_.))))
631
- .to(be_equivalent_to xmlpp(output))
632
- end
633
- end
560
+ === name2
634
561
 
635
- =begin
636
- context 'when lutaml_uml_attributes_table' do
637
- let(:example_file) { fixtures_path("diagram_definitions.lutaml") }
638
- let(:input) do
639
- <<~"OUTPUT"
640
- = Document title
641
- Author
642
- :docfile: test.adoc
643
- :nodoc:
644
- :novalid:
645
- :no-isobib:
646
- :imagesdir: spec/assets
647
-
648
- [lutaml_uml_attributes_table,#{example_file},AttributeProfile]
649
- OUTPUT
562
+ == Main
563
+
564
+ term:[name,name2] is a term
565
+ XML
650
566
  end
651
567
  let(:output) do
652
- <<~"OUTPUT"
653
- #{BLANK_HDR}
568
+ <<~XML
569
+ #{BLANK_HDR}
654
570
  <sections>
571
+ <terms id='_' obligation='normative'>
572
+ <title>Terms and definitions</title>
573
+ <p id='_'>For the purposes of this document, the following terms and definitions apply.</p>
574
+ <term id='term-name2'>
575
+ <preferred>name2</preferred>
576
+ </term>
577
+ </terms>
655
578
  <clause id='_' inline-header='false' obligation='normative'>
656
- <title>AttributeProfile</title>
657
- <table id='_'>
658
- <name>AttributeProfile attributes</name>
659
- <thead>
660
- <tr>
661
- <th valign='top' align='left'>Name</th>
662
- <th valign='top' align='left'>Definition</th>
663
- <th valign='top' align='left'>Mandatory/ Optional/ Conditional</th>
664
- <th valign='top' align='left'>Max Occur</th>
665
- <th valign='top' align='left'>Data Type</th>
666
- </tr>
667
- </thead>
668
- <tbody>
669
- <tr>
670
- <td valign='top' align='left'>addressClassProfile</td>
671
- <td valign='top' align='left'>TODO: enum ‘s definition</td>
672
- <td valign='top' align='left'>M</td>
673
- <td valign='top' align='left'>1</td>
674
- <td valign='top' align='left'>
675
- <tt>CharacterString</tt>
676
- </td>
677
- </tr>
678
- <tr>
679
- <td valign='top' align='left'>imlicistAttributeProfile</td>
680
- <td valign='top' align='left'>this is attribute definition with multiply lines</td>
681
- <td valign='top' align='left'>M</td>
682
- <td valign='top' align='left'>1</td>
683
- <td valign='top' align='left'>
684
- <tt>CharacterString</tt>
685
- </td>
686
- </tr>
687
- </tbody>
688
- </table>
579
+ <title>Main</title>
580
+ <p id='_'>
581
+ <em>name</em>
582
+ (
583
+ <xref target='term-name2'/>
584
+ ) is a term
585
+ </p>
689
586
  </clause>
690
587
  </sections>
691
588
  </standard-document>
692
- OUTPUT
589
+ XML
693
590
  end
694
591
 
695
- it "processes the lutaml_diagram" do
696
- expect(
697
- xmlpp(
698
- strip_guid(Asciidoctor.convert(input, backend: :standoc, header_footer: true))))
699
- .to(be_equivalent_to(xmlpp(output)))
592
+ it 'converts macro into the correct xml' do
593
+ expect(convert).to(be_equivalent_to(xmlpp(output)))
700
594
  end
701
- end
702
- =end
703
595
 
704
- it "processes the PlantUML macro with PlantUML disabled" do
705
- mock_plantuml_disabled
706
- expect { Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) }.to output(%r{PlantUML not installed}).to_stderr
707
- #{ASCIIDOC_BLANK_HDR}
596
+ context 'default params' do
597
+ let(:input) do
598
+ <<~XML
599
+ #{ASCIIDOC_BLANK_HDR}
708
600
 
709
- [plantuml]
710
- ....
711
- @startuml
712
- Alice -> Bob: Authentication Request
713
- Bob --> Alice: Authentication Response
601
+ == Terms and Definitions
714
602
 
715
- Alice -> Bob: Another authentication Request
716
- Alice <-- Bob: another authentication Response
717
- @enduml
718
- ....
719
- INPUT
603
+ === name
720
604
 
721
- mock_plantuml_disabled
722
- expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
723
- #{ASCIIDOC_BLANK_HDR}
605
+ == Main
724
606
 
725
- [plantuml]
726
- ....
727
- @startuml
728
- Alice -> Bob: Authentication Request
729
- Bob --> Alice: Authentication Response
607
+ term:[name] is a term
608
+ XML
609
+ end
610
+ let(:output) do
611
+ <<~XML
612
+ #{BLANK_HDR}
613
+ <sections>
614
+ <terms id='_' obligation='normative'>
615
+ <title>Terms and definitions</title>
616
+ <p id='_'>For the purposes of this document, the following terms and definitions apply.</p>
617
+ <term id='term-name'>
618
+ <preferred>name</preferred>
619
+ </term>
620
+ </terms>
621
+ <clause id='_' inline-header='false' obligation='normative'>
622
+ <title>Main</title>
623
+ <p id='_'>
624
+ <em>name</em>
625
+ (
626
+ <xref target='term-name' />
627
+ ) is a term
628
+ </p>
629
+ </clause>
630
+ </sections>
631
+ </standard-document>
632
+ XML
633
+ end
634
+
635
+ it 'uses `name` as termref name' do
636
+ expect(convert).to(be_equivalent_to(xmlpp(output)))
637
+ end
638
+ end
730
639
 
731
- Alice -> Bob: Another authentication Request
732
- Alice <-- Bob: another authentication Response
733
- @enduml
734
- ....
735
- INPUT
736
- #{BLANK_HDR}
737
- <sections>
738
- <sourcecode id="_" lang="plantuml">@startuml
739
- Alice -&gt; Bob: Authentication Request
740
- Bob --&gt; Alice: Authentication Response
741
-
742
- Alice -&gt; Bob: Another authentication Request
743
- Alice &lt;-- Bob: another authentication Response
744
- @enduml</sourcecode>
745
- </sections>
746
- </standard-document>
747
- OUTPUT
748
- end
640
+ context 'multiply exising ids in document' do
641
+ let(:input) do
642
+ <<~XML
643
+ #{ASCIIDOC_BLANK_HDR}
749
644
 
750
- it "processes the PlantUML macro with localdir unwritable" do
751
- mock_localdir_unwritable
752
- expect { Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) }.to output(%r{not writable for PlantUML}).to_stderr
753
- #{ASCIIDOC_BLANK_HDR}
645
+ == Terms and Definitions
754
646
 
755
- [plantuml]
756
- ....
757
- @startuml
758
- Alice -> Bob: Authentication Request
759
- Bob --> Alice: Authentication Response
647
+ === name
648
+ === name2
760
649
 
761
- Alice -> Bob: Another authentication Request
762
- Alice <-- Bob: another authentication Response
763
- @enduml
764
- ....
765
- INPUT
650
+ [[term-name]]
651
+ == Main
766
652
 
767
- mock_localdir_unwritable
768
- expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
769
- #{ASCIIDOC_BLANK_HDR}
653
+ paragraph
770
654
 
771
- [plantuml]
772
- ....
773
- @startuml
774
- Alice -> Bob: Authentication Request
775
- Bob --> Alice: Authentication Response
655
+ [[term-name2]]
656
+ == Second
776
657
 
777
- Alice -> Bob: Another authentication Request
778
- Alice <-- Bob: another authentication Response
779
- @enduml
780
- ....
781
- INPUT
782
- #{BLANK_HDR}
783
- <sections>
784
- <sourcecode id="_" lang="plantuml">@startuml
785
- Alice -&gt; Bob: Authentication Request
786
- Bob --&gt; Alice: Authentication Response
787
-
788
- Alice -&gt; Bob: Another authentication Request
789
- Alice &lt;-- Bob: another authentication Response
790
- @enduml</sourcecode>
791
- </sections>
792
- </standard-document>
793
- OUTPUT
794
- end
658
+ term:[name] is a term
659
+ term:[name2] is a term
660
+ XML
661
+ end
662
+ let(:output) do
663
+ <<~XML
664
+ #{BLANK_HDR}
665
+ <sections>
666
+ <terms id='_' obligation='normative'>
667
+ <title>Terms and definitions</title>
668
+ <p id='_'>For the purposes of this document, the following terms and definitions apply.</p>
669
+ <term id='term-name-1'>
670
+ <preferred>name</preferred>
671
+ </term>
672
+ <term id='term-name2-1'>
673
+ <preferred>name2</preferred>
674
+ </term>
675
+ </terms>
676
+ <clause id='term-name' inline-header='false' obligation='normative'>
677
+ <title>Main</title>
678
+ <p id='_'>paragraph</p>
679
+ </clause>
680
+ <clause id='term-name2' inline-header='false' obligation='normative'>
681
+ <title>Second</title>
682
+ <p id='_'>
683
+ <em>name</em>
684
+ (
685
+ <xref target='term-name-1' />
686
+ ) is a term
687
+ <em>name2</em>
688
+ (
689
+ <xref target='term-name2-1' />
690
+ ) is a term
691
+ </p>
692
+ </clause>
693
+ </sections>
694
+ </standard-document>
695
+ XML
696
+ end
697
+
698
+ it 'generates unique ids which do not match existing ids' do
699
+ expect(convert).to(be_equivalent_to(xmlpp(output)))
700
+ end
701
+ end
795
702
 
796
- private
703
+ context 'when missing actual ref' do
704
+ let(:input) do
705
+ <<~XML
706
+ #{ASCIIDOC_BLANK_HDR}
797
707
 
798
- def mock_plantuml_disabled
799
- expect(Asciidoctor::Standoc::PlantUMLBlockMacroBackend).to receive(:plantuml_installed?) do
800
- raise "PlantUML not installed"
801
- false
802
- end
803
- end
708
+ == Terms and Definitions
804
709
 
805
- def mock_localdir_unwritable
806
- expect(Asciidoctor::Standoc::Utils).to receive(:localdir) do
807
- "/"
808
- end.exactly(2).times
809
- end
710
+ === name identity
711
+
712
+ [[name-check]]
713
+ === name check
714
+
715
+ paragraph
810
716
 
811
- def mock_localdir_unwritable
812
- expect(File).to receive(:writable?) do
813
- false
717
+ term:[name check] is a term
718
+
719
+ term:[name identity] is a term
720
+
721
+ Moreover, term:[missing] is a term
722
+ XML
723
+ end
724
+ let(:output) do
725
+ <<~XML
726
+ #{BLANK_HDR}
727
+ <sections>
728
+ <terms id='_' obligation='normative'>
729
+ <title>Terms and definitions</title>
730
+ <p id='_'>For the purposes of this document, the following terms and definitions apply.</p>
731
+ <term id='term-name-identity'>
732
+ <preferred>name identity</preferred>
733
+ </term>
734
+ <term id='name-check'>
735
+ <preferred>name check</preferred>
736
+ <definition>
737
+ <p id='_'>paragraph</p>
738
+ <p id='_'>
739
+ <em>name check</em>
740
+ (
741
+ <xref target='name-check'/>
742
+ ) is a term
743
+ </p>
744
+ <p id='_'>
745
+ <em>name identity</em>
746
+ (
747
+ <xref target='term-name-identity'/>
748
+ ) is a term
749
+ </p>
750
+ <p id="_">Moreover, (<strong>term “missing” not resolved</strong>) is a term
751
+ </p>
752
+ </definition>
753
+ </term>
754
+ </terms>
755
+ </sections>
756
+ </standard-document>
757
+ XML
758
+ end
759
+
760
+ it 'generates unique ids which do not match existing ids' do
761
+ expect(convert).to(be_equivalent_to(xmlpp(output)))
762
+ end
814
763
  end
815
- end
764
+
765
+ end
766
+
816
767
  end