require 'rspec' require 'asciimath' TEST_CASES = { 'x+b/(2a)<+-sqrt((b^2)/(4a^2)-c/a)' => 'x+b2a<±b24a2ca', 'a^2 + b^2 = c^2' => 'a2+b2=c2', 'x = (-b+-sqrt(b^2-4ac))/(2a)' => 'x=b±b2-4ac2a', 'm = (y_2 - y_1)/(x_2 - x_1) = (Deltay)/(Deltax)' => 'm=y2y1x2x1=ΔyΔx', 'f\'(x) = lim_(Deltax->0)(f(x+Deltax)-f(x))/(Deltax)' => 'f\'(x)=limΔx0f(x+Δx)f(x)Δx', 'd/dx [x^n] = nx^(n - 1)' => 'ddx[xn]=nxn1', 'int_a^b f(x) dx = [F(x)]_a^b = F(b) - F(a)' => 'abf(x)dx=[F(x)]ab=F(b)F(a)', 'int_a^b f(x) dx = f(c)(b - a)' => 'abf(x)dx=f(c)(ba)', 'ax^2 + bx + c = 0' => 'ax2+bx+c=0', '"average value"=1/(b-a) int_a^b f(x) dx' => 'average value=1baabf(x)dx', 'd/dx[int_a^x f(t) dt] = f(x)' => 'ddx[axf(t)dt]=f(x)', 'hat(ab) bar(xy) ul(A) vec(v)' => 'ab^xy¯A_v', 'z_12^34' => 'z1234', 'lim_(x->c)(f(x)-f(c))/(x-c)' => 'limxcf(x)f(c)xc', 'int_0^(pi/2) g(x) dx' => '0π2g(x)dx', 'sum_(n=0)^oo a_n' => 'n=0an', '((1,2,3),(4,5,6),(7,8,9))' => '(123456789)', '|(a,b),(c,d)|=ad-bc' => '|abcd|=adbc', '((a_(11), cdots , a_(1n)),(vdots, ddots, vdots),(a_(m1), cdots , a_(mn)))' => '(a11a1nam1amn)', 'sum_(k=1)^n k = 1+2+ cdots +n=(n(n+1))/2' => 'k=1nk=1+2++n=n(n+1)2', } module AsciimathHelper def expect_mathml(asciimath, mathml) expect(Asciimath.parse(asciimath).to_mathml).to eq(mathml) end end RSpec.configure do |c| c.include AsciimathHelper end describe "Asciimath::MathMLBuilder" do TEST_CASES.each_pair do |asciimath, mathml| it "should produce identical output to asciimathml.js for '#{asciimath}'" do expect_mathml(asciimath, mathml) end end it 'should not generate mo elements for {: and :}' do expect_mathml '{:(a,b),(c,d):}', 'abcd' end end