Skip to content

Commit

Permalink
More tests (#456)
Browse files Browse the repository at this point in the history
Co-authored-by: Akuli <[email protected]>
  • Loading branch information
littlewhitecloud and Akuli authored Dec 17, 2023
1 parent 06c74f5 commit d7972ca
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 4 deletions.
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
1 change: 0 additions & 1 deletion 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
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

0 comments on commit d7972ca

Please sign in to comment.