]> ocean-lang.org Git - ocean/commitdiff
oceani-tests: Add testing for --bracket printing.
authorNeilBrown <neil@brown.name>
Sun, 19 Dec 2021 00:52:25 +0000 (11:52 +1100)
committerNeilBrown <neil@brown.name>
Sun, 19 Dec 2021 00:52:25 +0000 (11:52 +1100)
Make sure that printing with --bracket is still parseable, and
double-printing doesn't change from single.

Signed-off-by: NeilBrown <neil@brown.name>
csrc/oceani-tests.mdc
csrc/oceani.mdc

index fafb78821b76d5d1891cf1a630ad8896ef918a11..6759c542d6d7dd72093a99babcbcd02fafb26173 100644 (file)
@@ -66,6 +66,12 @@ arguments separated from the name by commas.  For each test, there is a section
                    ./oceani --noexec --print .tmp.code1a >> .tmp.code2a || exit 1;\
                    if ! cmp -s .tmp.code1 .tmp.code2a; then \
                       echo " Failed"; diff -u .tmp.code1 .tmp.code2a; exit 1; fi ; \
+                   echo -n "brackets.. "; \
+                   echo '``````' > .tmp.code2b ; echo '``````' > .tmp.code2c ;\
+                   ./oceani --noexec --print --brackets .tmp.code1 >> .tmp.code2b || exit 1; \
+                   ./oceani -npb .tmp.code2b >> .tmp.code2c || exit 1 ; \
+                   if ! cmp -s .tmp.code2b .tmp.code2c; then \
+                       echo " Failed"; diff -u .tmp.code2b .tmp.code2c; exit 1; fi; \
                    echo -n "exec-after-print.. "; \
                    ./oceani .tmp.code1 $${1+"$$@"} > .tmp.have ; \
                    if ! cmp -s .tmp.want .tmp.have; then \
index 543ca75a300a6ae740b19ccb15b9ff1d24a92a2a..910d0953572c639ed76f985e764c0402eec8a482 100644 (file)
@@ -3552,6 +3552,7 @@ further detailed when Expression Lists are introduced.
 
        static void function_print(struct type *type, struct value *val, FILE *f)
        {
+               fprintf(f, "\n");
                print_exec(val->function, 1, 0);
        }
 
@@ -3585,7 +3586,6 @@ further detailed when Expression Lists are introduced.
                        } else
                                type_print(type->function.return_type, f);
                }
-               fprintf(f, "\n");
        }
 
        static void function_free_type(struct type *t)
@@ -4313,9 +4313,10 @@ parentheses around an expression converts it into a Term,
                if (bracket) printf(")");
                break;
        case Bracket:
-               printf("(");
+               /* Avoid double brackets... */
+               if (!bracket) printf("(");
                print_exec(b->right, indent, bracket);
-               printf(")");
+               if (!bracket) printf(")");
                break;
 
 ###### propagate binode cases
@@ -5802,10 +5803,13 @@ is a bit more interesting at this level.
                                struct value *val = var_value(&context, v);
                                printf("func %.*s", v->name->name.len, v->name->name.txt);
                                v->type->print_type_decl(v->type, stdout);
-                               if (brackets)
-                                       print_exec(val->function, 0, brackets);
-                               else
+                               if (brackets) {
+                                       printf(" {\n");
+                                       print_exec(val->function, 1, brackets);
+                                       printf("}\n");
+                               } else {
                                        print_value(v->type, val, stdout);
+                               }
                                printf("/* frame size %d */\n", v->type->function.local_size);
                                target -= 1;
                        }