Added tests for formatter

This commit is contained in:
Devine Lu Linvega 2024-04-26 11:06:30 -07:00
parent 3167698795
commit a7abb9475a
2 changed files with 17 additions and 15 deletions

View File

@ -6,12 +6,14 @@
<> (ghost) () <> (ghost) ()
?(?-) (Whitespace) ?(?-) (Formatter)
(a b c ) = (a b c) (whitespace 1) test ?((?x ?y) one) aaa(bbb) = one (formatter 1) test
( a b c) = (a b c) (whitespace 2) test ?((?x ?y) one) (bbb)aaa = one (formatter 2) test
( a b c ) = (a b c) (whitespace 3) test (a b c ) = (a b c) (formatter 3) test
(a b c ( a b c ) ) = (a b c (a b c)) (whitespace 4) test ( a b c) = (a b c) (formatter 4) test
( a b c ) = (a b c) (formatter 5) test
(a b c ( a b c ) ) = (a b c (a b c)) (formatter 6) test
?(?-) (Empty replacements) ?(?-) (Empty replacements)

View File

@ -124,9 +124,9 @@ apply_rule(Rule *r, char *s)
if(*reg++ != *pp++) return 0; if(*reg++ != *pp++) return 0;
} else /* reg set */ } else /* reg set */
regs[id] = s; regs[id] = s;
c = *a, s = pcap; s = pcap;
} } else if(c != *s++)
else if(c != *s++) return 0; return 0;
} }
c = *s; c = *s;
if(!spacer(c)) return 0; if(!spacer(c)) return 0;
@ -232,7 +232,7 @@ main(int argc, char **argv)
{ {
FILE *f; FILE *f;
int i, pl = 0, pr = 0; int i, pl = 0, pr = 0;
char c, *w = bank_a; char c, last = 0, *w = bank_a;
if(argc < 2) if(argc < 2)
return !printf("usage: modal [-vqn] source.modal\n"); return !printf("usage: modal [-vqn] source.modal\n");
for(i = 1; i < argc && *argv[i] == '-'; i++) { for(i = 1; i < argc && *argv[i] == '-'; i++) {
@ -246,14 +246,14 @@ main(int argc, char **argv)
return !fprintf(stdout, "Modal file invalid: %s.\n", argv[i]); return !fprintf(stdout, "Modal file invalid: %s.\n", argv[i]);
while(fread(&c, 1, 1, f)) { while(fread(&c, 1, 1, f)) {
c = c <= 0x20 ? 0x20 : c; c = c <= 0x20 ? 0x20 : c;
if(w > bank_a) { if(c == ' ' && last == '(') continue;
if(c == ' ' && *(w - 1) == '(') continue; if(c == ')' && last == ' ') w--;
if(c == ')' && *(w - 1) == ' ') w--; if(c == ' ' && last == ' ') w--;
if(c == ' ' && *(w - 1) == ' ') w--;
}
if(c == '(') pl++; if(c == '(') pl++;
if(c == ')') pr++; if(c == ')') pr++;
*w++ = c; if(c == '(' && last != '?' && !spacer(last)) *w++ = ' ';
if(last == ')' && !spacer(c)) *w++ = ' ';
*w++ = last = c;
} }
while(*(--w) <= ' ') *w = 0; while(*(--w) <= ' ') *w = 0;
fclose(f); fclose(f);