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
057f6185
Commit
057f6185
authored
Feb 18, 2014
by
Igor Dejanovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unit test for exporter. Small fix in the exporter.
parent
715b0886
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
1 deletion
+56
-1
export.py
arpeggio/export.py
+1
-1
test_exporter.py
tests/test_exporter.py
+55
-0
No files found.
arpeggio/export.py
View file @
057f6185
...
...
@@ -153,7 +153,7 @@ class PTDOTExportAdapter(PMDOTExportAdapter):
else
:
if
not
hasattr
(
self
,
"_neighbours"
):
self
.
_neighbours
=
[]
for
c
,
n
in
enumerate
(
self
.
adaptee
.
nodes
):
for
c
,
n
in
enumerate
(
self
.
adaptee
):
adapter
=
PTDOTExportAdapter
(
n
,
self
.
export
)
self
.
_neighbours
.
append
((
str
(
c
+
1
),
adapter
))
return
self
.
_neighbours
...
...
tests/test_exporter.py
0 → 100644
View file @
057f6185
# -*- coding: utf-8 -*-
#######################################################################
# Name: test_python_parser
# Purpose: Test for parser constructed using Python-based grammars.
# 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
#######################################################################
import
os
from
unittest
import
TestCase
from
arpeggio.export
import
PMDOTExporter
,
PTDOTExporter
# Grammar
from
arpeggio
import
Optional
,
ZeroOrMore
,
OneOrMore
,
EndOfFile
,
ParserPython
,
Sequence
,
NonTerminal
from
arpeggio
import
RegExMatch
as
_
def
number
():
return
_
(
r'\d*\.\d*|\d+'
)
def
factor
():
return
Optional
([
"+"
,
"-"
]),
[
number
,
(
"("
,
expression
,
")"
)]
def
term
():
return
factor
,
ZeroOrMore
([
"*"
,
"/"
],
factor
)
def
expression
():
return
term
,
ZeroOrMore
([
"+"
,
"-"
],
term
)
def
calc
():
return
OneOrMore
(
expression
),
EndOfFile
class
TestPythonParser
(
TestCase
):
def
setUp
(
self
):
"""
Create parser
"""
self
.
parser
=
ParserPython
(
calc
)
def
test_export_parser_model
(
self
):
"""
Testing parser model export
"""
PMDOTExporter
()
.
exportFile
(
self
.
parser
.
parser_model
,
"test_exporter_parser_model.dot"
)
self
.
assertTrue
(
os
.
path
.
exists
(
"test_exporter_parser_model.dot"
))
def
test_export_parse_tree
(
self
):
"""
Testing parse tree export.
"""
parse_tree
=
self
.
parser
.
parse
(
"-(4-1)*5+(2+4.67)+5.89/(.2+7)"
)
PTDOTExporter
()
.
exportFile
(
parse_tree
,
"test_exporter_parse_tree.dot"
)
self
.
assertTrue
(
os
.
path
.
exists
(
"test_exporter_parse_tree.dot"
))
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