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

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: Merge using updated lexer, fix error msgs 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
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 json
8 import optparse
9 import os
10 import sys
11 import unittest
12
13 from idl_lexer import IDLLexer
14 from idl_parser import IDLParser, ParseFile
15
16 def ParseCommentTest(comment):
17 comment = comment.strip()
18 comments = comment.split(None, 1)
19 return comments[0], comments[1]
20
21
22 class WebIDLParser(unittest.TestCase):
23 def setUp(self):
24 self.parser = IDLParser(IDLLexer(), mute_error=True)
25 self.filenames = glob.glob('test_parser/*.idl')
26
27 def _TestNode(self, node):
28 comments = node.GetListOf('Comment')
29 errors = 0
30
31 for comment in comments:
32 check, value = ParseCommentTest(comment.GetName())
33 if check == 'BUILD':
34 msg = 'Expecting %s, but found %s.\n' % (value, str(node))
35 self.assertEqual(value, str(node), msg)
36
37 if check == 'ERROR':
38 msg = node.GetLogLine('Expecting\n\t%s\nbut found \n\t%s\n' % (
39 value, str(node)))
40 self.assertEqual(value, node.GetName(), msg)
41
42 if check == 'PROP':
43 key, expect = value.split('=')
44 actual = str(node.GetProperty(key))
45 msg = 'Mismatch property %s: %s vs %s.\n' % (key, expect, actual)
sehr 2013/04/12 15:54:57 Mismatched (to match the below)
noelallen1 2013/04/12 16:52:15 Done.
46 self.assertEqual(expect, actual, msg)
47
48 if check == 'TREE':
49 quick = '\n'.join(node.Tree())
50 lineno = node.GetProperty('LINENO')
51 msg = 'Misatched tree at line %d:\n%sVS\n%s' % (lineno, value, quick)
sehr 2013/04/12 15:54:57 Mismatched
noelallen1 2013/04/12 16:52:15 Done.
52 self.assertEqual(value, quick, msg)
53
54 def testExpectedNodes(self):
55 for filename in self.filenames:
56 print 'Testing %s' % filename
57 filenode = ParseFile(self.parser, filename)
58 children = filenode.GetChildren()
59 self.assertTrue(len(children) > 2, 'Expecting children in %s.' %
60 filename)
61
62 for node in filenode.GetChildren()[2:]:
63 self._TestNode(node)
64
65
66 if __name__ == '__main__':
67 unittest.main(verbosity=2)
68
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698