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