Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
b614aa32
Commit
b614aa32
authored
Aug 30, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up and simplify signature matching test
parent
df57c172
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
23 deletions
+23
-23
Cython/Compiler/Tests/TestSignatureMatching.py
Cython/Compiler/Tests/TestSignatureMatching.py
+23
-23
No files found.
Cython/Compiler/Tests/TestSignatureMatching.py
View file @
b614aa32
...
...
@@ -4,17 +4,17 @@ from Cython.Compiler import PyrexTypes as pt
from
Cython.Compiler.ExprNodes
import
NameNode
from
Cython.Compiler.PyrexTypes
import
CFuncTypeArg
def
cfunctype
(
*
arg_types
):
return
pt
.
CFuncType
(
pt
.
c_int_type
,
[
CFuncTypeArg
(
"name"
,
arg_type
,
None
)
for
arg_type
in
arg_types
])
def
cppclasstype
(
name
,
base_classes
):
return
pt
.
CppClassType
(
name
,
None
,
'CPP_'
+
name
,
base_classes
)
class
SignatureMatcherTest
(
unittest
.
TestCase
):
"""
Test the signature matching algorithm for overloaded signatures.
"""
def
_cfunctype
(
self
,
return_type
,
*
arg_types
):
return
pt
.
CFuncType
(
return_type
,
[
CFuncTypeArg
(
"name"
,
arg_type
,
None
)
for
arg_type
in
arg_types
])
def
_cppclasstype
(
self
,
name
,
base_classes
):
return
pt
.
CppClassType
(
name
,
None
,
'CPP_'
+
name
,
base_classes
)
def
assertMatches
(
self
,
expected_type
,
arg_types
,
functions
):
args
=
[
NameNode
(
None
,
type
=
arg_type
)
for
arg_type
in
arg_types
]
match
=
pt
.
best_match
(
args
,
functions
)
...
...
@@ -24,9 +24,9 @@ class SignatureMatcherTest(unittest.TestCase):
def
test_cpp_reference_single_arg
(
self
):
function_types
=
[
self
.
_cfunctype
(
pt
.
c_int_type
,
pt
.
CReferenceType
(
pt
.
c_int_type
)),
self
.
_cfunctype
(
pt
.
c_long_type
,
pt
.
CReferenceType
(
pt
.
c_long_type
)),
self
.
_cfunctype
(
pt
.
c_double_type
,
pt
.
CReferenceType
(
pt
.
c_double_type
)),
cfunctype
(
pt
.
CReferenceType
(
pt
.
c_int_type
)),
cfunctype
(
pt
.
CReferenceType
(
pt
.
c_long_type
)),
cfunctype
(
pt
.
CReferenceType
(
pt
.
c_double_type
)),
]
functions
=
[
NameNode
(
None
,
type
=
t
)
for
t
in
function_types
]
...
...
@@ -36,11 +36,9 @@ class SignatureMatcherTest(unittest.TestCase):
def
test_cpp_reference_two_args
(
self
):
function_types
=
[
self
.
_cfunctype
(
pt
.
c_int_type
,
cfunctype
(
pt
.
CReferenceType
(
pt
.
c_int_type
),
pt
.
CReferenceType
(
pt
.
c_long_type
)),
self
.
_cfunctype
(
pt
.
c_int_type
,
cfunctype
(
pt
.
CReferenceType
(
pt
.
c_long_type
),
pt
.
CReferenceType
(
pt
.
c_long_type
)),
]
...
...
@@ -50,10 +48,10 @@ class SignatureMatcherTest(unittest.TestCase):
self
.
assertMatches
(
function_types
[
1
],
[
pt
.
c_long_type
,
pt
.
c_int_type
],
functions
)
def
test_cpp_reference_cpp_class
(
self
):
classes
=
[
self
.
_
cppclasstype
(
"Test%d"
%
i
,
[])
for
i
in
range
(
2
)
]
classes
=
[
cppclasstype
(
"Test%d"
%
i
,
[])
for
i
in
range
(
2
)
]
function_types
=
[
self
.
_cfunctype
(
pt
.
c_int_type
,
pt
.
CReferenceType
(
classes
[
0
])),
self
.
_cfunctype
(
pt
.
c_int_type
,
pt
.
CReferenceType
(
classes
[
1
])),
cfunctype
(
pt
.
CReferenceType
(
classes
[
0
])),
cfunctype
(
pt
.
CReferenceType
(
classes
[
1
])),
]
functions
=
[
NameNode
(
None
,
type
=
t
)
for
t
in
function_types
]
...
...
@@ -61,14 +59,16 @@ class SignatureMatcherTest(unittest.TestCase):
self
.
assertMatches
(
function_types
[
1
],
[
classes
[
1
]],
functions
)
def
test_cpp_reference_cpp_class_and_int
(
self
):
classes
=
[
self
.
_
cppclasstype
(
"Test%d"
%
i
,
[])
for
i
in
range
(
2
)
]
classes
=
[
cppclasstype
(
"Test%d"
%
i
,
[])
for
i
in
range
(
2
)
]
function_types
=
[
self
.
_cfunctype
(
pt
.
c_int_type
,
pt
.
CReferenceType
(
classes
[
0
]),
pt
.
c_int
_type
),
self
.
_cfunctype
(
pt
.
c_int_type
,
pt
.
CReferenceType
(
classes
[
1
]),
pt
.
c_long_type
),
cfunctype
(
pt
.
CReferenceType
(
classes
[
0
]),
pt
.
c_int_type
)
,
cfunctype
(
pt
.
CReferenceType
(
classes
[
0
]),
pt
.
c_long
_type
),
cfunctype
(
pt
.
CReferenceType
(
classes
[
1
]),
pt
.
c_int_type
)
,
cfunctype
(
pt
.
CReferenceType
(
classes
[
1
]),
pt
.
c_long_type
),
]
functions
=
[
NameNode
(
None
,
type
=
t
)
for
t
in
function_types
]
self
.
assertMatches
(
function_types
[
0
],
[
classes
[
0
],
pt
.
c_int_type
],
functions
)
self
.
assertMatches
(
function_types
[
1
],
[
classes
[
1
],
pt
.
c_int_type
],
functions
)
self
.
assertMatches
(
function_types
[
1
],
[
classes
[
0
],
pt
.
c_long_type
],
functions
)
self
.
assertMatches
(
function_types
[
2
],
[
classes
[
1
],
pt
.
c_int_type
],
functions
)
self
.
assertMatches
(
function_types
[
3
],
[
classes
[
1
],
pt
.
c_long_type
],
functions
)
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