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() |