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

Side by Side Diff: build/gn_helpers_unittest.py

Issue 1844823002: Fix gn_helpers' parsing of bools. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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
« no previous file with comments | « 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(
11 gn_helpers.ToGNString([1, 'two', [ '"thr$\\', True, False, [] ]]), 11 gn_helpers.ToGNString([1, 'two', [ '"thr$\\', True, False, [] ]]),
12 '[ 1, "two", [ "\\"thr\\$\\\\", true, false, [ ] ] ]') 12 '[ 1, "two", [ "\\"thr\\$\\\\", true, false, [ ] ] ]')
13 13
14 def test_UnescapeGNString(self): 14 def test_UnescapeGNString(self):
15 # Backslash followed by a \, $, or " means the folling character without 15 # Backslash followed by a \, $, or " means the folling character without
16 # the special meaning. Backslash followed by everything else is a literal. 16 # the special meaning. Backslash followed by everything else is a literal.
17 self.assertEqual( 17 self.assertEqual(
18 gn_helpers.UnescapeGNString('\\as\\$\\\\asd\\"'), 18 gn_helpers.UnescapeGNString('\\as\\$\\\\asd\\"'),
19 '\\as$\\asd"') 19 '\\as$\\asd"')
20 20
21 def test_FromGNString(self): 21 def test_FromGNString(self):
22 self.assertEqual( 22 self.assertEqual(
23 gn_helpers.FromGNString('[1, -20, true, false,["as\\"", []]]'), 23 gn_helpers.FromGNString('[1, -20, true, false,["as\\"", []]]'),
24 [ 1, -20, True, False, [ 'as"', [] ] ]) 24 [ 1, -20, True, False, [ 'as"', [] ] ])
25 25
26 with self.assertRaises(gn_helpers.GNException): 26 with self.assertRaises(gn_helpers.GNException):
27 parser = gn_helpers.GNValueParser('123 456') 27 parser = gn_helpers.GNValueParser('123 456')
28 parser.Parse() 28 parser.Parse()
29 29
30 def test_ParseBool(self):
31 parser = gn_helpers.GNValueParser('true')
32 self.assertEqual(parser.Parse(), True)
33
34 parser = gn_helpers.GNValueParser('false')
35 self.assertEqual(parser.Parse(), False)
36
30 def test_ParseNumber(self): 37 def test_ParseNumber(self):
31 parser = gn_helpers.GNValueParser('123') 38 parser = gn_helpers.GNValueParser('123')
32 self.assertEqual(parser.ParseNumber(), 123) 39 self.assertEqual(parser.ParseNumber(), 123)
33 40
34 with self.assertRaises(gn_helpers.GNException): 41 with self.assertRaises(gn_helpers.GNException):
35 parser = gn_helpers.GNValueParser('') 42 parser = gn_helpers.GNValueParser('')
36 parser.ParseNumber() 43 parser.ParseNumber()
37 with self.assertRaises(gn_helpers.GNException): 44 with self.assertRaises(gn_helpers.GNException):
38 parser = gn_helpers.GNValueParser('a123') 45 parser = gn_helpers.GNValueParser('a123')
39 parser.ParseNumber() 46 parser.ParseNumber()
(...skipping 24 matching lines...) Expand all
64 parser.ParseList() 71 parser.ParseList()
65 with self.assertRaises(gn_helpers.GNException): 72 with self.assertRaises(gn_helpers.GNException):
66 parser = gn_helpers.GNValueParser('[1, 2') # Unterminated 73 parser = gn_helpers.GNValueParser('[1, 2') # Unterminated
67 parser.ParseList() 74 parser.ParseList()
68 with self.assertRaises(gn_helpers.GNException): 75 with self.assertRaises(gn_helpers.GNException):
69 parser = gn_helpers.GNValueParser('[1 2]') # No separating comma. 76 parser = gn_helpers.GNValueParser('[1 2]') # No separating comma.
70 parser.ParseList() 77 parser.ParseList()
71 78
72 if __name__ == '__main__': 79 if __name__ == '__main__':
73 unittest.main() 80 unittest.main()
OLDNEW
« 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