require 'rspec'
require 'asciimath'
TEST_CASES = {
'x+b/(2a)<+-sqrt((b^2)/(4a^2)-c/a)' =>
'',
'a^2 + b^2 = c^2' =>
'',
'x = (-b+-sqrt(b^2-4ac))/(2a)' =>
'',
'm = (y_2 - y_1)/(x_2 - x_1) = (Deltay)/(Deltax)' =>
'',
'f\'(x) = lim_(Deltax->0)(f(x+Deltax)-f(x))/(Deltax)' =>
'',
'd/dx [x^n] = nx^(n - 1)' =>
'',
'int_a^b f(x) dx = [F(x)]_a^b = F(b) - F(a)' =>
'',
'int_a^b f(x) dx = f(c)(b - a)' =>
'',
'ax^2 + bx + c = 0' =>
'',
'"average value"=1/(b-a) int_a^b f(x) dx' =>
'',
'd/dx[int_a^x f(t) dt] = f(x)' =>
'',
'hat(ab) bar(xy) ul(A) vec(v)' =>
'',
'z_12^34' =>
'',
'lim_(x->c)(f(x)-f(c))/(x-c)' =>
'',
'int_0^(pi/2) g(x) dx' =>
'',
'sum_(n=0)^oo a_n' =>
'',
'((1,2,3),(4,5,6),(7,8,9))' =>
'',
'|(a,b),(c,d)|=ad-bc' =>
'',
'((a_(11), cdots , a_(1n)),(vdots, ddots, vdots),(a_(m1), cdots , a_(mn)))' =>
'',
'sum_(k=1)^n k = 1+2+ cdots +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):}', ''
end
end