File: parser.py

package info (click to toggle)
rubber 1.6.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,556 kB
  • sloc: python: 3,844; sh: 172; makefile: 31
file content (71 lines) | stat: -rw-r--r-- 1,970 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# SPDX-License-Identifier: GPL-3.0-or-later
# vim: noet:ts=4
from rubber.tex import *
import unittest


class TestTexParser(unittest.TestCase):

    def assert_cseq(self, val):
        t = self.p.get_token()
        self.assertEqual(t.cat, CSEQ)
        self.assertEqual(t.val, val)

    def assert_latex_optional_text(self, ot):
        self.assertEqual(self.p.get_latex_optional_text(), ot)

    def assert_argument_text(self, at):
        self.assertEqual(self.p.get_argument_text(), at)

    def assert_eof(self):
        self.assertEqual(self.p.get_token().cat, EOF)


class TestMacroWithArgument(TestTexParser):

    def run_it(self, c):
        self.p = parse_string(c)
        self.assert_cseq("usepackage")
        self.assert_argument_text("aloha4")
        self.assert_eof()

    def test_latexmacro1(self):
        self.run_it("\\usepackage{aloha4}")

    def test_latexmacro2(self):
        self.run_it("\\usepackage {aloha4}")

    def test_latexmacro3(self):
        self.run_it("\\usepackage%comment\n{aloha4}")

    def test_latexmacro4(self):
        self.run_it("\\usepackage\n%comment\n{aloha4}")


class TestMacroWithLatexOptional(TestTexParser):

    def run_it(self, c):
        self.p = parse_string(c)
        self.assert_cseq("usepackage")
        self.assert_latex_optional_text("aloha1,aloha2=aloha3")
        self.assert_argument_text("aloha4")
        self.assert_eof()

    def test_latexmacro1(self):
        self.run_it("\\usepackage[aloha1,aloha2=aloha3]{aloha4}")

    def test_latexmacro2(self):
        self.run_it("\\usepackage [aloha1,aloha2=aloha3] {aloha4}")

    def test_latexmacro3(self):
        self.run_it("\\usepackage%comment\n[aloha1,aloha2=aloha3]%comment\n{aloha4}")

    def test_latexmacro4(self):
        self.run_it("\\usepackage\n[aloha1,aloha2=aloha3]{aloha4}")

    def test_latexmacro5(self):
        self.run_it("\\usepackage[aloha1,aloha2=aloha3]\n{aloha4}")


if __name__ == '__main__':
    unittest.main()