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
d220578f
Commit
d220578f
authored
Dec 29, 2014
by
Igor Dejanovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unit tests for parser parameters.
parent
3805e6f6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
0 deletions
+81
-0
test_parser_params.py
tests/unit/test_parser_params.py
+81
-0
No files found.
tests/unit/test_parser_params.py
0 → 100644
View file @
d220578f
# -*- coding: utf-8 -*-
#######################################################################
# Name: test_parser_params
# Purpose: Test for parser parameters.
# 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
from
arpeggio
import
ParserPython
,
NoMatch
from
arpeggio
import
RegExMatch
as
_
def
test_autokwd
():
"""
autokwd will match keywords on word boundaries.
"""
def
grammar
():
return
(
"one"
,
"two"
,
"three"
)
parser
=
ParserPython
(
grammar
,
autokwd
=
True
)
# If autokwd is enabled this should parse without error.
parser
.
parse
(
"one two three"
)
# But this will not parse because each word to match
# will be, by default, tried to match as a whole word
with
pytest
.
raises
(
NoMatch
):
parser
.
parse
(
"onetwothree"
)
parser
=
ParserPython
(
grammar
,
autokwd
=
False
)
# If we turn off the autokwd than this will match.
parser
.
parse
(
"one two three"
)
parser
.
parse
(
"onetwothree"
)
def
test_skipws
():
"""
skipws will skip whitespaces.
"""
def
grammar
():
return
(
"one"
,
"two"
,
"three"
)
parser
=
ParserPython
(
grammar
)
# If skipws is on this should parse without error.
parser
.
parse
(
"one two three"
)
# If not the same input will raise exception.
parser
=
ParserPython
(
grammar
,
skipws
=
False
)
with
pytest
.
raises
(
NoMatch
):
parser
.
parse
(
"one two three"
)
def
test_ws
():
"""
ws consists of chars that will be skipped if skipws is enables.
By default it consists of space, tab and newline.
"""
def
grammar
():
return
(
"one"
,
"two"
,
"three"
)
parser
=
ParserPython
(
grammar
)
# With default ws this should parse without error
parser
.
parse
(
"""one
two three"""
)
# If we make only a space char to be ws than the
# same input will raise exception.
parser
=
ParserPython
(
grammar
,
ws
=
" "
)
with
pytest
.
raises
(
NoMatch
):
parser
.
parse
(
"""one
two three"""
)
# But if only spaces are between words than it will
# parse.
parser
.
parse
(
"one two three"
)
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