Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: client/dom/scripts/templateloader_test.py

Issue 9845043: Rename client/{dom,html} to lib/{dom,html} . (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « client/dom/scripts/templateloader.py ('k') | client/dom/src/DOMType.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
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
6 import logging.config
7 import unittest
8 import templateloader
9
10 class TemplateLoaderTestCase(unittest.TestCase):
11
12 def _preprocess(self, input_text, conds):
13 loader = templateloader.TemplateLoader('.', [], conds)
14 return loader._Preprocess(input_text, '<file>')
15
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 = '''
21 EXPECTED:
22 %s
23 ---
24 ACTUAL :
25 %s
26 ---''' % (expected_text, output_text)
27 self.fail(msg)
28
29
30 def _preprocess_error_test(self, input_text, conds, expected_message):
31 threw = False
32 try:
33 output_text = self._preprocess(input_text, conds)
34 except Exception, e:
35 threw = True
36 if str(e).find(expected_message) == -1:
37 self.fail("'%s' does not contain '%s'" % (e, expected_message))
38 if not threw:
39 self.fail("missing error, expected '%s'" % expected_message)
40
41
42 def test_freevar(self):
43 input_text = '''$A
44 $B'''
45 self._preprocess_test(input_text, {}, input_text)
46
47
48 def test_ite1(self):
49 input_text = '''
50 aaa
51 $if A
52 bbb
53 $else
54 ccc
55 $endif
56 ddd
57 '''
58 self._preprocess_test(input_text, {'A':True},
59 '''
60 aaa
61 bbb
62 ddd
63 ''')
64
65 def test_ite2(self):
66 input_text = '''
67 aaa
68 $if A
69 bbb
70 $else
71 ccc
72 $endif
73 ddd
74 '''
75 self._preprocess_test(input_text, {'A':False},
76 '''
77 aaa
78 ccc
79 ddd
80 ''')
81
82 def test_if1(self):
83 input_text = '''
84 $if
85 '''
86 self._preprocess_error_test(input_text, {},
87 '$if does not have single variable')
88
89 def test_if2(self):
90 input_text = '''
91 $if A
92 '''
93 self._preprocess_error_test(input_text, {}, 'Unknown $if variable')
94
95 def test_else1(self):
96 input_text = '''
97 $else
98 '''
99 self._preprocess_error_test(input_text, {}, '$else without $if')
100
101 def test_else2(self):
102 input_text = '''
103 $if A
104 $else
105 $else
106 '''
107 self._preprocess_error_test(input_text, {'A':True}, 'Double $else')
108
109 def test_eof1(self):
110 input_text = '''
111 $if A
112 '''
113 self._preprocess_error_test(input_text, {'A':True}, 'Unterminated')
114
115 def test_eof2(self):
116 input_text = '''
117 $if A
118 $else
119 '''
120 self._preprocess_error_test(input_text, {'A':True}, 'Unterminated')
121
122 if __name__ == "__main__":
123 logging.config.fileConfig("logging.conf")
124 if __name__ == '__main__':
125 unittest.main()
OLDNEW
« no previous file with comments | « client/dom/scripts/templateloader.py ('k') | client/dom/src/DOMType.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698