doc/misc.tex: Document many utilities.
[sod] / test / test.sod
index 5779376..ee74da3 100644 (file)
@@ -1,4 +1,28 @@
-/* -*-sod-*- */
+/* -*-sod-*- *
+ *
+ * Test program for Sod functionality
+ *
+ * (c) 2016 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------*
+ *
+ * This file is part of the Sensible Object Design, an object system for C.
+ *
+ * SOD is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * SOD is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with SOD; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
 
 code h: includes {
 #include "sod.h"
@@ -232,11 +256,20 @@ code c: tests {
 [link = SodObject, nick = t2]
 class T2: SodObject {
   [initarg = x] int x = 0;
+  [initarg = z] t2.x;
 
   initarg int y = 1;
   init { if (!y) STEP(0); }
 }
 
+[link = T2]
+class T2Sub: T2 {
+  [initarg = a] t2.x;
+  [initarg = b] t2.x;
+  [initarg = x] t2.x;
+  [initarg = c] t2.x;
+}
+
 code c: tests {
   prepare("initargs, defaults");
   { SOD_DECL(T2, t, NO_KWARGS);
@@ -248,6 +281,21 @@ code c: tests {
     if (t->t2.x == 42) STEP(1);
     DONE(2);
   }
+  prepare("initargs, inheritance");
+  { SOD_DECL(T2Sub, t, KWARGS(K(c, 1) K(z, 2)));
+    if (t->t2.x == 1) STEP(0);
+    DONE(1);
+  }
+  prepare("initargs, ordering");
+  { SOD_DECL(T2Sub, t, KWARGS(K(a, 1) K(b, 2)));
+    if (t->t2.x == 1) STEP(0);
+    DONE(1);
+  }
+  prepare("initargs, reprioritizing");
+  { SOD_DECL(T2Sub, t, KWARGS(K(x, 1) K(c, 2)));
+    if (t->t2.x == 1) STEP(0);
+    DONE(1);
+  }
 }
 
 /*----- Keyword argument propagation --------------------------------------*/
@@ -279,4 +327,24 @@ code c: tests {
   }
 }
 
+/*----- Metaclass initialization ------------------------------------------*/
+
+[link = SodClass, nick = mycls]
+class MyClass: SodClass {
+  int x = -1, y, z = 2;
+}
+
+[link = SodObject, nick = myobj, metaclass = MyClass]
+class MyObject: SodObject {
+  class mycls.x = 0, mycls.y = 1;
+}
+
+code c: tests {
+  prepare("metaclass, init");
+  STEP(MyObject__cls_obj->mycls.x);
+  STEP(MyObject__cls_obj->mycls.y);
+  STEP(MyObject__cls_obj->mycls.z);
+  DONE(3);
+}
+
 /*----- That's all, folks -------------------------------------------------*/