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

Side by Side Diff: tools/idl_parser/idl_parser_test.py

Issue 13498002: Add WebIDL compliant parser plus tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 'Delay build of Lexer to handler tokens correctly.' Created 7 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 | Annotate | Revision Log
« no previous file with comments | « tools/idl_parser/idl_parser.py ('k') | tools/idl_parser/idl_ppapi_lexer.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import glob
7 import unittest
8
9 from idl_lexer import IDLLexer
10 from idl_parser import IDLParser, ParseFile
11
12 def ParseCommentTest(comment):
13 comment = comment.strip()
14 comments = comment.split(None, 1)
15 return comments[0], comments[1]
16
17
18 class WebIDLParser(unittest.TestCase):
19 def setUp(self):
20 self.parser = IDLParser(IDLLexer(), mute_error=True)
21 self.filenames = glob.glob('test_parser/*.idl')
22
23 def _TestNode(self, node):
24 comments = node.GetListOf('Comment')
25 for comment in comments:
26 check, value = ParseCommentTest(comment.GetName())
27 if check == 'BUILD':
28 msg = 'Expecting %s, but found %s.\n' % (value, str(node))
29 self.assertEqual(value, str(node), msg)
30
31 if check == 'ERROR':
32 msg = node.GetLogLine('Expecting\n\t%s\nbut found \n\t%s\n' % (
33 value, str(node)))
34 self.assertEqual(value, node.GetName(), msg)
35
36 if check == 'PROP':
37 key, expect = value.split('=')
38 actual = str(node.GetProperty(key))
39 msg = 'Mismatched property %s: %s vs %s.\n' % (key, expect, actual)
40 self.assertEqual(expect, actual, msg)
41
42 if check == 'TREE':
43 quick = '\n'.join(node.Tree())
44 lineno = node.GetProperty('LINENO')
45 msg = 'Mismatched tree at line %d:\n%sVS\n%s' % (lineno, value, quick)
46 self.assertEqual(value, quick, msg)
47
48 def testExpectedNodes(self):
49 for filename in self.filenames:
50 filenode = ParseFile(self.parser, filename)
51 children = filenode.GetChildren()
52 self.assertTrue(len(children) > 2, 'Expecting children in %s.' %
53 filename)
54
55 for node in filenode.GetChildren()[2:]:
56 self._TestNode(node)
57
58
59 if __name__ == '__main__':
60 unittest.main(verbosity=2)
61
OLDNEW
« no previous file with comments | « tools/idl_parser/idl_parser.py ('k') | tools/idl_parser/idl_ppapi_lexer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698