src/method-aggregate.lisp: Allow useful behaviour if no primary methods.
[sod] / test / test.sod
index 192f631..f794c76 100644 (file)
@@ -137,28 +137,39 @@ static int check_vec(struct vec *v, ...)
 
 [link = SodObject, nick = t1base]
 class T1Base: SodObject {
-  [combination = progn] void aprogn() { STEP(1); }
-  [combination = sum] int asum() { return 1; }
-  [combination = and] int aand() { return 8; }
-  [combination = max] int amax() { return 12; }
+  [combination = progn] void aprogn();
+  [combination = sum] int asum();
+  [combination = and] int aand();
+  [combination = max] int amax();
 
   [combination = custom,
+   empty = { sod_ret = 0; },
    decls = { struct item **head = &sod_ret; },
    each = { *head = sod_val; head = &sod_val->next; },
    after = { *head = 0; }]
-  struct item *alist() { return make_item("base"); }
+  struct item *alist();
 
   [combination = custom,
    decls = { int *v; size_t i = 0; }, methty = <int>, count = n,
+   empty = { sod_ret.v = 0; sod_ret.n = 0; },
    before = { v = xmalloc(n*sizeof(int)); },
    each = { v[i++] = sod_val; },
    after = { sod_ret.v = v; sod_ret.n = n; }]
   struct vec avec();
+}
+
+[link = T1Base, nick = t1mid]
+class T1Mid: T1Base {
+  void t1base.aprogn() { STEP(1); }
+  int t1base.asum() { return 1; }
+  int t1base.aand() { return 8; }
+  int t1base.amax() { return 12; }
+  struct item *t1base.alist() { return make_item("mid"); }
   int t1base.avec() { return 19; }
 }
 
-[link = T1Base, nick = t1sub]
-class T1Sub: T1Base {
+[link = T1Mid, nick = t1sub]
+class T1Sub: T1Mid {
   void t1base.aprogn() { STEP(0); }
   int t1base.asum() { return 2; }
   int t1base.aand() { return 6; }
@@ -172,12 +183,26 @@ code c: tests {
   { SOD_DECL(T1Base, t1, NO_KWARGS);
     struct item *l;
     struct vec v;
+    STEP(0); T1Base_aprogn(t1); STEP(1);
+    if (T1Base_asum(t1) == 0) STEP(2);
+    if (T1Base_aand(t1) == 1) STEP(3);
+    if (!t1->_vt->t1base.amax) STEP(4);
+    l = T1Base_alist(t1);
+    if (!l) STEP(5);
+    v = T1Base_avec(t1);
+    if (!v.n) STEP(6);
+    DONE(7);
+  }
+  prepare("aggregate, mid");
+  { SOD_DECL(T1Mid, t1, NO_KWARGS);
+    struct item *l;
+    struct vec v;
     STEP(0); T1Base_aprogn(t1); /* 1 */
     if (T1Base_asum(t1) == 1) STEP(2);
     if (T1Base_aand(t1) == 8) STEP(3);
     if (T1Base_amax(t1) == 12) STEP(4);
     l = T1Base_alist(t1);
-    if (!check_list(l, "base", (const char *)0)) STEP(5);
+    if (!check_list(l, "mid", (const char *)0)) STEP(5);
     free_list(l);
     v = T1Base_avec(t1);
     if (!check_vec(&v, 19, -1)) STEP(6);
@@ -193,7 +218,7 @@ code c: tests {
     if (T1Base_aand(t1) == 8) STEP(3);
     if (T1Base_amax(t1) == 17) STEP(4);
     l = T1Base_alist(t1);
-    if (!check_list(l, "sub", "base", (const char *)0)) STEP(5);
+    if (!check_list(l, "sub", "mid", (const char *)0)) STEP(5);
     free_list(l);
     v = T1Base_avec(t1);
     if (!check_vec(&v, 4, 19, -1)) STEP(6);