]> ocean-lang.org Git - ocean/blobdiff - csrc/oceani-tests.mdc
oceani tests: check for conflicts.
[ocean] / csrc / oceani-tests.mdc
index bd40b2de3685e36c2bb8988801bc58cec61e4967..bba5156a16b05f1c084afbc7404b975ffacc73ca 100644 (file)
@@ -38,6 +38,8 @@ arguments separated from the name by commas.  For each test, there is a section
 
        tests:: oceani_test_suite
        oceani_test_suite: oceani coverage_oceani
+               @./parsergen --report --LR1 --tag Parser oceani.mdc | grep " - no conflicts" > /dev/null || \
+                   { echo "Grammar container conflicts, please review" ; exit 1; }
                @rm -rf coverage; mkdir -p coverage
                @cp *.gcno coverage
                @for T in $(oceani_tests); do \
@@ -68,7 +70,7 @@ arguments separated from the name by commas.  For each test, there is a section
                @mv *.gcov coverage ; [ -f .gcov ] && mv .gcov coverage
                @ awk '/^ *[1-9]/ {ran+=1} /^ *###/ {skip+=1} \
                    END {printf "coverage: %6.2f%%\n", ran * 100 / (ran + skip); \
-                        if (ran < (ran + skip) *0.85) exit(1) }' \
+                        if (ran < (ran + skip) *0.90) exit(1) }' \
                        coverage/oceani.mdc.gcov
                @rm -f .tmp*
 
@@ -87,18 +89,25 @@ calculations on them.
 ###### test: valvar
 
        program:
-               a := 23; b:=12
+               a := 23; b:=12 ; b1 := -b
                print a, b, a+b, a-b, a*b, a/b, a%b
                print a<b, a<=b, a>b, a>=b, a<a, a==b, a==a
+               print +a, +b, +b1, -a, -b, -b1
+               x := True; y := False
+               print x and y, x or y, x and x, y or y, x and not x, x < y
 
                c ::= "This is a string"
                d ::= " field theory"
                print c, d, c++d
 
+               aconst :: string = "unchanging"
+
 ###### output: valvar
 
        23 12 35 11 276 1.91667 11
        False False True True False False True
+       23 12 12 -23 -12 12
+       False True True False False False
        This is a string  field theory This is a string field theory
 
 Next we change the value of variables
@@ -150,6 +159,16 @@ Now we need to test if/else and some different loops
                        count = count + 1
                print "error is ", target - guess * guess
 
+               for j:=0; then j = j+3 ; while j < 10:
+                       if j != 0 and then 20 / j > 3:
+                               print "20 /", j," =", 20 / j
+                       else:
+                               print "I won't calculate 20 /", j
+               pi ::= 3.1415926535897
+               if 355/113 == pi or else +(pi - 355/113) < 0.001:
+                       print "Close enough"
+               print "lower" if 355/113 < pi else "higher"
+
 ###### output: cond_loop
        Success
         1 2 4 8 16 32 64
@@ -158,6 +177,12 @@ Now we need to test if/else and some different loops
        2 1.41422
        3 1.41421
        error is  -4.51095e-12
+       I won't calculate 20 / 0
+       20 / 3  = 6.66667
+       20 / 6  = 3.33333
+       I won't calculate 20 / 9
+       Close enough
+       higher
 
 ## Say Hello
 
@@ -393,6 +418,30 @@ Here I break it into two parts, keeping the array code separate.
        list[ 53 ]= 9040
        list[ 54 ]= 9768
 
+## Arrays
+
+We already have some array tests, but this is where we put other
+ad-hoc things array related.
+
+###### test list
+       oceani_tests += arrays
+
+###### test: arrays
+
+       program:
+               bools:[5]Boolean
+               strings:[4]string
+
+               bools[3] = strings[1] == "Hello"
+               bools[1] = strings[2] <= "there"
+
+               for i:=0; then i=i+1; while i<5:
+                       print '', bools[i],
+               print
+
+###### output: arrays
+        False True False False False
+
 ## Test code with syntax errors
 
 Syntax errors aren't handled well yet - the result is almost always a
@@ -482,7 +531,7 @@ These programs were generated by looking for the
 various places that `type_err()` are called.
 
 ###### test list
-       oceani_failing_tests += type_err1 type_err2 type_err3
+       oceani_failing_tests += type_err1 type_err2 type_err3 type_err4
 
 ###### test: type_err1
 
@@ -578,6 +627,19 @@ various places that `type_err()` are called.
        .tmp.code:3:8: info: variable 'c' was set as string here.
        oceani: type error in program - not running.
 
+###### test: type_err4
+       program:
+               a:=1; b=2; c::=3
+               print a, b, c
+
+###### output: type_err4
+       .tmp.code:3:14: error: expected *unknown*type* (labels not permitted) but variable 'b' is label
+       .tmp.code:3:14: info: this is where 'b' was set to label
+       .tmp.code:3:16: error: expected label found number
+       .tmp.code:3:14: info: variable 'b' was set as label here.
+       .tmp.code:4:17: error: expected *unknown*type* (labels not permitted) but variable 'b' is label
+       .tmp.code:3:14: info: this is where 'b' was set to label
+       oceani: type error in program - not running.
 
 ## Test erroneous command line args