Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
templateloader_test.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5
6import logging.config
7import unittest
8import templateloader
9
10
11class TemplateLoaderTestCase(unittest.TestCase):
12
13 def _preprocess(self, input_text, conds):
14 loader = templateloader.TemplateLoader('.', [], conds)
15 return loader._Preprocess(input_text, '<file>', conds)
16
17 def _preprocess_test(self, input_text, conds, expected_text):
18 output_text = self._preprocess(input_text, conds)
19 if output_text != expected_text:
20 msg = '''
21EXPECTED:
22%s
23---
24ACTUAL :
25%s
26---''' % (expected_text, output_text)
27 self.fail(msg)
28
29 def _preprocess_error_test(self, input_text, conds, expected_message):
30 threw = False
31 try:
32 output_text = self._preprocess(input_text, conds)
33 except Exception as e:
34 threw = True
35 if str(e).find(expected_message) == -1:
36 self.fail("'%s' does not contain '%s'" % (e, expected_message))
37 if not threw:
38 self.fail("missing error, expected '%s'" % expected_message)
39
40 def test_freevar(self):
41 input_text = '''$A
42$B'''
43 self._preprocess_test(input_text, {}, input_text)
44
45 def test_comments(self):
46 input_text = '''//$ comment 1
47Hello
48//$ comment 2'''
49 self._preprocess_test(input_text, {}, 'Hello\n')
50
51 def test_ite1(self):
52 input_text = '''
53 aaa
54 $if A
55 bbb
56 $else
57 ccc
58 $endif
59 ddd
60 '''
62 input_text, {'A': True}, '''
63 aaa
64 bbb
65 ddd
66 ''')
67
68 def test_ite2(self):
69 input_text = '''
70 aaa
71 $if A
72 bbb
73 $else
74 ccc
75 $endif
76 ddd
77 '''
79 input_text, {'A': False}, '''
80 aaa
81 ccc
82 ddd
83 ''')
84
85 def test_if1(self):
86 input_text = '''
87 $if
88 '''
89 self._preprocess_error_test(input_text, {},
90 '$if does not have single variable')
91
92 def test_if2(self):
93 input_text = '''
94 $if A
95 '''
96 self._preprocess_error_test(input_text, {}, 'Unknown $if variable')
97
98 def test_else1(self):
99 input_text = '''
100 $else
101 '''
102 self._preprocess_error_test(input_text, {}, '$else without $if')
103
104 def test_else2(self):
105 input_text = '''
106 $if A
107 $else
108 $else
109 '''
110 self._preprocess_error_test(input_text, {'A': True}, 'Double $else')
111
112 def test_eof1(self):
113 input_text = '''
114 $if A
115 '''
116 self._preprocess_error_test(input_text, {'A': True}, 'Unterminated')
117
118 def test_eof2(self):
119 input_text = '''
120 $if A
121 $else
122 '''
123 self._preprocess_error_test(input_text, {'A': True}, 'Unterminated')
124
125
126if __name__ == "__main__":
127 logging.config.fileConfig("logging.conf")
128 if __name__ == '__main__':
129 unittest.main()
int find(T *array, int N, T item)
_preprocess_test(self, input_text, conds, expected_text)
_preprocess_error_test(self, input_text, conds, expected_message)