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 output = <<~OUTPUT <strong>Annex A</strong> <br/> (normative). <tab/> Clause

Text

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

Text

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

Text

OUTPUT expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true)) .sub(%r{.*}m, "")) .to be_equivalent_to xmlpp(output) 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 private def mock_symbols allow_any_instance_of(::IsoDoc::PresentationXMLConvert) .to receive(:twitter_cldr_localiser_symbols).and_return(group: "'") end end