Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
peephole
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
peephole
Commits
945d7583
Commit
945d7583
authored
Dec 22, 2011
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Created som unit tests for statement class.
parent
ed760ad8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
1 deletion
+33
-1
src/statement.py
src/statement.py
+10
-1
tests/test_statement.py
tests/test_statement.py
+23
-0
No files found.
src/statement.py
View file @
945d7583
...
...
@@ -5,7 +5,7 @@ class Statement:
def
__init__
(
self
,
stype
,
name
,
*
args
,
**
kwargs
):
self
.
stype
=
stype
self
.
name
=
name
self
.
args
=
args
self
.
args
=
list
(
args
)
self
.
options
=
kwargs
def
__getitem__
(
self
,
n
):
...
...
@@ -52,6 +52,12 @@ class Statement:
and
re
.
match
(
'^j|jal|beq|bne|blez|bgtz|bltz|bgez|bct|bcf$'
,
\
self
.
name
)
def
is_branch
(
self
):
"""Check if the statement is a branch."""
return
self
.
is_command
()
\
and
re
.
match
(
'^beq|bne|blez|bgtz|bltz|bgez|bct|bcf$'
,
\
self
.
name
)
def
is_shift
(
self
):
"""Check if the statement is a shift operation."""
return
self
.
is_command
()
and
re
.
match
(
'^s(ll|la|rl|ra)$'
,
self
.
name
)
...
...
@@ -81,6 +87,9 @@ class Block:
def __iter__(self):
return iter(self.statements)
def __getitem__(self, n):
return self.statements[n]
def __len__(self):
return len(self.statements)
...
...
tests/test_statement.py
View file @
945d7583
...
...
@@ -6,6 +6,7 @@ from src.statement import Statement as S, Block as B
class
TestStatement
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
statement
=
S
(
'command'
,
'foo'
,
'$1'
)
self
.
block
=
B
([
S
(
'command'
,
'foo'
),
\
S
(
'comment'
,
'bar'
),
S
(
'command'
,
'baz'
)])
...
...
@@ -13,6 +14,13 @@ class TestStatement(unittest.TestCase):
def
tearDown
(
self
):
del
self
.
block
def
test_getitem
(
self
):
self
.
assertEqual
(
self
.
statement
[
0
],
'$1'
)
def
test_setitem
(
self
):
self
.
statement
[
0
]
=
'$2'
self
.
assertEqual
(
self
.
statement
[
0
],
'$2'
)
def
test_eq
(
self
):
self
.
assertTrue
(
S
(
'command'
,
'foo'
)
==
S
(
'command'
,
'foo'
))
self
.
assertFalse
(
S
(
'command'
,
'foo'
)
==
S
(
'command'
,
'bar'
))
...
...
@@ -69,3 +77,18 @@ class TestStatement(unittest.TestCase):
self
.
block
.
apply_filter
(
lambda
s
:
s
.
is_command
())
self
.
assertEqual
(
self
.
block
.
statements
,
[
S
(
'command'
,
'foo'
),
\
S
(
'command'
,
'baz'
)])
def
test_is_shift
(
self
):
self
.
assertTrue
(
S
(
'command'
,
'sll'
).
is_shift
())
self
.
assertFalse
(
S
(
'command'
,
'foo'
).
is_shift
())
self
.
assertFalse
(
S
(
'label'
,
'sll'
).
is_shift
())
def
test_is_load
(
self
):
self
.
assertTrue
(
S
(
'command'
,
'lw'
).
is_load
())
self
.
assertFalse
(
S
(
'command'
,
'foo'
).
is_load
())
self
.
assertFalse
(
S
(
'label'
,
'lw'
).
is_load
())
def
test_is_arith
(
self
):
self
.
assertTrue
(
S
(
'command'
,
'add'
,
'$1'
,
'$2'
,
'$3'
).
is_arith
())
self
.
assertFalse
(
S
(
'command'
,
'foo'
).
is_arith
())
self
.
assertFalse
(
S
(
'label'
,
'add'
).
is_arith
())
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