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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
« build/gn_helpers.py ('K') | « build/gn_helpers.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/gn_helpers_unittest.py
diff --git a/build/gn_helpers_unittest.py b/build/gn_helpers_unittest.py
index 72123f9359cd438089ae6d52f3be86fbbbded454..fc32607546e94678a34c1b8fbfa403adea1574ed 100644
--- a/build/gn_helpers_unittest.py
+++ b/build/gn_helpers_unittest.py
@@ -76,5 +76,34 @@ class UnitTest(unittest.TestCase):
parser = gn_helpers.GNValueParser('[1 2]') # No separating comma.
parser.ParseList()
+ def test_FromGNArgs(self):
+ # Booleans and numbers should work; whitespace is allowed works.
+ self.assertEqual(gn_helpers.FromGNArgs('foo = true\nbar = 1\n'),
+ {'foo': True, 'bar': 1})
+
+ # Whitespace is not required; strings should also work.
+ self.assertEqual(gn_helpers.FromGNArgs('foo="bar baz"'),
+ {'foo': 'bar baz'})
+
+ # Lists should not be allowed.
+ with self.assertRaises(gn_helpers.GNException):
+ gn_helpers.FromGNArgs('foo=[1, 2, 3]')
+
+ # Empty strings should return an empty dict.
+ self.assertEqual(gn_helpers.FromGNArgs(''), {})
+ self.assertEqual(gn_helpers.FromGNArgs(' \n '), {})
+
+ # Non-identifiers should raise an exception.
+ with self.assertRaises(gn_helpers.GNException):
+ gn_helpers.FromGNArgs('123 = true')
+
+ # Underscores in identifiers should work.
+ self.assertEqual(gn_helpers.FromGNArgs('_foo = true'),
+ {'_foo': True})
+ self.assertEqual(gn_helpers.FromGNArgs('foo_bar = true'),
+ {'foo_bar': True})
+ self.assertEqual(gn_helpers.FromGNArgs('foo_=true'),
+ {'foo_': True})
+
if __name__ == '__main__':
unittest.main()
« 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