require "spec_helper"
RSpec.describe Metanorma::ISO do
it "processes open blocks" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
--
x
y
z
--
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
x
y
z
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
it "processes stem blocks" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
[stem]
++++
r = 1 %
r = 1 %
++++
[stem]
++++
FΑ
++++
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
it "ignores review blocks unless document is in draft mode" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
[[foreword]]
.Foreword
Foreword
[reviewer=ISO,date=20170101,from=foreword,to=foreword]
****
A Foreword shall appear in each document. The generic text is shown here. It does not contain requirements, recommendations or permissions.
For further information on the Foreword, see *ISO/IEC Directives, Part 2, 2016, Clause 12.*
****
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
Foreword
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
it "processes review blocks if document is in draft mode" do
input = Asciidoctor.convert(<<~"INPUT", *OPTIONS)
= Document title
Author
:docfile: test.adoc
:nodoc:
:novalid:
:draft: 1.2
:no-isobib:
[[foreword]]
.Foreword
Foreword
[reviewer=ISO,date=20170101,from=foreword,to=foreword]
****
A Foreword shall appear in each document. The generic text is shown here. It does not contain requirements, recommendations or permissions.
For further information on the Foreword, see *ISO/IEC Directives, Part 2, 2016, Clause 12.*
****
INPUT
output = <<~OUTPUT
Foreword
A Foreword shall appear in each document. The generic text is shown here. It does not contain requirements, recommendations or permissions.
For further information on the Foreword, see
ISO/IEC Directives, Part 2, 2016, Clause 12.
OUTPUT
expect(xmlpp(strip_guid(input)
.sub(/^.+/m, "")))
.to be_equivalent_to xmlpp(output)
end
it "processes term notes" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
== Terms and Definitions
=== Term1
NOTE: This is a note
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
Terms and definitions
#{TERM_BOILERPLATE}
Term1
This is a note
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
it "processes notes" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
NOTE: This is a note
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
This is a note
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
it "processes literals" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
....
LITERAL
....
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
LITERAL
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
it "processes simple admonitions with Asciidoc names" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
CAUTION: Only use paddy or parboiled rice for the determination of husked rice yield.
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
Only use paddy or parboiled rice for the determination of husked rice yield.
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
it "processes editorial notes" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
[IMPORTANT,type=editorial]
====
Editorial note
====
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
Editorial note
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
it "processes complex admonitions with non-Asciidoc names" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
[CAUTION,type=Safety Precautions]
.Safety Precautions
====
While werewolves are hardy community members, keep in mind the following dietary concerns:
. They are allergic to cinnamon.
. More than two glasses of orange juice in 24 hours makes them howl in harmony with alarms and sirens.
. Celery makes them sad.
====
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
Safety Precautions
While werewolves are hardy community members, keep in mind the following dietary concerns:
They are allergic to cinnamon.
More than two glasses of orange juice in 24 hours makes them howl in harmony with alarms and sirens.
Celery makes them sad.
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
it "processes term examples" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
== Terms and Definitions
=== Term1
[example]
This is an example
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
Terms and definitions
#{TERM_BOILERPLATE}
Term1
This is an example
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
it "processes examples" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
[example]
====
This is an example
Amen
====
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
This is an example
Amen
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
it "processes preambles" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
This is a preamble
== Section 1
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
Foreword
This is a preamble
Section 1
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
it "processes images" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
.Split-it-right sample divider
image::spec/examples/rice_images/rice_image1.png[]
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
Split-it-right sample divider
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
it "accepts width and height attributes on images" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
[height=4,width=3]
image::spec/examples/rice_images/rice_image1.png[]
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
it "accepts auto for width and height attributes on images" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
[height=4,width=auto]
image::spec/examples/rice_images/rice_image1.png[]
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
it "accepts alignment attribute on paragraphs" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
[align=right]
This para is right-aligned.
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
This para is right-aligned.
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
it "processes blockquotes" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
[quote, ISO, "ISO7301,section 1"]
____
Block quotation
____
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
1ISO
Block quotation
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
it "processes source code" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
[source,ruby]
--
puts "Hello, world."
%w{a b c}.each do |x|
puts x
end
--
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
puts "Hello, world."
%w{a b c}.each do |x|
puts x
end
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
it "processes callouts" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
[source,ruby]
--
puts "Hello, world." <1>
%w{a b c}.each do |x|
puts x <2>
end
--
<1> This is one callout
<2> This is another callout
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
puts "Hello, world." 1
%w{a b c}.each do |x|
puts x 2
end
This is one callout
This is another callout
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
it "processes unmodified term sources" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
== Terms and Definitions
=== Term1
Definition
[.source]
<>
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
Terms and definitions
#{TERM_BOILERPLATE}
Term1
Definition
1
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
it "processes modified term sources" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
== Terms and Definitions
=== Term1
Definition
[.source]
<>, with adjustments
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
Terms and definitions
#{TERM_BOILERPLATE}
Term1
Definition
1
with adjustments
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
it "processes the macro for editorial notes" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
EDITOR: Note1
[EDITOR]
====
Note2
====
[EDITOR]
Note3
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
Note1
Note2
Note3
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
end