]> ocean-lang.org Git - ocean/blobdiff - csrc/oceani-tests.mdc
oceani: add structs
[ocean] / csrc / oceani-tests.mdc
index 102c957b0b4e459327e1418aa1f7e4b33ba3dde8..5be4c5aa89d488467463974cb5a7c28f5a76c495 100644 (file)
@@ -499,6 +499,46 @@ ad-hoc things array related.
 ###### output: arrays
         False True False False False
 
+## Structures
+
+Time to test if structure declarations and accesses work correctly.
+
+###### test list
+       oceani_tests += structs
+
+###### test: structs
+
+       struct foo:
+               size:[3]number
+               name:string
+               active:Boolean
+
+       struct baz { a:number; b:Boolean; }
+
+       program:
+               info:[4]foo
+
+               for i:=0; then i=i+1; while i < 4:
+                       switch i
+                       case 2: nm:= "peter"
+                       case 0: nm:= "bob"
+                       case 1: nm:= "jane"
+                       else: nm:= "janine"
+
+                       info[i].name = nm
+                       info[i].size[0] = i*i
+                       info[i].active = nm == "jane"
+
+               for i:=0; then i=i+1; while i < 4:
+                       print info[i].name, info[i].active, info[i].size[0]
+
+###### output: structs
+
+       bob False 0
+       jane True 1
+       peter False 4
+       janine False 9
+
 ## Test code with syntax errors
 
 Syntax errors aren't handled well yet - the result is almost always a
@@ -634,6 +674,10 @@ various places that `type_err()` are called.
 
 ###### test: type_err3
 
+       struct foo:
+               a: number
+               b:string = "hello"
+
        program:
                c := "hello"
                c = c + 1
@@ -659,30 +703,37 @@ various places that `type_err()` are called.
                a4[1] = True
                c = a2[3]
 
+               bar:foo
+               foo.c = 43
+               print c.foo
+
 ###### output: type_err3
-       .tmp.code:4:12: error: expected number but variable 'c' is string
-       .tmp.code:3:8: info: this is where 'c' was set to string
-       .tmp.code:4:12: error: Arithmetic returns number but string expected
-       .tmp.code:3:8: info: variable 'c' was set as string here.
-       .tmp.code:5:24: error: Boolean operation found where string expected
-       .tmp.code:6:12: error: Comparison returns Boolean but string expected
-       .tmp.code:3:8: info: variable 'c' was set as string here.
-       .tmp.code:7:21: error: Concat returns string but number expected
-       .tmp.code:8:8: error: string cannot be indexed
-       .tmp.code:8:8: error: string cannot be indexed
-       .tmp.code:17:13: error: expected number found string
-       .tmp.code:13:16: error: expected number, found string
-       .tmp.code:20:8: error: cannot assign value of type [5]number
-       .tmp.code:21:13: error: expected [5]number but variable 'a3' is [10]number
-       .tmp.code:19:36: info: this is where 'a3' was set to [10]number
-       .tmp.code:21:8: error: cannot assign value of type [5]number
-       .tmp.code:22:13: error: expected [5]number but variable 'a4' is [5]string
-       .tmp.code:19:51: info: this is where 'a4' was set to [5]string
-       .tmp.code:22:8: error: cannot assign value of type [5]number
-       .tmp.code:23:16: error: expected number found string
-       .tmp.code:24:16: error: expected string found Boolean
-       .tmp.code:25:12: error: have number but need string
-       .tmp.code:3:8: info: variable 'c' was set as string here.
+       .tmp.code:8:12: error: expected number but variable 'c' is string
+       .tmp.code:7:8: info: this is where 'c' was set to string
+       .tmp.code:8:12: error: Arithmetic returns number but string expected
+       .tmp.code:7:8: info: variable 'c' was set as string here.
+       .tmp.code:9:24: error: Boolean operation found where string expected
+       .tmp.code:10:12: error: Comparison returns Boolean but string expected
+       .tmp.code:7:8: info: variable 'c' was set as string here.
+       .tmp.code:11:21: error: Concat returns string but number expected
+       .tmp.code:12:8: error: string cannot be indexed
+       .tmp.code:12:8: error: string cannot be indexed
+       .tmp.code:21:13: error: expected number found string
+       .tmp.code:17:16: error: expected number, found string
+       .tmp.code:24:8: error: cannot assign value of type [5]number
+       .tmp.code:25:13: error: expected [5]number but variable 'a3' is [10]number
+       .tmp.code:23:36: info: this is where 'a3' was set to [10]number
+       .tmp.code:25:8: error: cannot assign value of type [5]number
+       .tmp.code:26:13: error: expected [5]number but variable 'a4' is [5]string
+       .tmp.code:23:51: info: this is where 'a4' was set to [5]string
+       .tmp.code:26:8: error: cannot assign value of type [5]number
+       .tmp.code:27:16: error: expected number found string
+       .tmp.code:28:16: error: expected string found Boolean
+       .tmp.code:29:12: error: have number but need string
+       .tmp.code:7:8: info: variable 'c' was set as string here.
+       .tmp.code:32:8: error: field reference attempted on label, not a struct
+       .tmp.code:32:16: error: expected none found number
+       .tmp.code:33:14: error: field reference attempted on string, not a struct
        oceani: type error in program - not running.
 
 ###### test: type_err4
@@ -777,4 +828,3 @@ command list possible.
 
 ###### output: cmd,--section,toast:nothing,oceani-tests.mdc
        oceani: cannot find section toast:nothing
-