Răsfoiți Sursa

Added extensive parsing test ,tweaked some other test files

Taddeus Kroes 12 ani în urmă
părinte
comite
35476b2030

+ 95 - 0
test/basic/check_success/parse.cvc

@@ -0,0 +1,95 @@
+// extern function
+extern void printInt(int val);
+
+// extern variable
+extern int ext;
+
+// static functions with all possible return types
+bool  bfoo() { return true; }
+int   ifoo() { return 1; }
+float ffoo() { return 1.0; }
+void  vfoo() {}
+
+// function with parameters
+int bar(int a, float b) {
+    return a + (int)b;  // typecast
+}
+void baz(bool a) {}
+
+// exported function
+export int main() {
+    // regular vardec
+    bool uninitialized;
+    int i;
+    int a;
+    int b;
+    int c;
+
+    // initialized vardec
+    float initialized = 2.5;
+
+    uninitialized = false;  // assignment
+    vfoo();                 // funcall
+
+    // if-statement
+    if (bfoo()) {
+        i = 1;
+    }
+
+    if (bfoo())
+        i = 1;
+
+    // if-else statement
+    if (bfoo()) {
+        i = 2;
+    } else {
+        i = 3;
+    }
+
+    if (bfoo())
+        i = 2;
+    else
+        i = 3;
+
+    if (bfoo())
+        i = 2;
+    else if (bfoo())
+        i = 3;
+    else
+        i = 4;
+
+    // while-loop
+    while (bfoo()) {
+        vfoo();
+    }
+
+    while (bfoo())
+        vfoo();
+
+    // do-while-loop
+    do {
+        vfoo();
+    } while (bfoo());
+
+    do vfoo(); while (bfoo());
+
+    // for-loop
+    for (int i = 0, 10) {
+        vfoo();
+    }
+
+    for (int i = 0, 10, 2) {
+        vfoo();
+    }
+
+    for (int i = a, b, c) baz((bool)i);
+
+    // expressions (check precedences by hand!)
+    i = a + (b * c % i) / c - -10;
+    if (i < 0 || i > 100)
+        if (i >= 0 && i <= 100 || i != 0 && i != 100)
+            i = -i;
+
+    // return statement
+    return 0;
+}

+ 2 - 0
test/basic/check_success/preprocess.cvc

@@ -1,5 +1,7 @@
 #include "civic.h"
 
 export int main() {
+    printInt(scanInt());
+    printNewlines(1);
     return 0;
 }

+ 1 - 1
test/basic/check_success/vardec_init.cvc

@@ -1,4 +1,4 @@
-void testFunDecs()
+void testVarInits()
 {
   int a = 3;
   int c = 5;

+ 3 - 3
test/run.bash

@@ -14,7 +14,7 @@ function echo_success {
 }
 
 function echo_failed {
-    echo -e '\E[27;31m'"\033[1merror\033[0m"
+    echo -e '\E[27;31m'"\033[1mfailed\033[0m"
 }
 
 # The real tests: compile a file, run it, and compare the output to the
@@ -118,7 +118,7 @@ function check_return {
     if $CIVCC $CFLAGS $file -o tmp.s > /dev/null 2>&1
     then
         if [ $expect_failure -eq 1 ]; then
-            echo failed
+            echo_failed
             failed_tests=$((failed_tests+1))
         else
             echo_success
@@ -127,7 +127,7 @@ function check_return {
         if [ $expect_failure -eq 1 ]; then
             echo_success
         else
-            echo failed
+            echo_failed
             failed_tests=$((failed_tests+1))
         fi
     fi