]> git.lyx.org Git - lyx.git/blob - lib/lyx2lyx/test_parser_tools.py
Execute lyx2lyx unit test when running tests
[lyx.git] / lib / lyx2lyx / test_parser_tools.py
1 # This file is part of lyx2lyx
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2006 José Matos <jamatos@lyx.org>
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18
19 " This modules tests the functions used to help parse lines."
20
21 from parser_tools import *
22
23 import unittest
24
25 ug = r"""
26 \begin_layout Standard
27 The
28 \begin_inset Quotes eld
29 \end_inset
30
31
32 \emph on
33 Introduction
34 \emph default
35
36 \begin_inset Quotes erd
37 \end_inset
38
39  describes several things in addition to LyX's philosophy: most importantly,
40  the format of all of the manuals.
41  If you don't read it, you'll have a bear of a time navigating this manual.
42  You might also be better served looking in one of the other manuals instead
43  of this one.
44
45 \begin_inset Quotes eld
46 \end_inset
47
48
49 \emph on
50 Introduction
51 \emph default
52
53 \begin_inset Quotes erd
54 \end_inset
55
56  describes that, too.
57 \end_layout
58
59 """
60
61 lines = ug.splitlines()
62
63 class TestParserTools(unittest.TestCase):
64
65     def test_check_token(self):
66         line = "\\begin_layout Standard"
67
68         self.assertEquals(check_token(line, '\\begin_layout'), True)
69         self.assertEquals(check_token(line, 'Standard'), False)
70
71
72     def test_is_nonempty_line(self):
73         self.assertEquals(is_nonempty_line(lines[0]), False)
74         self.assertEquals(is_nonempty_line(lines[1]), True)
75         self.assertEquals(is_nonempty_line(" "*5), False)
76
77
78     def test_find_token(self):
79         self.assertEquals(find_token(lines, '\\emph', 0), 7)
80         self.assertEquals(find_token(lines, '\\emph', 0, 5), -1)
81         self.assertEquals(find_token(lines, '\\emp', 0, 0, True), -1)
82         self.assertEquals(find_token(lines, '\\emp', 0, 0, False), 7)
83         self.assertEquals(find_token(lines, 'emph', 0), -1)
84
85
86     def test_find_tokens(self):
87         tokens = ['\\emph', '\\end_inset']
88         self.assertEquals(find_tokens(lines, tokens, 0), 4)
89         self.assertEquals(find_tokens(lines, tokens, 0, 4), -1)
90
91
92 if __name__ == '__main__':  
93     unittest.main()