summaryrefslogtreecommitdiffstats
path: root/python/compare-locales/compare_locales/tests/test_ini.py
blob: 4c8cc03e15950b0b58ea0fe632c74c6e67e88440 (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# -*- coding: utf-8 -*-
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import unittest

from compare_locales.tests import ParserTestMixin


mpl2 = '''\
; This Source Code Form is subject to the terms of the Mozilla Public
; License, v. 2.0. If a copy of the MPL was not distributed with this file,
; You can obtain one at http://mozilla.org/MPL/2.0/.
'''


class TestIniParser(ParserTestMixin, unittest.TestCase):

    filename = 'foo.ini'

    def testSimpleHeader(self):
        self._test('''; This file is in the UTF-8 encoding
[Strings]
TitleText=Some Title
''', (('TitleText', 'Some Title'),))
        self.assert_('UTF-8' in self.parser.header)

    def testMPL2_Space_UTF(self):
        self._test(mpl2 + '''
; This file is in the UTF-8 encoding
[Strings]
TitleText=Some Title
''', (('TitleText', 'Some Title'),))
        self.assert_('MPL' in self.parser.header)

    def testMPL2_Space(self):
        self._test(mpl2 + '''
[Strings]
TitleText=Some Title
''', (('TitleText', 'Some Title'),))
        self.assert_('MPL' in self.parser.header)

    def testMPL2_MultiSpace(self):
        self._test(mpl2 + '''\

; more comments

[Strings]
TitleText=Some Title
''', (('TitleText', 'Some Title'),))
        self.assert_('MPL' in self.parser.header)

    def testMPL2_JunkBeforeCategory(self):
        self._test(mpl2 + '''\
Junk
[Strings]
TitleText=Some Title
''', (('_junk_\\d+_0-213$', mpl2 + '''\
Junk
[Strings]'''), ('TitleText', 'Some Title')))
        self.assert_('MPL' not in self.parser.header)

    def test_TrailingComment(self):
        self._test(mpl2 + '''
[Strings]
TitleText=Some Title
;Stray trailing comment
''', (('TitleText', 'Some Title'),))
        self.assert_('MPL' in self.parser.header)

    def test_SpacedTrailingComments(self):
        self._test(mpl2 + '''
[Strings]
TitleText=Some Title

;Stray trailing comment
;Second stray comment

''', (('TitleText', 'Some Title'),))
        self.assert_('MPL' in self.parser.header)

    def test_TrailingCommentsAndJunk(self):
        self._test(mpl2 + '''
[Strings]
TitleText=Some Title

;Stray trailing comment
Junk
;Second stray comment

''', (('TitleText', 'Some Title'), ('_junk_\\d+_231-284$', '''\

;Stray trailing comment
Junk
;Second stray comment

''')))
        self.assert_('MPL' in self.parser.header)

    def test_JunkInbetweenEntries(self):
        self._test(mpl2 + '''
[Strings]
TitleText=Some Title

Junk

Good=other string
''', (('TitleText', 'Some Title'), ('_junk_\\d+_231-236$', '''\

Junk'''), ('Good', 'other string')))
        self.assert_('MPL' in self.parser.header)

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