Initial work on type registration in the binder.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -6,7 +6,7 @@ using namespace MalachScript::Parser;
|
||||
#define KEYWORD_TEST(script, symbol) \
|
||||
TEST_CASE("Lex " script) { \
|
||||
MalachScript::Diagnostics::Logger diag; \
|
||||
auto lexer = Lexer(u8##script, u8##script, &diag); \
|
||||
auto lexer = Lexer(script, script, &diag); \
|
||||
const auto* token = lexer.Lex(); \
|
||||
CHECK(diag.GetMessages().empty()); \
|
||||
CHECK(token->GetKind() == LexTokenKind::symbol); \
|
||||
@@ -79,10 +79,8 @@ KEYWORD_TEST("while", WhileKeyword);
|
||||
KEYWORD_TEST("xor", XorKeyword);
|
||||
|
||||
namespace doctest {
|
||||
template <> struct StringMaker<std::u8string> {
|
||||
static String convert(const std::u8string& value) {
|
||||
return String(reinterpret_cast<const char*>(value.data()));
|
||||
}
|
||||
template <> struct StringMaker<std::string> {
|
||||
static String convert(const std::string& value) { return String(reinterpret_cast<const char*>(value.data())); }
|
||||
};
|
||||
template <> struct StringMaker<LexTokenKind> {
|
||||
static String convert(LexTokenKind value) { return String(std::to_string((uint32_t)value).c_str()); }
|
||||
@@ -93,12 +91,12 @@ namespace doctest {
|
||||
#define IDENTIFIER_TEST(identifier) \
|
||||
TEST_CASE("Lex identifier " identifier) { \
|
||||
MalachScript::Diagnostics::Logger diag; \
|
||||
auto lexer = Lexer(u8##identifier, u8##identifier, &diag); \
|
||||
auto lexer = Lexer(identifier, identifier, &diag); \
|
||||
const auto* token = lexer.Lex(); \
|
||||
CHECK(diag.GetMessages().empty()); \
|
||||
REQUIRE(token->GetKind() == LexTokenKind::Identifier); \
|
||||
auto value = ((IdentifierToken*)token)->GetValue().GetString(); \
|
||||
CHECK(value == std::u8string(reinterpret_cast<const char8_t*>(identifier))); \
|
||||
CHECK(value == std::string(reinterpret_cast<const char*>(identifier))); \
|
||||
CHECK(token->GetNext()->GetKind() == LexTokenKind::EndOfFile); \
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ using namespace MalachScript::Parser;
|
||||
#define LEX_TEST(script, ...) \
|
||||
TEST_CASE("Lex: " script) { \
|
||||
MalachScript::Diagnostics::Logger diag; \
|
||||
auto lexer = Lexer(u8##script, u8##script, &diag); \
|
||||
auto lexer = Lexer(script, script, &diag); \
|
||||
const auto* token = lexer.Lex(); \
|
||||
CHECK(diag.GetMessages().empty()); \
|
||||
std::vector<LexTokenKind> vec = {__VA_ARGS__, LexTokenKind::EndOfFile}; \
|
||||
|
||||
@@ -6,7 +6,7 @@ using namespace MalachScript::Parser;
|
||||
#define INTEGER_TEST(script, expected) \
|
||||
TEST_CASE("Lex " script) { \
|
||||
MalachScript::Diagnostics::Logger diag; \
|
||||
auto lexer = Lexer(u8##script, u8##script, &diag); \
|
||||
auto lexer = Lexer(script, script, &diag); \
|
||||
const auto* token = lexer.Lex(); \
|
||||
CHECK(diag.GetMessages().empty()); \
|
||||
REQUIRE(token->GetKind() == LexTokenKind::IntegerLiteral); \
|
||||
@@ -18,7 +18,7 @@ using namespace MalachScript::Parser;
|
||||
#define FLOAT_TEST(script, expected) \
|
||||
TEST_CASE("Lex " script) { \
|
||||
MalachScript::Diagnostics::Logger diag; \
|
||||
auto lexer = Lexer(u8##script, u8##script, &diag); \
|
||||
auto lexer = Lexer(script, script, &diag); \
|
||||
const auto* token = lexer.Lex(); \
|
||||
CHECK(diag.GetMessages().empty()); \
|
||||
REQUIRE(token->GetKind() == LexTokenKind::FloatLiteral); \
|
||||
|
||||
@@ -6,12 +6,12 @@ using namespace MalachScript::Parser;
|
||||
#define STRING_TEST(str, constraint) \
|
||||
TEST_CASE("Lex string " constraint str constraint) { \
|
||||
MalachScript::Diagnostics::Logger diag; \
|
||||
auto lexer = Lexer(u8##str, u8##constraint str constraint, &diag); \
|
||||
auto lexer = Lexer(str, constraint str constraint, &diag); \
|
||||
const auto* token = lexer.Lex(); \
|
||||
CHECK(diag.GetMessages().empty()); \
|
||||
REQUIRE(token->GetKind() == LexTokenKind::StringLiteral); \
|
||||
auto value = ((const StringLiteral*)token)->GetValue(); \
|
||||
CHECK(value == std::u8string(reinterpret_cast<const char8_t*>(str))); \
|
||||
CHECK(value == std::string(reinterpret_cast<const char*>(str))); \
|
||||
CHECK(token->GetNext()->GetKind() == LexTokenKind::EndOfFile); \
|
||||
}
|
||||
|
||||
@@ -23,14 +23,14 @@ STRING_TEST("\"\"foo bar\"\"", "\"\"\"");
|
||||
|
||||
TEST_CASE("Lex multiline string") {
|
||||
MalachScript::Diagnostics::Logger diag;
|
||||
auto lexer = Lexer(u8"multiline", u8R"("""foo
|
||||
auto lexer = Lexer("multiline", R"("""foo
|
||||
bar""")",
|
||||
&diag);
|
||||
const auto* token = lexer.Lex();
|
||||
CHECK(diag.GetMessages().empty());
|
||||
REQUIRE(token->GetKind() == LexTokenKind::StringLiteral);
|
||||
auto value = (dynamic_cast<const StringLiteral*>(token))->GetValue();
|
||||
CHECK(value == std::u8string(reinterpret_cast<const char8_t*>(R"(foo
|
||||
CHECK(value == std::string(reinterpret_cast<const char*>(R"(foo
|
||||
bar)")));
|
||||
CHECK(token->GetNext()->GetKind() == LexTokenKind::EndOfFile);
|
||||
}
|
||||
@@ -7,7 +7,7 @@ using namespace MalachScript::Parser;
|
||||
#define SYMBOL_TEST(script, symbol) \
|
||||
TEST_CASE("Lex " script) { \
|
||||
MalachScript::Diagnostics::Logger diag; \
|
||||
auto lexer = Lexer(u8##script, u8##script, &diag); \
|
||||
auto lexer = Lexer(script, script, &diag); \
|
||||
const auto* token = lexer.Lex(); \
|
||||
CHECK(diag.GetMessages().empty()); \
|
||||
CHECK(token->GetKind() == LexTokenKind::symbol); \
|
||||
@@ -71,10 +71,10 @@ SYMBOL_TEST(" ", Whitespace)
|
||||
#undef SYMBOL_TEST
|
||||
|
||||
TEST_CASE("Lex whitespace") {
|
||||
auto whitespace = {u8" ", u8"\t", u8"\n", u8"\r", u8"\xef\xbb\xbf"};
|
||||
auto whitespace = {" ", "\t", "\n", "\r", "\xef\xbb\xbf"};
|
||||
for (const auto* v : whitespace) {
|
||||
MalachScript::Diagnostics::Logger diag;
|
||||
auto lexer = Lexer(u8"whitespace", v, &diag);
|
||||
auto lexer = Lexer("whitespace", v, &diag);
|
||||
const auto* token = lexer.Lex();
|
||||
CHECK(diag.GetMessages().empty());
|
||||
CHECK(token->GetKind() == LexTokenKind::Whitespace);
|
||||
|
||||
Reference in New Issue
Block a user