X-Git-Url: https://ocean-lang.org/code/?a=blobdiff_plain;f=csrc%2Foceani-tests.mdc;h=b613ffe484133dd040753b3fa27c129635c37839;hb=ae5eb8c9a77d3d5c08db91ae0ca1f86762172a79;hp=958575c63cb4e1860d4fb88d1501df726b8fc8a7;hpb=038c114a1ceec224aeaa6c15c025c6bb4b3c2b6d;p=ocean diff --git a/csrc/oceani-tests.mdc b/csrc/oceani-tests.mdc index 958575c..b613ffe 100644 --- a/csrc/oceani-tests.mdc +++ b/csrc/oceani-tests.mdc @@ -97,7 +97,7 @@ arguments separated from the name by commas. For each test, there is a section ## valgrind test code @[ -n "$$SKIP_COVERAGE_CHECK" ] || awk '/NOTEST/ { next } /^ *[1-9]/ {ran+=1} /^ *###/ {skip+=1} \ END {printf "coverage: %6.2f%%\n", ran * 100 / (ran + skip); \ - if (ran < (ran + skip) *0.972) exit(1) }' \ + if (ran < (ran + skip) *0.98) exit(1) }' \ coverage/oceani.mdc.gcov coverage_oceani: oceani.c @@ -113,7 +113,7 @@ calculations on them. ###### test: valvar - func main(argv:[argc::]string) + func main(argv:[]string) a := 23; b:=12 ; b1 := -b print a, b, a+b, a-b, a*b, a/b, a%b print ab, a>=b, a pi else "lower" if pi > 3 then print "pi exceeds three"; else print "need more pie" if (pi < 3) { print "not enough pi" } else { print "pi sufficient" } @@ -303,6 +310,7 @@ Now we need to test if/else and some different loops I won't calculate 20 / 9 Close enough higher + higher pi exceeds three pi sufficient sum 1..10 is 55 @@ -319,10 +327,11 @@ Here I break it into two parts, keeping the array code separate. ###### test: sayhello - func main(av:[ac::number]string) + func main(av:[]string) A := $av[1]; B := $av[2] astr := av[3] - bbool := av[ac-1] == "True" + l := av[] + bbool := av[l-1] == "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. @@ -596,7 +605,7 @@ Time to test if structure declarations and accesses work correctly. const three ::= 3 struct foo size:[three]number - name:string + name:string = "Hello" thing:baz active:Boolean = True @@ -749,12 +758,12 @@ A simple linked list example freelist(lp) @free = list.next - func main(argv:[ac::]string) + func main(argv:[]string) list : linkage insert(list, "@start"); insert(list, "~end") - for i:=1; then i=i+1; while i < ac: + for i:=1; then i=i+1; while i < argv[]: insert(list, argv[i]) insert(list, "Hello!") printlist(list) @@ -895,6 +904,7 @@ various places that `type_err()` are called. a:number = 4 a ::number = 5 c: + d:number = 02 ###### output: type_err2 .tmp.code:4:8: error: variable 'a' redeclared @@ -906,6 +916,7 @@ various places that `type_err()` are called. .tmp.code:7:8: error: variable 'a' redeclared .tmp.code:3:8: info: this is where 'a' was first declared .tmp.code:8:8: Variable declared with no type or value: c + .tmp.code:9:19: error: unsupported number format: 02 ###### test: type_err3 @@ -948,6 +959,15 @@ various places that `type_err()` are called. while 1 if True else False: print case 2: print "two" + print "one" ++ a4[], c[] + + x:Boolean = $"42" + + five ::= 5 + four ::= 4 + x1:[five]number + x2:[four]number + x1 = x2 ###### output: type_err3 .tmp.code:8:12: error: expected number but variable 'c' is string @@ -983,6 +1003,14 @@ various places that `type_err()` are called. .tmp.code:34:14: error: cannot find requested field in foo .tmp.code:35:17: error: have string but need number .tmp.code:38:29: error: expected number found Boolean + .tmp.code:41:23: error: have number but need string + .tmp.code:41:29: error: string cannot provide length + .tmp.code:43:21: error: Can only convert string to number, not Boolean + .tmp.code:43:8: info: variable 'x' was set as Boolean here. + .tmp.code:49:13: error: expected [five]number but variable 'x2' is [four]number + .tmp.code:48:8: info: this is where 'x2' was set to [four]number + .tmp.code:49:8: error: cannot assign value of type [five]number + .tmp.code:47:8: info: variable 'x1' was set as [five]number here. oceani: type error in program - not running. ###### test: type_err4