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

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: allow lists in args 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « 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..cc6018a17210ab86d07b321c8490180d8803a04c 100644
--- a/build/gn_helpers_unittest.py
+++ b/build/gn_helpers_unittest.py
@@ -76,5 +76,42 @@ 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 work.
+ self.assertEqual(gn_helpers.FromGNArgs('foo=[1, 2, 3]'),
+ {'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')
+
+ # References to other variables should raise an exception.
+ with self.assertRaises(gn_helpers.GNException):
+ gn_helpers.FromGNArgs('foo = bar')
+
+ # References to functions should raise an exception.
+ with self.assertRaises(gn_helpers.GNException):
+ gn_helpers.FromGNArgs('foo = exec_script("//build/baz.py")')
+
+ # 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()
« no previous file with comments | « build/gn_helpers.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698