Finish implementation with proxy functions
This commit is contained in:
parent
559128e14e
commit
7c8405368e
4 changed files with 285 additions and 2 deletions
|
|
@ -30,6 +30,19 @@ class Foo {
|
|||
}
|
||||
|
||||
int (Foo::*func_ptr)(int);
|
||||
|
||||
const char* __str__() const { return "Foo"; }
|
||||
};
|
||||
|
||||
class FooSub : public Foo {
|
||||
public:
|
||||
FooSub() :Foo(42) {}
|
||||
};
|
||||
|
||||
class FooSubSub : public FooSub {
|
||||
public:
|
||||
FooSubSub() : FooSub() {}
|
||||
const char* __str__() const { return "FooSubSub"; }
|
||||
};
|
||||
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -76,3 +76,13 @@ assert(cb.test_func_ptr(f,2)==-8)
|
|||
|
||||
-- Test that __tostring metamethod produce no internal asserts
|
||||
f2_name = tostring(f2)
|
||||
|
||||
f3 = cb.FooSub()
|
||||
f3_name = tostring(f3)
|
||||
|
||||
f4 = cb.FooSubSub()
|
||||
f4_name = tostring(f4)
|
||||
|
||||
assert( f2_name == "Foo" )
|
||||
assert( f3_name == "Foo" )
|
||||
assert( f4_name == "FooSubSub" )
|
||||
|
|
|
|||
|
|
@ -78,6 +78,38 @@ assert(i(1,2)==6)
|
|||
assert(tostring(Op(1))=="Op(1)")
|
||||
assert(tostring(Op(-3))=="Op(-3)")
|
||||
|
||||
|
||||
-- check that operator overloads is correctly propogated accross hierarchy
|
||||
|
||||
a_d=OpDerived()
|
||||
b_d=OpDerived(5)
|
||||
c_d=OpDerived(5)
|
||||
d_d=OpDerived(2)
|
||||
-- test equality
|
||||
assert(a_d~=b_d)
|
||||
assert(b_d==c_d)
|
||||
assert(a_d~=d_d)
|
||||
|
||||
-- test <
|
||||
assert(a_d<b_d)
|
||||
assert(a_d<=b_d)
|
||||
assert(b_d<=c_d)
|
||||
assert(b_d>=c_d)
|
||||
assert(b_d>d_d)
|
||||
assert(b_d>=d_d)
|
||||
--
|
||||
-- test + inheritance
|
||||
f_d=OpDerived(1)
|
||||
g_d=OpDerived(1)
|
||||
assert(f_d+g_d==Op(2))
|
||||
assert(f_d-g_d==Op(0))
|
||||
assert(f_d*g_d==Op(1))
|
||||
assert(f_d/g_d==Op(1))
|
||||
--
|
||||
-- plus add some code to check the __str__ fn inheritance
|
||||
assert(tostring(OpDerived(1))=="Op(1)")
|
||||
assert(tostring(OpDerived(-3))=="Op(-3)")
|
||||
|
||||
--[[
|
||||
/* Sample test code in C++
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue