]> ocean-lang.org Git - ocean/blobdiff - csrc/oceani-tests.mdc
oceani: implement struct field initialisation properly.
[ocean] / csrc / oceani-tests.mdc
index 5e911925fd39d5a80c3eec0edc0c37614a486666..d5541e9c3e21ea27ddb418d666789d8062c60beb 100644 (file)
@@ -282,8 +282,9 @@ Here I break it into two parts, keeping the array code separate.
 
 ###### test: sayhello
 
-       program As Bs astr bbool:
+       program As Bs astr bbools:
                A := $As; B := $Bs
+               bbool := bbools == "True"
                print "Hello World, what lovely oceans you have!"
                /* When a variable is defined in both branches of an 'if',
                 * and used afterwards, the variables are merged.
@@ -531,11 +532,15 @@ ad-hoc things array related.
                bools[1] = strings[2] <= "there"
 
                for i:=0; then i=i+1; while i<5:
-                       print '', bools[i],
+                       j ::= i
+                       ra:[j]number
+                       ra[i-1] = i*i
+                       ra[6] = 42 // mustn't crash
+                       print '', bools[i], ra[j-1],
                print
 
 ###### output: arrays
-        False True False False False
+        False 0 True 1 False 4 False 9 False 16
 
 ## Structures
 
@@ -546,10 +551,11 @@ Time to test if structure declarations and accesses work correctly.
 
 ###### test: structs
 
+       const three ::= 3
        struct foo
-               size:[3]number
+               size:[three]number
                name:string
-               active:Boolean
+               active:Boolean = True
 
        struct baz { a:number; b:Boolean; }
 
@@ -565,7 +571,8 @@ Time to test if structure declarations and accesses work correctly.
 
                        info[i].name = nm
                        info[i].size[0] = i*i
-                       info[i].active = nm == "jane"
+                       if nm != "jane":
+                               info[i].active = False
 
                for i:=0; then i=i+1; while i < 4:
                        print info[i].name, info[i].active, info[i].size[0]