Pass CreateDirectory errors up to IndexedDB.
[chromium-blink-merge.git] / tools / idl_parser / idl_parser_test.py
blob5b7669efe5d2311715de7aa5231498f60c7c1dea
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.
6 import glob
7 import unittest
9 from idl_lexer import IDLLexer
10 from idl_parser import IDLParser, ParseFile
12 def ParseCommentTest(comment):
13 comment = comment.strip()
14 comments = comment.split(None, 1)
15 return comments[0], comments[1]
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')
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)
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)
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)
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)
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)
55 for node in filenode.GetChildren()[2:]:
56 self._TestNode(node)
59 if __name__ == '__main__':
60 unittest.main(verbosity=2)