diff options
author | noelallen@google.com <noelallen@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-12 18:48:47 +0000 |
---|---|---|
committer | noelallen@google.com <noelallen@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-12 18:48:47 +0000 |
commit | ac7b49d82dee3e690968139b610553386f6f1f3c (patch) | |
tree | 3701977bff91385289785992d6f016aa2ed66ee9 /tools/idl_parser/idl_parser_test.py | |
parent | 7a54a4316797f7afebeb013b20631f90bba9eecb (diff) | |
download | chromium_src-ac7b49d82dee3e690968139b610553386f6f1f3c.zip chromium_src-ac7b49d82dee3e690968139b610553386f6f1f3c.tar.gz chromium_src-ac7b49d82dee3e690968139b610553386f6f1f3c.tar.bz2 |
Add WebIDL and Pepper compliant lexer/parser tool.
This CL is the first step towards supporting automatic doc
generation. This lexer more closely follows the WebIDL
spec.
Please review idl_node, idl_parser, idl_node
idl_log.py is unchanged from the original
This is a complete re-write of the original lexer/parser, as well as simplifications to IDLNode.
All *.in and *.idl files are for test purposes only.
To test: python idl_lexer.py OR python idl_parser.py
NOTRY=true
R=sehr@chromium.org
BUG=224150
Review URL: https://codereview.chromium.org/13498002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193973 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/idl_parser/idl_parser_test.py')
-rwxr-xr-x | tools/idl_parser/idl_parser_test.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tools/idl_parser/idl_parser_test.py b/tools/idl_parser/idl_parser_test.py new file mode 100755 index 0000000..5b7669e --- /dev/null +++ b/tools/idl_parser/idl_parser_test.py @@ -0,0 +1,61 @@ +#!/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 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') + 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 = 'Mismatched property %s: %s vs %s.\n' % (key, expect, actual) + self.assertEqual(expect, actual, msg) + + if check == 'TREE': + quick = '\n'.join(node.Tree()) + lineno = node.GetProperty('LINENO') + msg = 'Mismatched tree at line %d:\n%sVS\n%s' % (lineno, value, quick) + self.assertEqual(value, quick, msg) + + def testExpectedNodes(self): + for filename in self.filenames: + 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) + |