require "spec_helper"
RSpec.describe Asciimath2UnitsML do
it "converts an AsciiMath string to MathML + UnitsML" do
expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
32 + 5 xx 7 "unitsml(kg^-2)" xx 9 "unitsml(g)" xx 1 "unitsml(kg*s^-2)" xx 812 "unitsml(m*s^-2)" - 9 "unitsml(C^3*A)" + 7 "unitsml(hp)"
INPUT
OUTPUT
end
it "raises error for illegal unit" do
expect{xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))}.to raise_error(Rsec::SyntaxError)
12 "unitsml(que?)"
INPUT
end
it "initialises multiplier" do
expect(xmlpp(Asciimath2UnitsML::Conv.new(multiplier: "\u00d7").Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
1 "unitsml(kg*s^-2)"
INPUT
1kg×s−2kg*s^-2
kg×s
−2kg×s−2kilok
OUTPUT
expect(xmlpp(Asciimath2UnitsML::Conv.new(multiplier: :space).Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
1 "unitsml(kg*s^-2)"
INPUT
1kgs−2kg*s^-2
kg s
−2kgs−2kilok
OUTPUT
expect(xmlpp(Asciimath2UnitsML::Conv.new(multiplier: :nospace).Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
1 "unitsml(kg*s^-2)"
INPUT
1kgs−2kg*s^-2
kgs
−2kgs−2kilok
OUTPUT
end
end