chiark / gitweb /
src/method-proto.lisp (invoke-delegation-chain): Pass keyword args correctly.
[sod] / test / test.sod
index 71fdd68c28753c7810b63d124be058307ce80b24..776228b11d4770cecc872e02f6980e5e006ab493 100644 (file)
@@ -202,4 +202,56 @@ 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 = mid]
+class T3Mid : T3Base {
+  void base.m0(?int y) { STEP(y); CALL_NEXT_METHOD; }
+  void base.m1(?) { STEP(4); CALL_NEXT_METHOD; }
+}
+
+[link = T3Mid, nick = sub]
+class T3Sub : T3Mid {
+  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(y, 1) K(x, 2)));
+    T3Base_m1(t, KWARGS(K(z, 3)));
+    DONE(5);
+  }
+}
+
 /*----- That's all, folks -------------------------------------------------*/