Commit 21a9816c authored by Kenichi Ishibashi's avatar Kenichi Ishibashi Committed by Commit Bot

idl_parser: Add unittests for "implements" definitions

The "PROP" pattern match checks and other checks except for "TREE"
are currently broken and it's somewhat difficult to make them workable.
It would be easier to check AST nodes directly. This CL drops "PROP"
checks and adds some unittests. Follow-up CLs will remove other checks
except for "TREE".

BUG=617899

Change-Id: Ifb7041ab971fc584b0a43e8ce465e2e30905f9d4
Reviewed-on: https://chromium-review.googlesource.com/581129Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488690}
parent de2037a5
......@@ -33,12 +33,6 @@ class WebIDLParser(unittest.TestCase):
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')
......@@ -56,5 +50,53 @@ class WebIDLParser(unittest.TestCase):
self._TestNode(node)
class TestImplements(unittest.TestCase):
def setUp(self):
self.parser = IDLParser(IDLLexer(), mute_error=True)
def _ParseImplements(self, idl_text):
filenode = self.parser.ParseText(filename='', data=idl_text)
self.assertEqual(1, len(filenode.GetChildren()))
return filenode.GetChildren()[0]
def testAImplementsB(self):
idl_text = 'A implements B;'
implements_node = self._ParseImplements(idl_text)
self.assertEqual('Implements(A)', str(implements_node))
reference_node = implements_node.GetProperty('REFERENCE')
self.assertEqual('B', str(reference_node))
def testBImplementsC(self):
idl_text = 'B implements C;'
implements_node = self._ParseImplements(idl_text)
self.assertEqual('Implements(B)', str(implements_node))
reference_node = implements_node.GetProperty('REFERENCE')
self.assertEqual('C', str(reference_node))
def testUnexpectedSemicolon(self):
idl_text = 'A implements;'
node = self._ParseImplements(idl_text)
self.assertEqual('Error', node.GetClass())
error_message = node.GetName()
self.assertEqual('Unexpected ";" after keyword "implements".',
error_message)
def testUnexpectedImplements(self):
idl_text = 'implements C;'
node = self._ParseImplements(idl_text)
self.assertEqual('Error', node.GetClass())
error_message = node.GetName()
self.assertEqual('Unexpected implements.',
error_message)
def testUnexpectedImplementsAfterBracket(self):
idl_text = '[foo] implements B;'
node = self._ParseImplements(idl_text)
self.assertEqual('Error', node.GetClass())
error_message = node.GetName()
self.assertEqual('Unexpected keyword "implements" after "]".',
error_message)
if __name__ == '__main__':
unittest.main(verbosity=2)
......@@ -15,10 +15,6 @@ ERROR Error String
This comment signals that a error of <Error String> is generated. The error
is not assigned to a node, but are expected in order.
PROP Key=Value
This comment signals that a property has been set on the Node such that
<Key> = <Value>.
TREE
Type(Name)
Type(Name)
......
......@@ -15,10 +15,6 @@ ERROR Error String
This comment signals that a error of <Error String> is generated. The error
is not assigned to a node, but are expected in order.
PROP Key=Value
This comment signals that a property has been set on the Node such that
<Key> = <Value>.
TREE
Type(Name)
Type(Name)
......
......@@ -15,10 +15,6 @@ ERROR Error String
This comment signals that a error of <Error String> is generated. The error
is not assigned to a node, but are expected in order.
PROP Key=Value
This comment signals that a property has been set on the Node such that
<Key> = <Value>.
TREE
Type(Name)
Type(Name)
......
/* 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. */
/* Test Implements productions
Run with --test to generate an AST and verify that all comments accurately
reflect the state of the Nodes.
BUILD Type(Name)
This comment signals that a node of type <Type> is created with the
name <Name>.
ERROR Error String
This comment signals that a error of <Error String> is generated. The error
is not assigned to a node, but are expected in order.
PROP Key=Value
This comment signals that a property has been set on the Node such that
<Key> = <Value>.
TREE
Type(Name)
Type(Name)
Type(Name)
Type(Name)
...
This comment signals that a tree of nodes matching the BUILD comment
symatics should exist. This is an exact match.
*/
/** BUILD Implements(A) */
/** PROP REFERENCE=B */
A implements B;
/** ERROR Unexpected ";" after keyword "implements". */
A implements;
/** BUILD Implements(B) */
/** PROP REFERENCE=C */
B implements C;
/** ERROR Unexpected keyword "implements" after "]". */
[foo] implements B;
/** BUILD Implements(D) */
/** PROP REFERENCE=E */
D implements E;
/** ERROR Unexpected keyword "implements" after comment. */
implements C;
......@@ -15,10 +15,6 @@ ERROR Error String
This comment signals that a error of <Error String> is generated. The error
is not assigned to a node, but are expected in order.
PROP Key=Value
This comment signals that a property has been set on the Node such that
<Key> = <Value>.
TREE
Type(Name)
Type(Name)
......
......@@ -15,10 +15,6 @@ ERROR Error String
This comment signals that a error of <Error String> is generated. The error
is not assigned to a node, but are expected in order.
PROP Key=Value
This comment signals that a property has been set on the Node such that
<Key> = <Value>.
TREE
Type(Name)
Type(Name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment