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

Side by Side Diff: grit/node/base_unittest.py

Issue 156443002: Provide defines as local variables in if-expressions. (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk
Patch Set: rebased past is_posix fix, fixed is_posix again and updated unittests Created 6 years, 10 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 | « grit/node/base.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 '''Unit tests for base.Node functionality (as used in various subclasses)''' 6 '''Unit tests for base.Node functionality (as used in various subclasses)'''
7 7
8 8
9 import os 9 import os
10 import sys 10 import sys
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 </release> 185 </release>
186 </grit>''' 186 </grit>'''
187 grd = grd_reader.Parse(StringIO.StringIO(xml), 187 grd = grd_reader.Parse(StringIO.StringIO(xml),
188 util.PathFromRoot('grit/test/data')) 188 util.PathFromRoot('grit/test/data'))
189 from grit.node import io 189 from grit.node import io
190 output_nodes = grd.GetChildrenOfType(io.OutputNode) 190 output_nodes = grd.GetChildrenOfType(io.OutputNode)
191 self.failUnlessEqual(len(output_nodes), 3) 191 self.failUnlessEqual(len(output_nodes), 3)
192 self.failUnlessEqual(output_nodes[2].attrs['filename'], 192 self.failUnlessEqual(output_nodes[2].attrs['filename'],
193 'de/generated_resources.rc') 193 'de/generated_resources.rc')
194 194
195 def testEvaluateExpression(self):
196 def AssertExpr(expected_value, expr, defs, target_platform,
197 extra_variables):
198 self.failUnlessEqual(expected_value, base.Node.EvaluateExpression(
199 expr, defs, target_platform, extra_variables))
200
201 AssertExpr(True, "True", {}, 'linux', {})
202 AssertExpr(False, "False", {}, 'linux', {})
203 AssertExpr(True, "True or False", {}, 'linux', {})
204 AssertExpr(False, "True and False", {}, 'linux', {})
205 AssertExpr(True, "os == 'linux'", {}, 'linux', {})
206 AssertExpr(False, "os == 'linux'", {}, 'ios', {})
207 AssertExpr(True, "'foo' in defs", {'foo': 'bar'}, 'ios', {})
208 AssertExpr(False, "'foo' in defs", {'baz': 'bar'}, 'ios', {})
209 AssertExpr(False, "'foo' in defs", {}, 'ios', {})
210 AssertExpr(True, "is_linux", {}, 'linux2', {})
211 AssertExpr(False, "is_linux", {}, 'win32', {})
212 AssertExpr(True, "is_macosx", {}, 'darwin', {})
213 AssertExpr(False, "is_macosx", {}, 'ios', {})
214 AssertExpr(True, "is_win", {}, 'win32', {})
215 AssertExpr(False, "is_win", {}, 'darwin', {})
216 AssertExpr(True, "is_android", {}, 'android', {})
217 AssertExpr(False, "is_android", {}, 'linux3', {})
218 AssertExpr(True, "is_ios", {}, 'ios', {})
219 AssertExpr(False, "is_ios", {}, 'darwin', {})
220 AssertExpr(True, "is_posix", {}, 'linux2', {})
221 AssertExpr(True, "is_posix", {}, 'darwin', {})
222 AssertExpr(True, "is_posix", {}, 'android', {})
223 AssertExpr(True, "is_posix", {}, 'ios', {})
224 AssertExpr(True, "is_posix", {}, 'freebsd7', {})
225 AssertExpr(False, "is_posix", {}, 'win32', {})
226 AssertExpr(True, "pp_ifdef('foo')", {'foo': True}, 'win32', {})
227 AssertExpr(True, "pp_ifdef('foo')", {'foo': False}, 'win32', {})
228 AssertExpr(False, "pp_ifdef('foo')", {'bar': True}, 'win32', {})
229 AssertExpr(True, "pp_if('foo')", {'foo': True}, 'win32', {})
230 AssertExpr(False, "pp_if('foo')", {'foo': False}, 'win32', {})
231 AssertExpr(False, "pp_if('foo')", {'bar': True}, 'win32', {})
232 AssertExpr(True, "foo", {'foo': True}, 'win32', {})
233 AssertExpr(False, "foo", {'foo': False}, 'win32', {})
234 AssertExpr(False, "foo", {'bar': True}, 'win32', {})
235 AssertExpr(True, "foo == 'baz'", {'foo': 'baz'}, 'win32', {})
236 AssertExpr(False, "foo == 'baz'", {'foo': True}, 'win32', {})
237 AssertExpr(False, "foo == 'baz'", {}, 'win32', {})
238 AssertExpr(True, "lang == 'de'", {}, 'win32', {'lang': 'de'})
239 AssertExpr(False, "lang == 'de'", {}, 'win32', {'lang': 'fr'})
240 AssertExpr(False, "lang == 'de'", {}, 'win32', {})
241
242 # Test a couple more complex expressions for good measure.
243 AssertExpr(True, "is_ios and (lang in ['de', 'fr'] or foo)",
244 {'foo': 'bar'}, 'ios', {'lang': 'fr', 'context': 'today'})
245 AssertExpr(False, "is_ios and (lang in ['de', 'fr'] or foo)",
246 {'foo': False}, 'linux2', {'lang': 'fr', 'context': 'today'})
247 AssertExpr(False, "is_ios and (lang in ['de', 'fr'] or foo)",
248 {'baz': 'bar'}, 'ios', {'lang': 'he', 'context': 'today'})
249 AssertExpr(True, "foo == 'bar' or not baz",
250 {'foo': 'bar', 'fun': True}, 'ios', {'lang': 'en'})
251 AssertExpr(True, "foo == 'bar' or not baz",
252 {}, 'ios', {'lang': 'en', 'context': 'java'})
253 AssertExpr(False, "foo == 'bar' or not baz",
254 {'foo': 'ruz', 'baz': True}, 'ios', {'lang': 'en'})
255
195 if __name__ == '__main__': 256 if __name__ == '__main__':
196 unittest.main() 257 unittest.main()
197 258
OLDNEW
« no previous file with comments | « grit/node/base.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698