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

... 64212149677264515 642121496772645.15 30000 PXXmax=j=Xmax10001000jpj1p1.003j

INPUT output = <<~OUTPUT test

... 64,212,149,677,264,515 642,121,496,772,645.15 30,000 P X X max = j = X max 1,000 1,000 j p j 1 p 1.003 j

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

30000 P X X max = j = X max 1000 1000 j p j 1 p 1.003 j 1 p 459384.123456789 j

INPUT end let(:output) do <<~OUTPUT test

30,000 P X X max = j = X max 1,000 1,000 j p j 1 p 1.00'3 j 1 p 459,384.12'34'56 j

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 test fr

30000 PXXmax=j=Xmax10001000jpj1p1.003j

INPUT output = <<~OUTPUT test fr

30 000 P X X max = j = X max 1 000 1 000 j p j 1 p 1,003 j

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 test fr

30000 PXXmax=j=Xmax10001000jpj0.0000032p1.003j

INPUT output = <<~OUTPUT test fr

30'000 P X X max = j = X max 1'000 1'000 j p j 0,0000032 p 1,003 j

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 Flintstone Slate Rock and Gravel Company
1 Infinity Loop Cupertino CA USA 95014
INPUT output = <<~OUTPUT Fred Flintstone Slate 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 x

Text

Clause Clause A x

Text

INPUT presxml = <<~OUTPUT <strong>Annex A</strong> <br/> (normative). <tab/> Clause

Text

<strong>Annex A</strong> <br/> (normative). <tab/> Subclause “A” ‘B’ Clause A x

Text

<strong>Annex A</strong> <br/> (normative) <br/> <br/> <strong>Clause</strong> Clause A x

Text

OUTPUT html = <<~OUTPUT

 


 


Annex A
(normative).   Clause

Text

Annex A
(normative).   Subclause

“A” ‘B’

Text


Annex A
(normative)

Clause

Text

OUTPUT doc = <<~OUTPUT

 


 


Annex A
(normative).   Clause

Text

Annex A
(normative).   Subclause

“A” ‘B’

Text


Annex A
(normative)

Clause

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
1 2 3 4
INPUT output = <<~OUTPUT 1.<tab/>Clause
Figure 1 1 2 3 4
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
  1. A1
    1. A2
      1. A3
        1. A4
          1. A5
            1. A6
              1. A7
                1. A8
                  1. A9
                    1. A0
#{' '} INPUT presxml = <<~OUTPUT 1. <tab/> Clause
  1. A1
    1. A2
      1. A3
        1. A4
          1. A5
            1. A6
              1. A7
                1. A8
                  1. A9
                    1. 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
  1. A1
    • A2
      1. A3
INPUT presxml = <<~OUTPUT 1. <tab/> Clause
  1. A1
    • A2
      1. 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 figures List of tables List 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

text text

INPUT presxml = <<~OUTPUT 1. <tab/> 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
First
Second
Unnamed
Third
INPUT presxml = <<~OUTPUT 1. <tab/> Section
Figure 1 — First
EXAMPLE 1
Figure 2 — Second
EXAMPLE 2
Unnamed
Figure 3 — Third
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
First
INPUT presxml = <<~OUTPUT font-license-agreement no-install-fonts fonts font2 fonts font1 1. <tab/> Section
Figure 1 — First
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.

INPUT presxml = <<~OUTPUT 1. <tab/> Scope

A

ISO 639-2

2. <tab/> Terms and definitions

No terms and definitions are listed in this document.

OUTPUT expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true)) .sub(%r{.*}m, "")) .to be_equivalent_to xmlpp(presxml) end private def mock_symbols allow_any_instance_of(::IsoDoc::PresentationXMLConvert) .to receive(:twitter_cldr_localiser_symbols).and_return(group: "'") end end