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

More tests #456

Merged
merged 18 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from 17 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
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ indent_size = 3

[tests/syntax_error/indentation_not4.jou]
indent_size = 2

[tests/should_succeed/newline_and_space_at_eof.jou]
trim_trailing_whitespace = false
indent_size = unset
1 change: 1 addition & 0 deletions self_hosted/tokenizer.jou
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ class Tokenizer:
if c == '\\':
after_backslash = self->read_byte()
if after_backslash == '\0' or after_backslash == '\n':
self->location.lineno--
fail(self->location, "missing ' to end the byte literal")
elif after_backslash == 'n':
c = '\n'
Expand Down
3 changes: 0 additions & 3 deletions src/tokenize.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ static int read_indentation_level_for_newline_token(struct State *st)
consume_rest_of_line(st);
else if (c == '\0') {
// Ignore newline+spaces at end of file. Do not validate 4 spaces.
// TODO: test case
return 0;
} else {
unread_byte(st, c);
Expand Down Expand Up @@ -295,7 +294,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 +319,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
3 changes: 0 additions & 3 deletions src/typecheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ static const char *short_type_description(const Type *t)
case TYPE_ARRAY:
return "an array type";
case TYPE_BOOL:
// TODO: Is it possible to get this in an error message?
return "the built-in bool type";
}
}
Expand Down Expand Up @@ -246,8 +245,6 @@ static Signature handle_signature(FileTypes *ft, const AstSignature *astsig, con
else
sig.returntype = type_from_ast(ft, &astsig->returntype);

// TODO: validate main() parameters
// TODO: test main() taking parameters
littlewhitecloud marked this conversation as resolved.
Show resolved Hide resolved
if (!self_type && !strcmp(sig.name, "main") && sig.returntype != intType) {
fail_with_error(astsig->returntype.location, "the main() function must return int");
}
Expand Down
2 changes: 2 additions & 0 deletions tests/already_exists_error/bool.jou
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def foo() -> None:
x = True.asdf() # Error: type bool does not have any methods because it is the built-in bool type, not a class
3 changes: 3 additions & 0 deletions tests/should_succeed/newline_and_space_at_eof.jou
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def main() -> int:
return 0

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 6: missing " to end the string
def main() -> int:
a = "\
asdf
printf(a)
return 0