Skip to content

Commit ebb86bc

Browse files
committed
Add parsing test
1 parent 2350bec commit ebb86bc

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

tests/testthat/test-parseLatex.R

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
test_that("parsing works", {
2+
parsed <- parseLatex("{abc}")
3+
expect_equal(latexTag(parsed[[1]]), "BLOCK")
4+
expect_equal(length(parsed), 1)
5+
6+
parsed <- parseLatex("\\begin{center} abc \\end{center}")
7+
expect_true(is_env(parsed[[1]], "center"))
8+
expect_equal(length(parsed), 1)
9+
10+
parsed <- parseLatex("\\texttt abc")
11+
expect_true(is_macro(parsed[[1]], "\\texttt"))
12+
expect_equal(c(parsed[[2]]), "abc")
13+
expect_equal(length(parsed), 2)
14+
15+
parsed <- parseLatex("abc \\foo % def")
16+
expect_equal(c(parsed[[1]]), "abc")
17+
expect_true(is_macro(parsed[[3]], "\\foo"))
18+
expect_equal(latexTag(parsed[[5]]), "COMMENT")
19+
expect_equal(length(parsed), 5)
20+
21+
parsed <- parseLatex("\\verb!abc!\\Sexpr{x$1}")
22+
expect_equal(latexTag(parsed[[1]]), "VERB")
23+
expect_equal(latexTag(parsed[[2]]), "VERB")
24+
expect_equal(length(parsed), 2)
25+
26+
parsed <- parseLatex("\\def\\x3\\def\\y = 4\\newcommand{\\z}{5}")
27+
expect_equal(latexTag(parsed[[1]]), "DEFINITION")
28+
expect_equal(latexTag(parsed[[2]]), "DEFINITION")
29+
expect_equal(latexTag(parsed[[3]]), "DEFINITION")
30+
expect_equal(length(parsed), 3)
31+
32+
parsed <- parseLatex("$x + 3$ $$ x + 4 $$")
33+
expect_equal(latexTag(parsed[[1]]), "MATH")
34+
expect_equal(latexTag(parsed[[2]]), "SPECIAL")
35+
expect_equal(latexTag(parsed[[3]]), "DISPLAYMATH")
36+
expect_equal(length(parsed), 3)
37+
38+
})

0 commit comments

Comments
 (0)