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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: tools/idl_parser/idl_parser_test.py
diff --git a/tools/idl_parser/idl_parser_test.py b/tools/idl_parser/idl_parser_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..35c7fb0615a8148e8ee0870a152d655c65937b2a
--- /dev/null
+++ b/tools/idl_parser/idl_parser_test.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import glob
+import json
+import optparse
+import os
+import sys
+import unittest
+
+from idl_lexer import IDLLexer
+from idl_parser import IDLParser, ParseFile
+
+def ParseCommentTest(comment):
+ comment = comment.strip()
+ comments = comment.split(None, 1)
+ return comments[0], comments[1]
+
+
+class WebIDLParser(unittest.TestCase):
+ def setUp(self):
+ self.parser = IDLParser(IDLLexer(), mute_error=True)
+ self.filenames = glob.glob('test_parser/*.idl')
+
+ def _TestNode(self, node):
+ comments = node.GetListOf('Comment')
+ errors = 0
+
+ for comment in comments:
+ check, value = ParseCommentTest(comment.GetName())
+ if check == 'BUILD':
+ msg = 'Expecting %s, but found %s.\n' % (value, str(node))
+ self.assertEqual(value, str(node), msg)
+
+ if check == 'ERROR':
+ msg = node.GetLogLine('Expecting\n\t%s\nbut found \n\t%s\n' % (
+ value, str(node)))
+ self.assertEqual(value, node.GetName(), msg)
+
+ if check == 'PROP':
+ key, expect = value.split('=')
+ actual = str(node.GetProperty(key))
+ 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.
+ self.assertEqual(expect, actual, msg)
+
+ if check == 'TREE':
+ quick = '\n'.join(node.Tree())
+ lineno = node.GetProperty('LINENO')
+ 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.
+ self.assertEqual(value, quick, msg)
+
+ def testExpectedNodes(self):
+ for filename in self.filenames:
+ print 'Testing %s' % filename
+ filenode = ParseFile(self.parser, filename)
+ children = filenode.GetChildren()
+ self.assertTrue(len(children) > 2, 'Expecting children in %s.' %
+ filename)
+
+ for node in filenode.GetChildren()[2:]:
+ self._TestNode(node)
+
+
+if __name__ == '__main__':
+ unittest.main(verbosity=2)
+

Powered by Google App Engine
This is Rietveld 408576698