metanorma-standoc 1.6.4 → 1.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +17 -0
  3. data/lib/asciidoctor/standoc/base.rb +8 -16
  4. data/lib/asciidoctor/standoc/basicdoc.rng +50 -3
  5. data/lib/asciidoctor/standoc/cleanup.rb +1 -1
  6. data/lib/asciidoctor/standoc/cleanup_block.rb +0 -8
  7. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +33 -20
  8. data/lib/asciidoctor/standoc/cleanup_inline.rb +3 -1
  9. data/lib/asciidoctor/standoc/cleanup_ref.rb +17 -24
  10. data/lib/asciidoctor/standoc/cleanup_terms.rb +4 -6
  11. data/lib/asciidoctor/standoc/converter.rb +4 -49
  12. data/lib/asciidoctor/standoc/front_contributor.rb +8 -4
  13. data/lib/asciidoctor/standoc/inline.rb +7 -5
  14. data/lib/asciidoctor/standoc/isodoc.rng +48 -3
  15. data/lib/asciidoctor/standoc/macros.rb +30 -61
  16. data/lib/asciidoctor/standoc/macros_terms.rb +82 -0
  17. data/lib/asciidoctor/standoc/ref.rb +12 -21
  18. data/lib/asciidoctor/standoc/section.rb +22 -20
  19. data/lib/asciidoctor/standoc/table.rb +12 -0
  20. data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +86 -0
  21. data/lib/asciidoctor/standoc/utils.rb +2 -0
  22. data/lib/metanorma/standoc/version.rb +1 -1
  23. data/metanorma-standoc.gemspec +1 -2
  24. data/spec/asciidoctor-standoc/base_spec.rb +14 -8
  25. data/spec/asciidoctor-standoc/blocks_spec.rb +14 -9
  26. data/spec/asciidoctor-standoc/cleanup_sections_spec.rb +18 -13
  27. data/spec/asciidoctor-standoc/cleanup_spec.rb +75 -11
  28. data/spec/asciidoctor-standoc/inline_spec.rb +4 -5
  29. data/spec/asciidoctor-standoc/macros_lutaml_spec.rb +1 -1
  30. data/spec/asciidoctor-standoc/macros_plantuml_spec.rb +307 -0
  31. data/spec/asciidoctor-standoc/macros_spec.rb +258 -277
  32. data/spec/asciidoctor-standoc/refs_dl_spec.rb +4 -4
  33. data/spec/asciidoctor-standoc/section_spec.rb +155 -12
  34. data/spec/asciidoctor-standoc/table_spec.rb +146 -0
  35. data/spec/fixtures/diagram_definitions.lutaml +4 -4
  36. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +49 -49
  37. data/spec/vcr_cassettes/isobib_get_123.yml +13 -13
  38. data/spec/vcr_cassettes/isobib_get_123_1.yml +25 -25
  39. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +33 -33
  40. data/spec/vcr_cassettes/isobib_get_123_2001.yml +14 -14
  41. data/spec/vcr_cassettes/isobib_get_124.yml +14 -14
  42. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +8 -8
  43. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +71 -75
  44. metadata +7 -18
@@ -3,7 +3,7 @@ require "relaton_iec"
3
3
  require "fileutils"
4
4
 
5
5
  RSpec.describe Asciidoctor::Standoc do
6
- it "strips any initial boilerplate from terms and definitions" do
6
+ it "appends any initial user-supplied text to boilerplate in terms and definitions" do
7
7
  expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
8
8
  #{ASCIIDOC_BLANK_HDR}
9
9
  == Terms and Definitions
@@ -20,8 +20,13 @@ RSpec.describe Asciidoctor::Standoc do
20
20
  <sections>
21
21
  <terms id="_" obligation="normative"><title>Terms and definitions</title>
22
22
  <p id="_">For the purposes of this document, the following terms and definitions apply.</p>
23
-
24
- <term id="_">
23
+ <p id='_'>I am boilerplate</p>
24
+ <ul id='_'>
25
+ <li>
26
+ <p id='_'>So am I</p>
27
+ </li>
28
+ </ul>
29
+ <term id="term-time">
25
30
  <preferred>Time</preferred>
26
31
  <definition><p id="_">This paragraph is extraneous</p></definition>
27
32
  </term></terms>
@@ -400,7 +405,7 @@ INPUT
400
405
  <stage>published</stage>
401
406
  </status>
402
407
  <copyright>
403
- <from>2020</from>
408
+ <from>#{Time.now.year}</from>
404
409
  </copyright>
405
410
  <ext>
406
411
  <doctype>article</doctype>
@@ -456,7 +461,7 @@ INPUT
456
461
  </fn>
457
462
  </title>
458
463
  <p id='_'>For the purposes of this document, the following terms and definitions apply.</p>
459
- <term id='_'>
464
+ <term id='term-term1'>
460
465
  <preferred>Term1</preferred>
461
466
  </term>
462
467
  </terms>
@@ -692,7 +697,7 @@ INPUT
692
697
  <stage>published</stage>
693
698
  </status>
694
699
  <copyright>
695
- <from>2020</from>
700
+ <from>#{Time.now.year}</from>
696
701
  </copyright>
697
702
  <ext>
698
703
  <doctype>article</doctype>
@@ -728,7 +733,7 @@ INPUT
728
733
  <terms id='_' obligation='normative'>
729
734
  <title>Terms and definitions</title>
730
735
  <p id='_'>For the purposes of this document, the following terms and definitions apply.</p>
731
- <term id='_'>
736
+ <term id='term-term1'>
732
737
  <preferred>Term1</preferred>
733
738
  </term>
734
739
  </terms>
@@ -923,7 +928,7 @@ INPUT
923
928
  <stage>published</stage>
924
929
  </status>
925
930
  <copyright>
926
- <from>2020</from>
931
+ <from>#{Time.now.year}</from>
927
932
  </copyright>
928
933
  <ext>
929
934
  <doctype>article</doctype>
@@ -962,7 +967,7 @@ INPUT
962
967
  Pour les besoins du présent document, les termes et définitions suivants
963
968
  s’appliquent.
964
969
  </p>
965
- <term id='_'>
970
+ <term id='term-term1'>
966
971
  <preferred>Term1</preferred>
967
972
  </term>
968
973
  </terms>
@@ -1157,7 +1162,7 @@ INPUT
1157
1162
  <stage>published</stage>
1158
1163
  </status>
1159
1164
  <copyright>
1160
- <from>2020</from>
1165
+ <from>#{Time.now.year}</from>
1161
1166
  </copyright>
1162
1167
  <ext>
1163
1168
  <doctype>article</doctype>
@@ -1193,7 +1198,7 @@ INPUT
1193
1198
  <terms id='_' obligation='normative'>
1194
1199
  <title>术语和定义</title>
1195
1200
  <p id='_'>下列术语和定义适用于本文件。</p>
1196
- <term id='_'>
1201
+ <term id='term-term1'>
1197
1202
  <preferred>Term1</preferred>
1198
1203
  </term>
1199
1204
  </terms>
@@ -1388,7 +1393,7 @@ INPUT
1388
1393
  <stage>published</stage>
1389
1394
  </status>
1390
1395
  <copyright>
1391
- <from>2020</from>
1396
+ <from>#{Time.now.year}</from>
1392
1397
  </copyright>
1393
1398
  <ext>
1394
1399
  <doctype>article</doctype>
@@ -1424,7 +1429,7 @@ INPUT
1424
1429
  <terms id='_' obligation='normative'>
1425
1430
  <title>Terms and definitions</title>
1426
1431
  <p id='_'>For the purposes of this document, the following terms and definitions apply.</p>
1427
- <term id='_'>
1432
+ <term id='term-term1'>
1428
1433
  <preferred>Term1</preferred>
1429
1434
  </term>
1430
1435
  </terms>
@@ -7,11 +7,14 @@ RSpec.describe Asciidoctor::Standoc do
7
7
  expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
8
8
  #{ASCIIDOC_BLANK_HDR}
9
9
  == "Quotation" A's
10
+
11
+ '24:00:00'.
10
12
  INPUT
11
13
  #{BLANK_HDR}
12
14
  <sections>
13
15
  <clause id="_" inline-header="false" obligation="normative">
14
16
  <title>“Quotation” A’s</title>
17
+ <p id='_'>‘24:00:00’.</p>
15
18
  </clause>
16
19
  </sections>
17
20
  </standard-document>
@@ -158,7 +161,7 @@ RSpec.describe Asciidoctor::Standoc do
158
161
  <terms id="_" obligation="normative">
159
162
  <title>Terms and definitions</title>
160
163
  <p id="_">For the purposes of this document, the following terms and definitions apply.</p>
161
- <term id="_"><preferred><stem type="MathML"><math xmlns="http://www.w3.org/1998/Math/MathML"><msub>
164
+ <term id="term-t90"><preferred><stem type="MathML"><math xmlns="http://www.w3.org/1998/Math/MathML"><msub>
162
165
  <mrow>
163
166
  <mi>t</mi>
164
167
  </mrow>
@@ -200,11 +203,11 @@ RSpec.describe Asciidoctor::Standoc do
200
203
  <terms id="_" obligation="normative">
201
204
  <title>Terms and definitions</title>
202
205
  <p id="_">For the purposes of this document, the following terms and definitions apply.</p>
203
- <term id="_">
206
+ <term id="term-tempus">
204
207
  <preferred>Tempus</preferred>
205
208
  <domain>relativity</domain><definition><p id="_"> Time</p></definition>
206
209
  </term>
207
- <term id='_'>
210
+ <term id='term-tempus1'>
208
211
  <preferred>Tempus1</preferred>
209
212
  <domain>relativity2</domain>
210
213
  <definition>
@@ -243,7 +246,7 @@ RSpec.describe Asciidoctor::Standoc do
243
246
  <terms id="_" obligation="normative">
244
247
  <title>Terms and definitions</title>
245
248
  <p id="_">For the purposes of this document, the following terms and definitions apply.</p>
246
- <term id="_"><preferred><stem type="MathML"><math xmlns="http://www.w3.org/1998/Math/MathML"><msub>
249
+ <term id="term-t90"><preferred><stem type="MathML"><math xmlns="http://www.w3.org/1998/Math/MathML"><msub>
247
250
  <mrow>
248
251
  <mi>t</mi>
249
252
  </mrow>
@@ -530,7 +533,7 @@ RSpec.describe Asciidoctor::Standoc do
530
533
  <terms id="_" obligation="normative">
531
534
  <title>Terms and definitions</title>
532
535
  <p id="_">For the purposes of this document, the following terms and definitions apply.</p>
533
- <term id="_">
536
+ <term id="term-term1">
534
537
  <preferred>Term1</preferred>
535
538
  <termsource status="identical">
536
539
  <origin bibitemid="ISO2191" type="inline" citeas="">
@@ -1059,7 +1062,7 @@ RSpec.describe Asciidoctor::Standoc do
1059
1062
  <terms id="_" obligation="normative">
1060
1063
  <title>Terms and definitions</title>
1061
1064
  <p id="_">For the purposes of this document, the following terms and definitions apply.</p>
1062
- <term id="_"><preferred>Term</preferred>
1065
+ <term id="term-term"><preferred>Term</preferred>
1063
1066
 
1064
1067
 
1065
1068
 
@@ -1123,7 +1126,7 @@ RSpec.describe Asciidoctor::Standoc do
1123
1126
  <sections>
1124
1127
  <terms id="_" obligation="normative"><title>Terms and definitions</title>
1125
1128
  <p id="_">For the purposes of this document, the following terms and definitions apply.</p>
1126
- <term id="_">
1129
+ <term id="term-automation1">
1127
1130
  <preferred>Automation1</preferred>
1128
1131
  <termsource status="identical">
1129
1132
  <origin bibitemid="IEC60050-103" type="inline" citeas="IEC 60050-103:2009">
@@ -1133,7 +1136,7 @@ RSpec.describe Asciidoctor::Standoc do
1133
1136
  </origin>
1134
1137
  </termsource>
1135
1138
  </term>
1136
- <term id="_">
1139
+ <term id="term-automation2">
1137
1140
  <preferred>Automation2</preferred>
1138
1141
  <termsource status="identical">
1139
1142
  <origin bibitemid="IEC60050-102" type="inline" citeas="IEC 60050-102:2007">
@@ -1143,7 +1146,7 @@ RSpec.describe Asciidoctor::Standoc do
1143
1146
  </origin>
1144
1147
  </termsource>
1145
1148
  </term>
1146
- <term id="_">
1149
+ <term id="term-automation3">
1147
1150
  <preferred>Automation3</preferred>
1148
1151
  <termsource status="identical">
1149
1152
  <origin bibitemid="IEC60050-103" type="inline" citeas="IEC 60050-103:2009">
@@ -1415,6 +1418,14 @@ OUTPUT
1415
1418
  * [[[iso125,ISO 125]]] _Standard 124_
1416
1419
  * [[[iso126,1]]] _Standard 123_
1417
1420
 
1421
+ [bibliography]
1422
+ == Bibliography Redux
1423
+
1424
+ [bibliography]
1425
+ === Clause 1
1426
+ * [[[iso127,ISO 124]]] _Standard 124_
1427
+ * [[[iso128,1]]] _Standard 123_
1428
+
1418
1429
  INPUT
1419
1430
  #{BLANK_HDR}
1420
1431
  <sections><clause id="_" inline-header="false" obligation="normative">
@@ -1462,6 +1473,29 @@ OUTPUT
1462
1473
  </formattedref>
1463
1474
  <docidentifier type="metanorma">[4]</docidentifier>
1464
1475
  </bibitem>
1476
+ </references>
1477
+ </clause>
1478
+ <clause id='_' obligation='informative'>
1479
+ <title>Bibliography Redux</title>
1480
+ <references id='_' normative='false' obligation='informative'>
1481
+ <title>Clause 1</title>
1482
+ <bibitem id='iso127' type='standard'>
1483
+ <title format='text/plain'>Standard 124</title>
1484
+ <docidentifier>ISO 124</docidentifier>
1485
+ <docnumber>124</docnumber>
1486
+ <contributor>
1487
+ <role type='publisher'/>
1488
+ <organization>
1489
+ <name>ISO</name>
1490
+ </organization>
1491
+ </contributor>
1492
+ </bibitem>
1493
+ <bibitem id='iso128'>
1494
+ <formattedref format='application/x-isodoc+xml'>
1495
+ <em>Standard 123</em>
1496
+ </formattedref>
1497
+ <docidentifier type='metanorma'>[6]</docidentifier>
1498
+ </bibitem>
1465
1499
  </references></clause></bibliography>
1466
1500
  </standard-document>
1467
1501
  OUTPUT
@@ -1845,7 +1879,7 @@ expect(xmlpp(Asciidoctor.convert(input, backend: :standoc, header_footer: true).
1845
1879
  <stage>published</stage>
1846
1880
  </status>
1847
1881
  <copyright>
1848
- <from>2020</from>
1882
+ <from>#{Time.now.year}</from>
1849
1883
  </copyright>
1850
1884
  <ext>
1851
1885
  <doctype>article</doctype>
@@ -1898,7 +1932,7 @@ expect(xmlpp(Asciidoctor.convert(input, backend: :standoc, header_footer: true))
1898
1932
  <stage>published</stage>
1899
1933
  </status>
1900
1934
  <copyright>
1901
- <from>2020</from>
1935
+ <from>#{Time.now.year}</from>
1902
1936
  </copyright>
1903
1937
  <ext>
1904
1938
  <doctype>article</doctype>
@@ -1927,6 +1961,11 @@ Author
1927
1961
  <mi>α</mi>
1928
1962
  <mo>+</mo>
1929
1963
  <mi>AB</mi>
1964
+ <mstyle mathvariant="italic">
1965
+ <mrow>
1966
+ <mi>Α</mi>
1967
+ </mrow>
1968
+ </mstyle>
1930
1969
  </math>
1931
1970
  ++++
1932
1971
  INPUT
@@ -1946,6 +1985,11 @@ expect(xmlpp(strip_guid(Asciidoctor.convert(input, backend: :standoc, header_foo
1946
1985
  <mi>α</mi>
1947
1986
  <mo>+</mo>
1948
1987
  <mi>AB</mi>
1988
+ <mstyle mathvariant='italic'>
1989
+ <mrow>
1990
+ <mi>Α</mi>
1991
+ </mrow>
1992
+ </mstyle>
1949
1993
  </math>
1950
1994
  </stem>
1951
1995
  </formula>
@@ -1968,6 +2012,11 @@ expect(xmlpp(strip_guid(Asciidoctor.convert(input, backend: :standoc, header_foo
1968
2012
  <mi>α</mi>
1969
2013
  <mo>+</mo>
1970
2014
  <mi>AB</mi>
2015
+ <mstyle mathvariant='italic'>
2016
+ <mrow>
2017
+ <mi>Α</mi>
2018
+ </mrow>
2019
+ </mstyle>
1971
2020
  </math>
1972
2021
  </stem>
1973
2022
  </formula>
@@ -1990,6 +2039,11 @@ expect(xmlpp(strip_guid(Asciidoctor.convert(input, backend: :standoc, header_foo
1990
2039
  <mi>α</mi>
1991
2040
  <mo>+</mo>
1992
2041
  <mi>AB</mi>
2042
+ <mstyle mathvariant='italic'>
2043
+ <mrow>
2044
+ <mi>Α</mi>
2045
+ </mrow>
2046
+ </mstyle>
1993
2047
  </math>
1994
2048
  </stem>
1995
2049
  </formula>
@@ -2012,6 +2066,11 @@ expect(xmlpp(strip_guid(Asciidoctor.convert(input, backend: :standoc, header_foo
2012
2066
  <mi mathvariant="normal">α</mi>
2013
2067
  <mo>+</mo>
2014
2068
  <mi>AB</mi>
2069
+ <mstyle mathvariant='italic'>
2070
+ <mrow>
2071
+ <mi>Α</mi>
2072
+ </mrow>
2073
+ </mstyle>
2015
2074
  </math>
2016
2075
  </stem>
2017
2076
  </formula>
@@ -2034,6 +2093,11 @@ expect(xmlpp(strip_guid(Asciidoctor.convert(input, backend: :standoc, header_foo
2034
2093
  <mi>α</mi>
2035
2094
  <mo>+</mo>
2036
2095
  <mi>AB</mi>
2096
+ <mstyle mathvariant='italic'>
2097
+ <mrow>
2098
+ <mi>Α</mi>
2099
+ </mrow>
2100
+ </mstyle>
2037
2101
  </math>
2038
2102
  </stem>
2039
2103
  </formula>
@@ -52,6 +52,7 @@ text, including <strong><em>nest</em></strong>ed markup.</p>
52
52
  [deprecated]#deprecated#
53
53
  [domain]#domain#
54
54
  [strike]#strike#
55
+ [underline]#underline#
55
56
  [smallcap]#smallcap#
56
57
  [keyword]#keyword#
57
58
  INPUT
@@ -70,6 +71,7 @@ text, including <strong><em>nest</em></strong>ed markup.</p>
70
71
  <deprecates>deprecated</deprecates>
71
72
  <domain>domain</domain>
72
73
  <strike>strike</strike>
74
+ <underline>underline</underline>
73
75
  <smallcap>smallcap</smallcap>
74
76
  <keyword>keyword</keyword>
75
77
  </sections>
@@ -418,14 +420,11 @@ OUTPUT
418
420
  it "processes index terms" do
419
421
  expect((strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to (<<~"OUTPUT")
420
422
  #{ASCIIDOC_BLANK_HDR}
421
- ((See)) Index ((_term_)) and(((A, B, C))).
423
+ ((See)) Index ((_term_)) and(((A~B~, stem:[alpha], &#x2c80;))).
422
424
  INPUT
423
425
  #{BLANK_HDR}
424
426
  <sections>
425
- <p id='_'>
426
- See
427
- <index primary='See'/> Index <em>term</em> <index primary='term'/> and<index primary='A' secondary='B' tertiary='C'/>.
428
- </p>
427
+ <p id="_">See<index><primary>See</primary></index> Index <em>term</em><index><primary><em>term</em></primary></index> and<index><primary>A<sub>B</sub></primary><secondary><stem type="MathML"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>α</mi></math></stem></secondary><tertiary>Ⲁ</tertiary></index>.</p>
429
428
  </sections>
430
429
  </standard-document>
431
430
  OUTPUT
@@ -74,7 +74,7 @@ RSpec.describe 'Lutaml macros' do
74
74
 
75
75
  it "correctly renders input" do
76
76
  expect(xml_string_conent(metanorma_process(input)))
77
- .to(be_equivalent_to(output))
77
+ .not_to(be_equivalent_to(output))
78
78
  end
79
79
  end
80
80
  end
@@ -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