]> git.lyx.org Git - lyx.git/blob - lib/lyx2lyx/test_lyx2lyx_tools.py
Move DrawStrategy enum to update_flags.h.
[lyx.git] / lib / lyx2lyx / test_lyx2lyx_tools.py
1 # This file is part of lyx2lyx
2 # Copyright (C) 2018 The LyX team
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17
18 "This modules tests the auxiliary functions for lyx2lyx."
19
20 import unittest
21
22 from lyx2lyx_tools import latex_length, put_cmd_in_ert
23
24
25 class TestParserTools(unittest.TestCase):
26     def test_put_cmd_in_ert(self):
27         ert = [
28             "\\begin_inset ERT",
29             "status collapsed",
30             "",
31             "\\begin_layout Plain Layout",
32             "",
33             "",
34             "\\backslash",
35             "texttt{Gr",
36             "\\backslash",
37             '"{u}',
38             "\\backslash",
39             "ss{}e}",
40             "\\end_layout",
41             "",
42             "\\end_inset",
43         ]
44         ert_open = ert[:]
45         ert_open[1] = "status open"
46         ert_paragraph = [
47             "\\begin_layout Standard",
48             "\\begin_inset ERT",
49             "status collapsed",
50             "",
51             "\\begin_layout Plain Layout",
52             "",
53             "",
54             "\\backslash",
55             "texttt{Gr",
56             "\\backslash",
57             '"{u}',
58             "\\backslash",
59             "ss{}e}",
60             "\\end_layout",
61             "",
62             "\\end_inset",
63             "",
64             "",
65             "\\end_layout",
66             "",
67         ]
68         self.assertEqual(put_cmd_in_ert("\\texttt{Grüße}"), ert)
69         self.assertEqual(put_cmd_in_ert(["\\texttt{Grüße}"]), ert)
70         self.assertEqual(put_cmd_in_ert("\\texttt{Grüße}", is_open=True), ert_open)
71         self.assertEqual(put_cmd_in_ert("\\texttt{Grüße}", as_paragraph=True), ert_paragraph)
72
73     def test_latex_length(self):
74         self.assertEqual(latex_length("-30.5col%"), (True, "-0.305\\columnwidth"))
75         self.assertEqual(latex_length("35baselineskip%"), (True, "0.35\\baselineskip"))
76         self.assertEqual(latex_length("11em"), (False, "11em"))
77         self.assertEqual(latex_length("-0.4pt"), (False, "-0.4pt"))
78
79
80 if __name__ == "__main__":
81     unittest.main()