require "spec_helper" RSpec.describe MathML2AsciiMath do it "processes mstyle and mrow" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip.strip a x2 +b×x +c3 INPUT a diamond x^2 + b xx x + c_3 OUTPUT end it "processes mrow" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip a x2d +b×x +cab INPUT a diamond x^(2d) + b xx x + c_(ab) OUTPUT end it "processes mfrac" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip 1 + 5 2 INPUT ((1 + sqrt(5)))/(2) OUTPUT end it "processes mfenced default" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip a + b INPUT (a + b) OUTPUT end it "processes mfenced with unmatching braces" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.to_s.strip 0 1 INPUT [0,1) OUTPUT end it "processes munderover" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip 0 INPUT int_0^(oo) OUTPUT end it "processes msubsup" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip ab ds INPUT int_(ab)^(ds) OUTPUT end it "processes ubrace" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip x + y + z INPUT ubrace (x + y + z) OUTPUT end it "processes ul" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip x + y + z ̲ INPUT ul (x + y + z) OUTPUT end it "processes underset" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip x + y + z fred INPUT underset(fred)((x + y + z)) OUTPUT end it "processes obrace" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip x + y + z INPUT obrace x + y + z OUTPUT end it "processes hat" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip x + y + z ^ INPUT hat x + y + z OUTPUT end it "processes bar" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip x + y + z ¯ INPUT bar x + y + z OUTPUT end it "processes vec" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip x + y + z INPUT vec x + y + z OUTPUT end it "processes dot" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip x + y + z . INPUT dot x + y + z OUTPUT end it "processes ddot" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip x + y + z .. INPUT ddot x + y + z OUTPUT end it "processes overset" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip x + y + z fred INPUT overset(fred)(x + y + z) OUTPUT end it "processes mtable" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip X = A B C D E F INPUT X = [[A,B],[C,D],[E,F]] OUTPUT end it "processes wrapping element" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip λ ¯ ( t 1 , t 2 ) INPUT bar lambda ( t_1 , t_2 ) OUTPUT end it "processes without xmlns" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip z ¯ ( t 1 , t 2 ) INPUT bar z ( t_1 , t_2 ) OUTPUT end it "processes and skips element" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip z ¯ ( t 1 , t 2 ) MathType@MTEF@5@5@+=feaagCart1ev2aaatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLnhiov2DGi1BTfMBaeXatLxBI9gBaerbbjxAHXgarqqtubsr4rNCHbGeaGqipG0dh9qqWrVepG0dbbL8F4rqqrVepeea0xe9LqFf0xc9q8qqaqFn0lXdHiVcFbIOFHK8Feea0dXdar=Jb9hs0dXdHuk9fr=xfr=xfrpeWZqaaeqabiGaciGacaqadmaadaqaaqaaaOqaaiqadQhagaqeaiaacIcacaWG0bWaaSbaaSqaaiaaigdaaeqaaOGaaiilaiaaysW7caWG0bWaaSbaaSqaaiaaikdaaeqaaOGaaiykaaaa@3DCE@ INPUT bar z ( t_1 , t_2 ) OUTPUT end it "does not include non-significant whitespaces (spaces between nodes)" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip x 1 , x 2 , x n MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbbjxAHX garuavP1wzZbItLDhis9wBH5garmWu51MyVXgarqqtubsr4rNCHbGe aGqipG0dh9qqWrVepG0dbbL8F4rqqrVepeea0xe9LqFf0xc9q8qqaq Fn0lXdHiVcFbIOFHK8Feea0dXdar=Jb9hs0dXdHuk9fr=xfr=xfrpe WZqaaeGaciWaamGadaGadeaabaGaaqaaaOqaaiaadIhadaWgaaWcba GaaGymaaqabaGccaGGSaGaaGjbVlaadIhadaWgaaWcbaGaaGOmaaqa baGccaGGSaGaaGjbVlaaykW7cqWIMaYscaaMc8UaaGPaVlaaysW7ca WG4bWaaSbaaSqaaiaad6gaaeqaaaaa@4713@ INPUT x_1 , x_2 , ... x_n OUTPUT end it "processes unknown MathML" do expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip x + y + z INPUT x + y + z OUTPUT end end