aboutsummaryrefslogtreecommitdiffstats
path: root/docs/sphinx/hieroglyph/test/test_hierglyph.py
blob: 7815960905ccc4e17ea6990951adddd13a746969 (plain) (blame)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
from __future__ import unicode_literals
import unittest
from hieroglyph.hieroglyph import first_paragraph_indent, gather_lines, unindent

__author__ = 'Robert Smallshire'

class UnindentTests(unittest.TestCase):

    def test_zero_lines(self):
        source   = []
        expected = []
        actual = unindent(source)
        self.assertEqual(actual, expected)

    def test_one_zero_indent_line(self):
        source   = ["First line"]
        expected = [(0, "First line")]
        actual = unindent(source)
        self.assertEqual(actual, expected)

    def test_two_zero_indent_lines(self):
        source   = ["First line",
                    "Second line"]
        expected = [(0, "First line"),
                    (0, "Second line")]
        actual = unindent(source)
        self.assertEqual(actual, expected)

    def test_two_indented_lines(self):
        source   = ["    First line",
                    "      Second line"]
        expected = [(4, "First line"),
                    (6, "Second line")]
        actual = unindent(source)
        self.assertEqual(actual, expected)

    def test_whitespace_line(self):
        source   = ["    "]
        expected = [(4, "")]
        actual = unindent(source)
        self.assertEqual(actual, expected)

    def test_tab_line(self):
        source   = ["\tHello"]
        expected = [(1, "Hello")]
        actual = unindent(source)
        self.assertEqual(actual, expected)


class FirstParagraphIndentTests(unittest.TestCase):

    def test_zero_lines(self):
        source   = []
        expected = []
        actual = first_paragraph_indent(source)
        self.assertEqual(actual, expected)

    def test_single_line_non_indented_comment(self):
        source   = [(0, "A single line comment")]
        expected = [(0, "A single line comment")]
        actual = first_paragraph_indent(source)
        self.assertEqual(actual, expected)

    def test_single_line_indented_comment(self):
        source   = [(4, "A single line comment")]
        expected = [(4, "A single line comment")]
        actual = first_paragraph_indent(source)
        self.assertEqual(actual, expected)

    def test_double_line_non_indented_comment(self):
        source   = [(0, "The first line"),
                    (0, "The second line")]
        expected = [(0, "The first line"),
                    (0, "The second line")]
        actual = first_paragraph_indent(source)
        self.assertEqual(actual, expected)

    def test_double_line_indented_comment(self):
        source   = [(4, "The first line"),
                    (4, "The second line")]
        expected = [(4, "The first line"),
                    (4, "The second line")]
        actual = first_paragraph_indent(source)
        self.assertEqual(actual, expected)

    def test_first_line_indent(self):
        source   = [(4, "The first line"),
                    (0, "The second line")]
        expected = [(4, "The first line"),
                    (0, "The second line")]
        actual = first_paragraph_indent(source)
        self.assertEqual(actual, expected)

    def test_first_line_non_indent(self):
        source   = [(0, "The first line"),
                    (4, "The second line")]
        expected = [(4, "The first line"),
                    (4, "The second line")]
        actual = first_paragraph_indent(source)
        self.assertEqual(actual, expected)

    def test_increasing_indent(self):
        source   = [(0, "The first line"),
                    (4, "The second line"),
                    (8, "The third line")]
        expected = [(4, "The first line"),
                    (4, "The second line"),
                    (8, "The third line")]
        actual = first_paragraph_indent(source)
        self.assertEqual(actual, expected)

    def test_separate_paragraphs(self):
        source   = [(0, "This is the first paragraph"),
                    (0, ""),
                    (4, "This is the second paragraph")]
        expected = [(0, "This is the first paragraph"),
                    (0, ""),
                    (4, "This is the second paragraph")]
        actual = first_paragraph_indent(source)
        self.assertEqual(actual, expected)

    def test_separate_paragraphs_indented(self):
        source   = [(4, "This is the first paragraph"),
                    (4, ""),
                    (8, "This is the second paragraph")]
        expected = [(4, "This is the first paragraph"),
                    (4, ""),
                    (8, "This is the second paragraph")]
        actual = first_paragraph_indent(source)
        self.assertEqual(actual, expected)

    def test_separated_lines_first_line_non_indented(self):
        source   = [(0, "The first line"),
                    (0, ""),
                    (4, "The third line")]
        expected = [(0, "The first line"),
                    (0, ""),
                    (4, "The third line")]
        actual = first_paragraph_indent(source)
        self.assertEqual(actual, expected)

    def test_separated_lines_first_line_indented(self):
        source   = [(4, "The first line"),
                    (4, ""),
                    (4, "The third line")]
        expected = [(4, "The first line"),
                    (4, ""),
                    (4, "The third line")]
        actual = first_paragraph_indent(source)
        self.assertEqual(actual, expected)

class GatherLinesTests(unittest.TestCase):

    def test_empty(self):
        source   = []
        expected = []
        actual = gather_lines(source)
        self.assertEqual(actual, expected)

    def test_one_liner(self):
        source   = [(0, 'One liner')]
        expected = [(0, ['One liner'])]
        actual = gather_lines(source)
        self.assertEqual(actual, expected)

    def test_two_liner(self):
        source   = [(0, 'First line'),
                    (0, 'Second line')]
        expected = [(0, ['First line',
                           'Second line'])]
        actual = gather_lines(source)
        self.assertEqual(actual, expected)

    def test_separated_lines(self):
        source   = [(0, 'First line'),
                    (0, ''),
                    (0, 'Third line')]
        expected = [(0, ['First line',
                         '']),
                    (0, ['Third line'])]
        actual = gather_lines(source)
        self.assertEqual(actual, expected)

    def test_separated_multi_lines(self):
        source   = [(0, 'First line'),
                    (0, 'Second line'),
                    (0, ''),
                    (0, 'Fourth line'),
                    (0, 'Fifth line')]
        expected = [(0, ['First line',
                         'Second line',
                         '']),
                    (0, ['Fourth line',
                         'Fifth line'])]
        actual = gather_lines(source)
        self.assertEqual(actual, expected)


    def test_indented_lines(self):
        source   = [(0, 'First line'),
                    (4, 'Second line')]
        expected = [(0, ['First line']),
                    (4, ['Second line'])]
        actual = gather_lines(source)
        self.assertEqual(actual, expected)

    def test_dedented_lines(self):
        source   = [(4, 'First line'),
                    (0, 'Second line')]
        expected = [(4, ['First line']),
                    (0, ['Second line'])]
        actual = gather_lines(source)
        self.assertEqual(actual, expected)

    def test_indented_multi_lines(self):
        source   = [(0, 'First line'),
                    (0, 'Second line'),
                    (4, 'Third line'),
                    (4, 'Fourth line')]
        expected = [(0, ['First line',
                         'Second line']),
                    (4, ['Third line',
                         'Fourth line'])]
        actual = gather_lines(source)
        self.assertEqual(actual, expected)

    def test_dedented_multi_lines(self):
        source   = [(4, 'First line'),
                    (4, 'Second line'),
                    (0, 'Third line'),
                    (0, 'Fourth line')]
        expected = [(4, ['First line',
                         'Second line']),
                    (0, ['Third line',
                         'Fourth line'])]
        actual = gather_lines(source)
        self.assertEqual(actual, expected)

    def test_indented_separated_multi_lines(self):
        source   = [(0, 'First line'),
                    (0, 'Second line'),
                    (0, ''),
                    (4, 'Fourth line'),
                    (4, 'Fifth line')]
        expected = [(0, ['First line',
                         'Second line',
                         '']),
                    (4, ['Fourth line',
                         'Fifth line'])]
        actual = gather_lines(source)
        self.assertEqual(actual, expected)

    def test_dedented_separated_multi_lines(self):
        source   = [(4, 'First line'),
                    (4, 'Second line'),
                    (4, ''),
                    (0, 'Fourth line'),
                    (0, 'Fifth line')]
        expected = [(4, ['First line',
                         'Second line',
                         '']),
                    (0, ['Fourth line',
                         'Fifth line'])]
        actual = gather_lines(source)
        self.assertEqual(actual, expected)