From: Danilo Freitas Date: Mon, 24 Aug 2009 20:31:31 +0000 (-0300) Subject: Tests for operators and templates X-Git-Tag: 0.13.beta0~353^2~42 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=dffd0a32cd818ce4bd845e47020f750f1301ff29;p=cython.git Tests for operators and templates --- diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index acadd2b9..04eaee09 100755 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -1422,8 +1422,8 @@ class CppClassType(CType): return PyrexTypes.error_type if len(self.templates) != len(template_values): error(pos, "%s templated type receives %d arguments, got %d" % - (base_type, len(self.templates), len(template_values))) - return PyrexTypes.error_type + (self.name, len(self.templates), len(template_values))) + return error_type return self.specialize(dict(zip(self.templates, template_values))) def specialize(self, values): diff --git a/tests/compile/operators.h b/tests/compile/operators.h new file mode 100644 index 00000000..f719a3dc --- /dev/null +++ b/tests/compile/operators.h @@ -0,0 +1,26 @@ +#ifndef _OPERATORS_H_ +#define _OPERATORS_H_ + +class Operators +{ +public: + int value; + Operators() { } + Operators(int value) { this->value = value; } + virtual ~Operators() { } + Operators operator+(Operators f) { return Operators(this->value + f.value); } + Operators operator-(Operators f) { return Operators(this->value - f.value); } + Operators operator*(Operators f) { return Operators(this->value * f.value); } + Operators operator/(Operators f) { return Operators(this->value / f.value); } + bool operator<(Operators f) { return this->value < f.value; } + bool operator<=(Operators f) { return this->value <= f.value; } + bool operator==(Operators f) { return this->value == f.value; } + bool operator!=(Operators f) { return this->value != f.value; } + bool operator>(Operators f) { return this->value > f.value; } + bool operator>=(Operators f) { return this->value >= f.value; } + Operators operator>>(int v) { return Operators(this->value >> v); } + Operators operator<<(int v) { return Operators(this->value << v); } + Operators operator%(int v) { return Operators(this->value % v); } +}; + +#endif diff --git a/tests/compile/operators.pyx b/tests/compile/operators.pyx new file mode 100644 index 00000000..f1f20abd --- /dev/null +++ b/tests/compile/operators.pyx @@ -0,0 +1,36 @@ +cdef extern from "operators.h": + cdef cppclass Operators: + __init__(int) + Operators __add__(Operators, Operators) + Operators __sub__(Operators, Operators) + Operators __mul__(Operators, Operators) + Operators __div__(Operators, Operators) + bool __lt__(Operators, Operators) + bool __le__(Operators, Operators) + bool __eq__(Operators, Operators) + bool __ne__(Operators, Operators) + bool __gt__(Operators, Operators) + bool __ge__(Operators, Operators) + Operators __rshift__(Operators, int) + Operators __lshift__(Operators, int) + Operators __mod__(Operators, int) + +cdef int v = 10 +cdef Operators a +cdef Operators b +cdef Operators c + +c = a + b +c = a - b +c = a * b +c = a / b +c = a << 2 +c = a >> 1 +c = b % 2 +a < b +a <= b +a == b +a != b +a > b +a >= b + diff --git a/tests/compile/templates.h b/tests/compile/templates.h new file mode 100644 index 00000000..7a139117 --- /dev/null +++ b/tests/compile/templates.h @@ -0,0 +1,25 @@ +#ifndef _TEMPLATES_H_ +#define _TEMPLATES_H_ + +template +class TemplateTest1 +{ +public: + T value; + int t; + TemplateTest1() { } + T getValue() { return value; } +}; + +template +class TemplateTest2 +{ +public: + T value1; + U value2; + TemplateTest2() { } + T getValue1() { return value1; } + U getValue2() { return value2; } +}; + +#endif diff --git a/tests/compile/templates.pyx b/tests/compile/templates.pyx new file mode 100644 index 00000000..fb1b2cc3 --- /dev/null +++ b/tests/compile/templates.pyx @@ -0,0 +1,28 @@ +cdef extern from "templates.h": + cdef cppclass TemplateTest1[T]: + __init__() + T value + int t + T getValue() + + cdef cppclass TemplateTest2[T, U]: + __init__() + T value1 + U value2 + T getValue1() + U getValue2() + +cdef TemplateTest1[int] a +cdef TemplateTest1[int]* b = new TemplateTest1[int]() + +cdef int c = a.getValue() +c = b.getValue() + +cdef TemplateTest2[int, char] d +cdef TemplateTest2[int, char]* e = new TemplateTest2[int, char]() + +c = d.getValue1() +c = e.getValue2() + +cdef char f = d.getValue2() +f = e.getValue2()