Skip to content

Commit

Permalink
Add tests for unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
tjysdsg committed May 13, 2020
1 parent 86fd8a3 commit e83b10a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .idea/runConfigurations/tanc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion include/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ struct line_info {
line_info(const size_t lineno, const std::string &code) : lineno(lineno), code(code) {}
};

// TODO: support unicode
class Reader final {
public:
Reader() = default;
Expand Down
2 changes: 1 addition & 1 deletion src/lexer/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Token *tokenize_char(Reader *reader, cursor &start) {
}
value = std::string(1, escape_char(value[1]));
} else if (value.length() != 1) {
report_code_error(reader->get_line(forward.l).code, forward.l, forward.c, "Incomplete character literal");
report_code_error(reader->get_line(forward.l).code, forward.l, forward.c, "Invalid character literal");
}
t = new Token(TokenType::CHAR, value, start, &reader->get_line(start.l));
start = (*reader).forward(forward);
Expand Down
16 changes: 15 additions & 1 deletion src/test/test_src/string.tan
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@ import "runtime/print.tan";
import "runtime/debug.tan";

pub fn main(argc: int, argv: char**) : int {
var s: str = "shit";
var s: str = "shit 他妈的";
assert(s[0] == 's');
assert(s[1] == 'h');
assert(s[2] == 'i');
assert(s[3] == 't');
assert(s[4] == ' ');
var ta = "他";
assert(s[5] == ta[0]);
assert(s[6] == ta[1]);
assert(s[7] == ta[2]);
var ma = "妈";
assert(s[8] == ma[0]);
assert(s[9] == ma[1]);
assert(s[10] == ma[2]);
var de = "的";
assert(s[11] == de[0]);
assert(s[12] == de[1]);
assert(s[13] == de[2]);
print("SUCCESS\n");
print(s);
return 0;
}

0 comments on commit e83b10a

Please sign in to comment.