local v=require("extend_default")

-- %extend before the class definition
local ex = v.Before()
assert(ex.i == -1 and ex.d == -1, "Before constructor 1 failed")
ex = v.Before(10)
assert(ex.i == 10 and ex.d == -1, "Before constructor 2 failed")
ex = v.Before(20, 30)
assert(ex.i == 20 and ex.d == 30, "Before constructor 3 failed")
ex = v.Before()
assert(ex:AddedMethod() == -2, "Before AddedMethod 1 failed")
assert(ex:AddedMethod(-2) == -3, "Before AddedMethod 2 failed")
assert(ex:AddedMethod(-10, -10) == -20, "Before AddedMethod 3 failed")
assert(v.Before.AddedStaticMethod() == -2, "Before AddedStaticMethod 1 failed")
assert(v.Before.AddedStaticMethod(-2) == -3, "Before AddedStaticMethod 2 failed")
assert(v.Before.AddedStaticMethod(-10, -10) == -20, "Before AddedStaticMethod 3 failed")

-- %extend after the class definition
ex = v.After()
assert(ex.i == -1 and ex.d == -1, "After constructor 1 failed")
ex = v.After(10)
assert(ex.i == 10 and ex.d == -1, "After constructor 2 failed")
ex = v.After(20, 30)
assert(ex.i == 20 and ex.d == 30, "After constructor 3 failed")
ex = v.After()
assert(ex:AddedMethod() == -2, "After AddedMethod 1 failed")
assert(ex:AddedMethod(-2) == -3, "After AddedMethod 2 failed")
assert(ex:AddedMethod(-10, -10) == -20, "After AddedMethod 3 failed")
assert(v.After.AddedStaticMethod() == -2, "After AddedStaticMethod 1 failed")
assert(v.After.AddedStaticMethod(-2) == -3, "After AddedStaticMethod 2 failed")
assert(v.After.AddedStaticMethod(-10, -10) == -20, "After AddedStaticMethod 3 failed")

-- %extend before the class definition - with overloading and default args
ex = v.OverBefore()
assert(ex.i == -1 and ex.d == -1, "OverBefore constructor 1 failed")
ex = v.OverBefore(10)
assert(ex.i == 10 and ex.d == -1, "OverBefore constructor 2 failed")
ex = v.OverBefore(20, 30)
assert(ex.i == 20 and ex.d == 30, "OverBefore constructor 3 failed")
ex = v.OverBefore()
assert(ex:AddedMethod() == -2, "OverBefore AddedMethod 1 failed")
assert(ex:AddedMethod(-2) == -3, "OverBefore AddedMethod 2 failed")
assert(ex:AddedMethod(-10, -10) == -20, "OverBefore AddedMethod 3 failed")
assert(v.OverBefore.AddedStaticMethod() == -2, "OverBefore AddedStaticMethod 1 failed")
assert(v.OverBefore.AddedStaticMethod(-2) == -3, "OverBefore AddedStaticMethod 2 failed")
assert(v.OverBefore.AddedStaticMethod(-10, -10) == -20, "OverBefore AddedStaticMethod 3 failed")
ex = v.OverBefore("hello")
assert(ex.i == -2 and ex.d == -2, "OverBefore overload constructor 1 failed")
ex = v.OverBefore("hello", 10)
assert(ex.i == 10 and ex.d == -2, "OverBefore overload constructor 2 failed")
ex = v.OverBefore("hello", 20, 30)
assert(ex.i == 20 and ex.d == 30, "OverBefore overload constructor 3 failed")
ex = v.OverBefore("hello")
assert(ex:AddedMethod("hello") == -2, "OverBefore overload AddedMethod 1 failed")
assert(ex:AddedMethod("hello", -2) == -3, "OverBefore overload AddedMethod 2 failed")
assert(ex:AddedMethod("hello", -10, -10) == -20, "OverBefore overload AddedMethod 3 failed")
assert(v.OverBefore.AddedStaticMethod("hello") == -2, "OverBefore overload AddedStaticMethod 1 failed")
assert(v.OverBefore.AddedStaticMethod("hello", -2) == -3, "OverBefore overload AddedStaticMethod 2 failed")
assert(v.OverBefore.AddedStaticMethod("hello", -10, -10) == -20, "OverBefore overload AddedStaticMethod 3 failed")

-- %extend after the class definition - with overloading and default args
ex = v.OverAfter()
assert(ex.i == -1 and ex.d == -1, "OverAfter constructor 1 failed")
ex = v.OverAfter(10)
assert(ex.i == 10 and ex.d == -1, "OverAfter constructor 2 failed")
ex = v.OverAfter(20, 30)
assert(ex.i == 20 and ex.d == 30, "OverAfter constructor 3 failed")
ex = v.OverAfter()
assert(ex:AddedMethod() == -2, "OverAfter AddedMethod 1 failed")
assert(ex:AddedMethod(-2) == -3, "OverAfter AddedMethod 2 failed")
assert(ex:AddedMethod(-10, -10) == -20, "OverAfter AddedMethod 3 failed")
assert(v.OverAfter.AddedStaticMethod() == -2, "OverAfter AddedStaticMethod 1 failed")
assert(v.OverAfter.AddedStaticMethod(-2) == -3, "OverAfter AddedStaticMethod 2 failed")
assert(v.OverAfter.AddedStaticMethod(-10, -10) == -20, "OverAfter AddedStaticMethod 3 failed")
ex = v.OverAfter("hello")
assert(ex.i == -2 and ex.d == -2, "OverAfter overload constructor 1 failed")
ex = v.OverAfter("hello", 10)
assert(ex.i == 10 and ex.d == -2, "OverAfter overload constructor 2 failed")
ex = v.OverAfter("hello", 20, 30)
assert(ex.i == 20 and ex.d == 30, "OverAfter overload constructor 3 failed")
ex = v.OverAfter("hello")
assert(ex:AddedMethod("hello") == -2, "OverAfter overload AddedMethod 1 failed")
assert(ex:AddedMethod("hello", -2) == -3, "OverAfter overload AddedMethod 2 failed")
assert(ex:AddedMethod("hello", -10, -10) == -20, "OverAfter overload AddedMethod 3 failed")
assert(v.OverAfter.AddedStaticMethod("hello") == -2, "OverAfter overload AddedStaticMethod 1 failed")
assert(v.OverAfter.AddedStaticMethod("hello", -2) == -3, "OverAfter overload AddedStaticMethod 2 failed")
assert(v.OverAfter.AddedStaticMethod("hello", -10, -10) == -20, "OverAfter overload AddedStaticMethod 3 failed")

-- Override
local o = v.Override()
assert(o:over() == -1, "override test 1 failed")
assert(o:over(10) == 10*10, "override test 2 failed")
assert(o:ride() == -1, "override test 3 failed")
assert(o:ride(10) == 10, "override test 4 failed")
assert(o:overload() == -10, "override test 5 failed")
assert(o:overload(10) == 10*10, "override test 6 failed")
