68 lines
2.4 KiB
C++
68 lines
2.4 KiB
C++
#ifdef TESTS_BUILD
|
|
#define CATCH_CONFIG_MAIN
|
|
#include <catch.hpp>
|
|
#include "../src/Script.hpp"
|
|
|
|
using namespace Porygon;
|
|
TEST_CASE( "Diagnostic invalid character", "[integration]" ) {
|
|
auto script = Script::Create("1 + 1 @");
|
|
REQUIRE(script->Diagnostics -> HasErrors());
|
|
auto diags = script->Diagnostics -> GetDiagnostics();
|
|
REQUIRE(diags.size() == 1);
|
|
CHECK(diags[0].GetCode() == Diagnostics::DiagnosticCode::UnexpectedCharacter);
|
|
CHECK(diags[0].GetStartPosition() == 6);
|
|
CHECK(diags[0].GetLength() == 1);
|
|
delete script;
|
|
}
|
|
|
|
TEST_CASE( "Diagnostic invalid token", "[integration]" ) {
|
|
auto script = Script::Create("1 +/ 1");
|
|
REQUIRE(script->Diagnostics -> HasErrors());
|
|
auto diags = script->Diagnostics -> GetDiagnostics();
|
|
REQUIRE(diags.size() == 1);
|
|
CHECK(diags[0].GetCode() == Diagnostics::DiagnosticCode::UnexpectedToken);
|
|
CHECK(diags[0].GetStartPosition() == 3);
|
|
CHECK(diags[0].GetLength() == 1);
|
|
CHECK(script->Diagnostics->GetLineFromPosition(diags[0].GetStartPosition()) == 0);
|
|
delete script;
|
|
}
|
|
|
|
TEST_CASE( "Get diagnostic line", "[integration]" ) {
|
|
auto script = Script::Create(uR"(
|
|
1 +/ 1
|
|
)");
|
|
REQUIRE(script->Diagnostics -> HasErrors());
|
|
auto diags = script->Diagnostics -> GetDiagnostics();
|
|
REQUIRE(diags.size() == 1);
|
|
CHECK(diags[0].GetCode() == Diagnostics::DiagnosticCode::UnexpectedToken);
|
|
CHECK(diags[0].GetStartPosition() == 4);
|
|
CHECK(diags[0].GetLength() == 1);
|
|
CHECK(script->Diagnostics->GetLineFromPosition(diags[0].GetStartPosition()) == 1);
|
|
delete script;
|
|
}
|
|
|
|
TEST_CASE( "Get diagnostic line 2", "[integration]" ) {
|
|
auto script = Script::Create(u"\n'\\x'");
|
|
REQUIRE(script->Diagnostics -> HasErrors());
|
|
auto diags = script->Diagnostics -> GetDiagnostics();
|
|
REQUIRE(diags.size() == 1);
|
|
CHECK(diags[0].GetCode() == Diagnostics::DiagnosticCode::InvalidStringControlCharacter);
|
|
CHECK(diags[0].GetStartPosition() == 2);
|
|
CHECK(diags[0].GetLength() == 2);
|
|
CHECK(script->Diagnostics->GetLineFromPosition(diags[0].GetStartPosition()) == 1);
|
|
delete script;
|
|
}
|
|
|
|
TEST_CASE( "Get full diagnostic message", "[integration]" ) {
|
|
auto script = Script::Create(uR"(
|
|
"\x"
|
|
)");
|
|
REQUIRE(script->Diagnostics -> HasErrors());
|
|
auto diags = script->Diagnostics -> GetDiagnostics();
|
|
auto msg = script->Diagnostics->GetFullDiagnostic(&diags[0]);
|
|
REQUIRE(*msg == "[Error] (2, 2) '\\x' is not a valid control character.");
|
|
delete script;
|
|
}
|
|
|
|
|
|
#endif |