aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/cython/Cython/Compiler/Tests/TestSignatureMatching.py
diff options
context:
space:
mode:
authoralexv-smirnov <alex@ydb.tech>2023-06-13 11:05:01 +0300
committeralexv-smirnov <alex@ydb.tech>2023-06-13 11:05:01 +0300
commitbf0f13dd39ee3e65092ba3572bb5b1fcd125dcd0 (patch)
tree1d1df72c0541a59a81439842f46d95396d3e7189 /contrib/tools/cython/Cython/Compiler/Tests/TestSignatureMatching.py
parent8bfdfa9a9bd19bddbc58d888e180fbd1218681be (diff)
downloadydb-bf0f13dd39ee3e65092ba3572bb5b1fcd125dcd0.tar.gz
add ymake export to ydb
Diffstat (limited to 'contrib/tools/cython/Cython/Compiler/Tests/TestSignatureMatching.py')
-rw-r--r--contrib/tools/cython/Cython/Compiler/Tests/TestSignatureMatching.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/contrib/tools/cython/Cython/Compiler/Tests/TestSignatureMatching.py b/contrib/tools/cython/Cython/Compiler/Tests/TestSignatureMatching.py
new file mode 100644
index 0000000000..166bb225b9
--- /dev/null
+++ b/contrib/tools/cython/Cython/Compiler/Tests/TestSignatureMatching.py
@@ -0,0 +1,73 @@
+import unittest
+
+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 assertMatches(self, expected_type, arg_types, functions):
+ match = pt.best_match(arg_types, functions)
+ if expected_type is not None:
+ self.assertNotEqual(None, match)
+ self.assertEqual(expected_type, match.type)
+
+ def test_cpp_reference_single_arg(self):
+ function_types = [
+ 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 ]
+ self.assertMatches(function_types[0], [pt.c_int_type], functions)
+ self.assertMatches(function_types[1], [pt.c_long_type], functions)
+ self.assertMatches(function_types[2], [pt.c_double_type], functions)
+
+ def test_cpp_reference_two_args(self):
+ function_types = [
+ cfunctype(
+ pt.CReferenceType(pt.c_int_type), pt.CReferenceType(pt.c_long_type)),
+ cfunctype(
+ pt.CReferenceType(pt.c_long_type), pt.CReferenceType(pt.c_long_type)),
+ ]
+
+ functions = [ NameNode(None, type=t) for t in function_types ]
+ self.assertMatches(function_types[0], [pt.c_int_type, pt.c_long_type], functions)
+ self.assertMatches(function_types[1], [pt.c_long_type, pt.c_long_type], functions)
+ self.assertMatches(function_types[1], [pt.c_long_type, pt.c_int_type], functions)
+
+ def test_cpp_reference_cpp_class(self):
+ classes = [ cppclasstype("Test%d"%i, []) for i in range(2) ]
+ function_types = [
+ cfunctype(pt.CReferenceType(classes[0])),
+ cfunctype(pt.CReferenceType(classes[1])),
+ ]
+
+ functions = [ NameNode(None, type=t) for t in function_types ]
+ self.assertMatches(function_types[0], [classes[0]], functions)
+ self.assertMatches(function_types[1], [classes[1]], functions)
+
+ def test_cpp_reference_cpp_class_and_int(self):
+ classes = [ cppclasstype("Test%d"%i, []) for i in range(2) ]
+ function_types = [
+ 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[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)