Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
A
arpeggio-gm
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
backend
arpeggio-gm
Commits
f349b0fc
Commit
f349b0fc
authored
Oct 12, 2014
by
Igor Dejanovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Visitor test
parent
811c7227
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
+59
-0
test_visitor.py
tests/unit/test_visitor.py
+59
-0
No files found.
tests/unit/test_visitor.py
0 → 100644
View file @
f349b0fc
# -*- coding: utf-8 -*-
#######################################################################
# Name: test_semantic_action_results
# Purpose: Tests semantic actions based on visitor
# Author: Igor R. Dejanović <igor DOT dejanovic AT gmail DOT com>
# Copyright: (c) 2014 Igor R. Dejanović <igor DOT dejanovic AT gmail DOT com>
# License: MIT License
#######################################################################
from
__future__
import
unicode_literals
import
pytest
# Grammar
from
arpeggio
import
ZeroOrMore
,
OneOrMore
,
ParserPython
,
\
PTNodeVisitor
,
visit_parse_tree
,
SemanticActionResults
from
arpeggio.export
import
PTDOTExporter
from
arpeggio
import
RegExMatch
as
_
def
grammar
():
return
first
,
"a"
,
second
def
first
():
return
[
fourth
,
third
],
ZeroOrMore
(
third
)
def
second
():
return
OneOrMore
(
third
),
"b"
def
third
():
return
[
third_str
,
fourth
]
def
third_str
():
return
"3"
def
fourth
():
return
_
(
r'\d+'
)
first_sar
=
None
third_sar
=
None
class
TestVisitor
(
PTNodeVisitor
):
def
visit_first
(
self
,
node
,
children
):
global
first_sar
first_sar
=
children
def
visit_third
(
self
,
node
,
children
):
global
third_sar
third_sar
=
children
return
1
def
test_semantic_action_results
():
global
first_sar
,
third_sar
input
=
"4 3 3 3 a 3 3 b"
parser
=
ParserPython
(
grammar
,
reduce_tree
=
False
)
result
=
parser
.
parse
(
input
)
PTDOTExporter
()
.
exportFile
(
result
,
'test_semantic_action_results_pt.dot'
)
visit_parse_tree
(
result
,
TestVisitor
(
defaults
=
True
))
assert
isinstance
(
first_sar
,
SemanticActionResults
)
assert
len
(
first_sar
.
third
)
==
3
assert
third_sar
.
third_str
[
0
]
==
'3'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment