X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/284f1fa2ace3e276052ff1bd7d66442500e693da..bce58d373fad048a8e30bd1794953f7ebb081540:/test/test.sod diff --git a/test/test.sod b/test/test.sod index e5025b5..6bc775b 100644 --- a/test/test.sod +++ b/test/test.sod @@ -169,7 +169,7 @@ class T1Sub : T1Base { code c : tests { prepare("aggregate, base"); - { SOD_DECL(T1Base, t1); + { SOD_DECL(T1Base, t1, NO_KWARGS); struct item *l; struct vec v; STEP(0); T1Base_aprogn(t1); /* 1 */ @@ -185,7 +185,7 @@ code c : tests { DONE(7); } prepare("aggregate, sub"); - { SOD_DECL(T1Sub, t1); + { SOD_DECL(T1Sub, t1, NO_KWARGS); struct item *l; struct vec v; T1Base_aprogn(t1); /* 0, 1 */ @@ -202,4 +202,50 @@ code c : tests { } } +/*----- Slot and user initargs --------------------------------------------*/ + +[link = SodObject, nick = t2] +class T2 : SodObject { + [initarg = x] int x = 0; + + initarg int y = 1; + init { if (!y) STEP(0); } +} + +code c : tests { + prepare("initargs, defaults"); + { SOD_DECL(T2, t, NO_KWARGS); + if (t->t2.x == 0) STEP(0); + DONE(1); + } + prepare("initargs, explicit"); + { SOD_DECL(T2, t, KWARGS(K(x, 42) K(y, 0))); + if (t->t2.x == 42) STEP(1); + DONE(2); + } +} + +/*----- Keyword argument propagation --------------------------------------*/ + +[link = SodObject, nick = base] +class T3Base : SodObject { + void m0(?int x) { STEP(x); } + void m1(?) { } +} + +[link = T3Base, nick = sub] +class T3Sub : T3Base { + void base.m0(?int z) { STEP(z); CALL_NEXT_METHOD; } + void base.m1(?int z) { STEP(z); CALL_NEXT_METHOD; } +} + +code c : tests { + prepare("kwargs"); + { SOD_DECL(T3Sub, t, NO_KWARGS); + T3Base_m0(t, KWARGS(K(z, 0) K(x, 1))); + T3Base_m1(t, KWARGS(K(z, 2))); + DONE(3); + } +} + /*----- That's all, folks -------------------------------------------------*/