package texmath
import (
"encoding/xml"
"errors"
"io"
"regexp"
"strings"
"testing"
"time"
)
func TestConvert(t *testing.T) {
cases := []struct {
tex, want string
}{
{`x`, ``},
{`12.5+x`, ``},
{`a-b`, ``},
{`x^2`, ``},
{`x_i^2`, ``},
{`x^{2n}`, ``},
{`\frac{a}{b}`, ``},
{`\frac12`, ``},
{`\sqrt{x}`, ``},
{`\sqrt[3]{x}`, ``},
{`\alpha\Gamma`, ``},
{`a\le b`, ``},
{`(a)`, ``},
{`\left( x \right.`, ``},
{`\left\{ x \middle| y \right\}`, ``},
{`\sin x`, ``},
{`\sin(x)`, ``},
{`\text{if } x`, ``},
{`\mathbb{R}\mathbf{v}`, ``},
{`\mathrm{d}x`, ``},
{`\hat{x}`, ``},
{`a\,b`, ``},
{`\binom{n}{k}`, ``},
{`\begin{pmatrix}a&b\\c&d\end{pmatrix}`, ``},
{`\begin{matrix}a\\\end{matrix}`, ``},
{`x % comment` + "\n" + `+1`, ``},
{`aa<b`},
}
for _, c := range cases {
got, err := Convert(c.tex, false)
if err != nil {
t.Errorf("Convert(%q): %v", c.tex, err)
continue
}
if got != c.want {
t.Errorf("Convert(%q)\n got %s\nwant %s", c.tex, got, c.want)
}
}
}
func TestConvertDisplayLimits(t *testing.T) {
got, err := Convert(`\sum_{i=1}^n i`, true)
if err != nil {
t.Fatal(err)
}
if !strings.HasPrefix(got, `