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

Side by Side Diff: build/gn_helpers_unittest.py

Issue 1553993002: Add a Python parser for GN types to gn_helpers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
(Empty)
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
3 # found in the LICENSE file.
4
5 import gn_helpers
6 import unittest
7
8 class UnitTest(unittest.TestCase):
9 def test_ToGNString(self):
10 self.assertEqual(
11 gn_helpers.ToGNString([1, 'two', [ '"thr$\\', True, False, [] ]]),
12 '[ 1, "two", [ "\\"thr\\$\\\\", true, false, [ ] ] ]')
13
14 def test_UnescapeGNString(self):
15 # Backslash followed by a \, $, or " means the folling character without
16 # the special meaning. Backslash followed by everything else is a literal.
17 self.assertEqual(
18 gn_helpers.UnescapeGNString('\\as\\$\\\\asd\\"'),
19 '\\as$\\asd"')
20
21 def test_FromGNString(self):
22 self.assertEqual(
23 gn_helpers.FromGNString('[1, -20, true, false,["as\\"", []]]'),
24 [ 1, -20, True, False, [ 'as"', [] ] ])
25
26 with self.assertRaises(gn_helpers.GNException):
27 parser = gn_helpers.GNValueParser('123 456')
28 parser.Parse()
29
30 def test_ParseNumber(self):
31 parser = gn_helpers.GNValueParser('123')
32 self.assertEqual(parser.ParseNumber(), 123)
33
34 with self.assertRaises(gn_helpers.GNException):
35 parser = gn_helpers.GNValueParser('')
36 parser.ParseNumber()
37 with self.assertRaises(gn_helpers.GNException):
38 parser = gn_helpers.GNValueParser('a123')
39 parser.ParseNumber()
40
41 def test_ParseString(self):
42 parser = gn_helpers.GNValueParser('"asdf"')
43 self.assertEqual(parser.ParseString(), 'asdf')
44
45 with self.assertRaises(gn_helpers.GNException):
46 parser = gn_helpers.GNValueParser('') # Empty.
47 parser.ParseString()
48 with self.assertRaises(gn_helpers.GNException):
49 parser = gn_helpers.GNValueParser('asdf') # Unquoted.
50 parser.ParseString()
51 with self.assertRaises(gn_helpers.GNException):
52 parser = gn_helpers.GNValueParser('"trailing') # Unterminated.
53 parser.ParseString()
54
55 def test_ParseList(self):
56 parser = gn_helpers.GNValueParser('[1,]') # Optional end comma OK.
57 self.assertEqual(parser.ParseList(), [ 1 ])
58
59 with self.assertRaises(gn_helpers.GNException):
60 parser = gn_helpers.GNValueParser('') # Empty.
61 parser.ParseList()
62 with self.assertRaises(gn_helpers.GNException):
63 parser = gn_helpers.GNValueParser('asdf') # No [].
64 parser.ParseList()
65 with self.assertRaises(gn_helpers.GNException):
66 parser = gn_helpers.GNValueParser('[1, 2') # Unterminated
67 parser.ParseList()
68 with self.assertRaises(gn_helpers.GNException):
69 parser = gn_helpers.GNValueParser('[1 2]') # No separating comma.
70 parser.ParseList()
71
72 if __name__ == '__main__':
73 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