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 expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}).convert("test", <<~INPUT, true)).sub(%r{.*}m, "")).to be_equivalent_to xmlpp(<<~OUTPUT) test

30000 PXXmax=j=Xmax10001000jpj1p1.003j

INPUT test

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

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 expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}).convert("test", <<~INPUT, true)).sub(%r{.*}m, "")).to be_equivalent_to xmlpp(<<~OUTPUT) test fr

30000 PXXmax=j=Xmax10001000jpj1p1.003j

INPUT test fr

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

OUTPUT end it "customises localisation of numbers" do mock_symbols expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}).convert("test", <<~INPUT, true)).sub(%r{.*}m, "")).to be_equivalent_to xmlpp(<<~OUTPUT) test fr

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

INPUT 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 end private def mock_symbols allow_any_instance_of(::IsoDoc::PresentationXMLConvert).to receive(:twitter_cldr_localiser_symbols).and_return(group: "'") end end