require "spec_helper"
RSpec.describe IsoDoc do
it "generates file based on string input" do
FileUtils.rm_f "test.presentation.xml"
IsoDoc::PresentationXMLConvert.new({ filename: "test" })
.convert("test", <<~"INPUT", false)
test
These results are based on a study carried out on three different types of kernel.
INPUT
expect(File.exist?("test.presentation.xml")).to be true
end
it "localises numbers in MathML" do
input = <<~INPUT
test
OUTPUT
expect(xmlpp(IsoDoc::PresentationXMLConvert.new({})
.convert("test", input, true))
.sub(%r{.*}m, ""))
.to be_equivalent_to xmlpp(output)
end
context "when twitter_cldr_localiser_symbols has additional options" do
let(:input) do
<<~INPUT
test
INPUT
end
let(:output) do
<<~OUTPUT
test
30,000
OUTPUT
end
let(:additional_symbols) do
{
fraction_group_digits: 2,
fraction_group: "'",
precision: 5,
}
end
before do
allow_any_instance_of(IsoDoc::PresentationXMLConvert)
.to(receive(:twitter_cldr_localiser_symbols)
.and_return(additional_symbols))
end
it "Supports twitter_cldr_localiser_symbols fraction options" do
expect(xmlpp(IsoDoc::PresentationXMLConvert.new({})
.convert("test", input, true))
.sub(%r{.*}m, ""))
.to(be_equivalent_to(xmlpp(output)))
end
end
it "localises numbers in MathML in French" do
input = <<~INPUT
testfr
INPUT
output = <<~OUTPUT
testfr
30 000
OUTPUT
expect(xmlpp(IsoDoc::PresentationXMLConvert.new({})
.convert("test", input, true))
.sub(%r{.*}m, ""))
.to be_equivalent_to xmlpp(output)
end
it "customises localisation of numbers" do
mock_symbols
input = <<~INPUT
testfr
INPUT
output = <<~OUTPUT
testfr
30'000
OUTPUT
expect(xmlpp(IsoDoc::PresentationXMLConvert.new({})
.convert("test", input, true))
.sub(%r{.*}m, ""))
.to be_equivalent_to xmlpp(output)
end
it "resolve address components" do
input = <<~INPUT
Fred FlintstoneSlate Rock and Gravel Company1 Infinity LoopCupertinoCAUSA95014
INPUT
output = <<~OUTPUT
Fred FlintstoneSlate Rock and Gravel Company
1 Infinity Loop
Cupertino
CA
USA 95014
OUTPUT
expect(xmlpp(IsoDoc::PresentationXMLConvert.new({})
.convert("test", input, true))
.sub(%r{.*}m, ""))
.to be_equivalent_to xmlpp(output)
end
it "strips variant-title" do
input = <<~INPUT
Clause
Text
Subclause“A” ‘B’
Clause
A
Text
Clause
Clause
A
Text
INPUT
presxml = <<~OUTPUT
Annex A
(normative).
Clause
Text
Annex A
(normative).
Subclause
“A” ‘B’
Clause
A
Text
Annex A
(normative)
Clause
Clause
A
Text
OUTPUT
html = <<~OUTPUT
Annex A
(normative). Clause
Text
Annex A
(normative). Subclause
“A” ‘B’
Clause
A
Text
Annex A
(normative)
Clause
Clause
A
Text
OUTPUT
doc = <<~OUTPUT
Annex A
(normative).
Clause
Text
Annex A
(normative).
Subclause
“A” ‘B’
Clause
A
Text
Annex A
(normative)
Clause
Clause
A
Text
OUTPUT
expect(xmlpp(IsoDoc::PresentationXMLConvert.new({})
.convert("test", input, true))
.sub(%r{.*}m, ""))
.to be_equivalent_to xmlpp(presxml)
expect(xmlpp(IsoDoc::HtmlConvert.new({})
.convert("test", presxml, true))).to be_equivalent_to xmlpp(html)
expect(xmlpp(IsoDoc::WordConvert.new({})
.convert("test", presxml, true))).to be_equivalent_to xmlpp(doc)
end
it "duplicates EMF and SVG files" do
input = <<~INPUT
Clause
INPUT
output = <<~OUTPUT
1.Clause
OUTPUT
expect(IsoDoc::PresentationXMLConvert.new({})
.convert("test", input, true)
.sub(%r{.*}m, "")
.gsub(%r{"data:application/x-msmetafile;base64,[^"]+"},
'"data:application/x-msmetafile;base64"'))
.to be_equivalent_to (output)
end
it "adds types to ordered lists" do
input = <<~INPUT
Clause
A1
A2
A3
A4
A5
A6
A7
A8
A9
A0
#{' '}
INPUT
presxml = <<~OUTPUT
1.
Clause
A1
A2
A3
A4
A5
A6
A7
A8
A9
A0
OUTPUT
expect(xmlpp(IsoDoc::PresentationXMLConvert.new({})
.convert("test", input, true))
.sub(%r{.*}m, ""))
.to be_equivalent_to xmlpp(presxml)
end
it "considers ul when adding types to ordered lists" do
input = <<~INPUT
Clause
A1
A2
A3
INPUT
presxml = <<~OUTPUT
1.
Clause
A1
A2
A3
OUTPUT
expect(xmlpp(IsoDoc::PresentationXMLConvert.new({})
.convert("test", input, true))
.sub(%r{.*}m, ""))
.to be_equivalent_to xmlpp(presxml)
end
it "inserts toc metadata" do
input = <<~INPUT
INPUT
presxml = <<~OUTPUT
List of figuresList of tablesList of recommendations
OUTPUT
expect(xmlpp(IsoDoc::PresentationXMLConvert
.new({ tocfigures: true,
toctables: true,
tocrecommendations: true })
.convert("test", input, true))
.sub(%r{.*}m, ""))
.to be_equivalent_to xmlpp(presxml)
end
it "processes multiple-target xrefs" do
input = <<~INPUT
Section
texttext
INPUT
presxml = <<~OUTPUT
1.
Section
Clause 2 to 3
text
Clause 2 and 3
Clause 2, 3, and 4
text
Clause 2 or 3
Clause 2, 3, or 4
Clause 2 to 3 and 4 to 5
2.3.4.5.
OUTPUT
expect(xmlpp(IsoDoc::PresentationXMLConvert.new({})
.convert("test", input, true))
.sub(%r{.*}m, ""))
.to be_equivalent_to xmlpp(presxml)
end
it "captions embedded figures" do
input = <<~INPUT
Section
INPUT
presxml = <<~OUTPUT
1.
Section
EXAMPLE 1EXAMPLE 2
OUTPUT
expect(xmlpp(IsoDoc::PresentationXMLConvert.new({})
.convert("test", input, true))
.sub(%r{.*}m, ""))
.to be_equivalent_to xmlpp(presxml)
end
it "passes font names to Presentation XML" do
input = <<~INPUT
Section
INPUT
presxml = <<~OUTPUT
font-license-agreementno-install-fontsfontsfont2fontsfont1
1.
Section
OUTPUT
expect(xmlpp(IsoDoc::PresentationXMLConvert
.new({ fonts: "font1; font2", fontlicenseagreement: "no-install-fonts" })
.convert("test", input, true))
.sub(%r{.*}m, ""))
.to be_equivalent_to xmlpp(presxml)
end
it "skips numbering of hidden sections" do
input = <<~INPUT
Scope
A
Terms and definitions
No terms and definitions are listed in this document.