Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more tests to fix todos #437

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/tokenize.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static char read_byte(struct State *st) {

// Use the zero byte to represent end of file.
if (c == '\0')
fail_with_error(st->location, "source file contains a zero byte"); // TODO: test this
fail_with_error(st->location, "source file contains a zero byte");
if (c == EOF) {
assert(!ferror(st->f));
return '\0';
Expand Down Expand Up @@ -220,9 +220,10 @@ static bool is_keyword(const char *s)
// - self-hosted compiler
// - syntax documentation
"import", "def", "declare", "class", "union", "enum", "global",
"return", "if", "elif", "else", "while", "for", "pass", "break", "continue",
"True", "False", "None", "NULL", "void", "noreturn",
"and", "or", "not", "self", "as", "sizeof", "assert",
"return", "if", "elif", "else", "while", "for", "break", "continue",
"True", "False", "NULL", "self",
"and", "or", "not", "as", "sizeof", "assert", "pass",
"void", "noreturn",
"bool", "byte", "short", "int", "long", "float", "double",
};
for (const char **kw = &keywords[0]; kw < &keywords[sizeof(keywords)/sizeof(keywords[0])]; kw++)
Expand Down Expand Up @@ -295,7 +296,6 @@ static char *read_string(struct State *st, char quote, int *len)
case '\n':
// \ at end of line, string continues on next line
if (quote == '\'') {
// TODO: tests
st->location.lineno--; // to get error at the correct line number
goto missing_end_quote;
}
Expand All @@ -321,7 +321,6 @@ static char *read_string(struct State *st, char quote, int *len)
return result.ptr;

missing_end_quote:
// TODO: tests
if (quote == '"')
fail_with_error(st->location, "missing \" to end the string");
else
Expand Down
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/syntax_error/missing_end_quote_in_byte.jou
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import "stdlib/io.jou"

# Output: compiler error in file "tests/syntax_error/missing_end_quote_in_byte.jou", line 5: missing ' to end the byte literal
def main() -> int:
printf('?)
return 0
6 changes: 6 additions & 0 deletions tests/syntax_error/missing_end_quote_in_string.jou
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import "stdlib/io.jou"

# Output: compiler error in file "tests/syntax_error/missing_end_quote_in_string.jou", line 5: missing " to end the string
def main() -> int:
printf("Hello)
return 0
8 changes: 8 additions & 0 deletions tests/syntax_error/string_continue_on_next_line.jou
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import "stdlib/io.jou"

# Output: compiler error in file "tests/syntax_error/string_continue_on_next_line.jou", line 5: missing ' to end the byte literal
def main() -> int:
a = '\
't\''
printf(a)
return 0
Loading