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

Side by Side Diff: build/gn_helpers_unittest.py

Issue 1847333005: Add FromGNArgs() to gn_helpers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix_gn_helpers_bools
Patch Set: Created 4 years, 8 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
« build/gn_helpers.py ('K') | « build/gn_helpers.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 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import gn_helpers 5 import gn_helpers
6 import unittest 6 import unittest
7 7
8 class UnitTest(unittest.TestCase): 8 class UnitTest(unittest.TestCase):
9 def test_ToGNString(self): 9 def test_ToGNString(self):
10 self.assertEqual( 10 self.assertEqual(
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 with self.assertRaises(gn_helpers.GNException): 69 with self.assertRaises(gn_helpers.GNException):
70 parser = gn_helpers.GNValueParser('asdf') # No []. 70 parser = gn_helpers.GNValueParser('asdf') # No [].
71 parser.ParseList() 71 parser.ParseList()
72 with self.assertRaises(gn_helpers.GNException): 72 with self.assertRaises(gn_helpers.GNException):
73 parser = gn_helpers.GNValueParser('[1, 2') # Unterminated 73 parser = gn_helpers.GNValueParser('[1, 2') # Unterminated
74 parser.ParseList() 74 parser.ParseList()
75 with self.assertRaises(gn_helpers.GNException): 75 with self.assertRaises(gn_helpers.GNException):
76 parser = gn_helpers.GNValueParser('[1 2]') # No separating comma. 76 parser = gn_helpers.GNValueParser('[1 2]') # No separating comma.
77 parser.ParseList() 77 parser.ParseList()
78 78
79 def test_FromGNArgs(self):
80 # Booleans and numbers should work; whitespace is allowed works.
81 self.assertEqual(gn_helpers.FromGNArgs('foo = true\nbar = 1\n'),
82 {'foo': True, 'bar': 1})
83
84 # Whitespace is not required; strings should also work.
85 self.assertEqual(gn_helpers.FromGNArgs('foo="bar baz"'),
86 {'foo': 'bar baz'})
87
88 # Lists should not be allowed.
89 with self.assertRaises(gn_helpers.GNException):
90 gn_helpers.FromGNArgs('foo=[1, 2, 3]')
91
92 # Empty strings should return an empty dict.
93 self.assertEqual(gn_helpers.FromGNArgs(''), {})
94 self.assertEqual(gn_helpers.FromGNArgs(' \n '), {})
95
96 # Non-identifiers should raise an exception.
97 with self.assertRaises(gn_helpers.GNException):
98 gn_helpers.FromGNArgs('123 = true')
99
100 # Underscores in identifiers should work.
101 self.assertEqual(gn_helpers.FromGNArgs('_foo = true'),
102 {'_foo': True})
103 self.assertEqual(gn_helpers.FromGNArgs('foo_bar = true'),
104 {'foo_bar': True})
105 self.assertEqual(gn_helpers.FromGNArgs('foo_=true'),
106 {'foo_': True})
107
79 if __name__ == '__main__': 108 if __name__ == '__main__':
80 unittest.main() 109 unittest.main()
OLDNEW
« build/gn_helpers.py ('K') | « build/gn_helpers.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698