Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue#42 #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions plyj/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,15 +643,6 @@ def __init__(self, block, catches=None, _finally=None, resources=None):
self._finally = _finally
self.resources = resources

def accept(self, visitor):
if visitor.visit_Try(self):
for s in self.block:
s.accept(visitor)
for c in self.catches:
visitor.visit_Catch(c)
if self._finally:
self._finally.accept(visitor)


class Catch(SourceElement):

Expand Down
34 changes: 34 additions & 0 deletions test/visitors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import unittest

import plyj.parser as plyj
import plyj.model as model


class VisitorTest(unittest.TestCase):

def setUp(self):
self.parser = plyj.Parser()

def test_visit_expressions_in_try_catch(self):
statement = '''
try {
b = c;
} catch(Exception e) {
method(1, 2);
}
'''
s = self.parser.parse_statement(statement)

class TestVisitor(model.Visitor):
def __init__(self):
super(TestVisitor, self).__init__()
self._count = 0

def visit_ExpressionStatement(self, expression_statement):
self._count += 1
return True

visitor = TestVisitor()
s.accept(visitor)
self.assertEqual(visitor._count, 2,
'for {} \nNumber of Expressions got: {}, expected: {}'.format(statement, visitor._count, 2))