2019-05-21 13:11:00 +00:00
|
|
|
#ifdef TESTS_BUILD
|
|
|
|
#define CATCH_CONFIG_MAIN
|
|
|
|
#include <catch.hpp>
|
|
|
|
#include "../src/Script.hpp"
|
|
|
|
|
2019-06-17 16:35:12 +00:00
|
|
|
using namespace Porygon;
|
2019-05-21 13:11:00 +00:00
|
|
|
TEST_CASE( "Diagnostic invalid character", "[integration]" ) {
|
2019-05-28 15:49:03 +00:00
|
|
|
auto script = Script::Create("1 + 1 @");
|
|
|
|
REQUIRE(script->Diagnostics -> HasErrors());
|
|
|
|
auto diags = script->Diagnostics -> GetDiagnostics();
|
2019-05-21 13:11:00 +00:00
|
|
|
REQUIRE(diags.size() == 1);
|
2019-06-18 14:39:36 +00:00
|
|
|
CHECK(diags[0].GetCode() == Diagnostics::DiagnosticCode::UnexpectedCharacter);
|
2019-05-21 13:11:00 +00:00
|
|
|
CHECK(diags[0].GetStartPosition() == 6);
|
|
|
|
CHECK(diags[0].GetLength() == 1);
|
2019-05-29 12:58:00 +00:00
|
|
|
delete script;
|
2019-05-21 13:11:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE( "Diagnostic invalid token", "[integration]" ) {
|
2019-05-28 15:49:03 +00:00
|
|
|
auto script = Script::Create("1 +/ 1");
|
|
|
|
REQUIRE(script->Diagnostics -> HasErrors());
|
|
|
|
auto diags = script->Diagnostics -> GetDiagnostics();
|
2019-05-21 13:11:00 +00:00
|
|
|
REQUIRE(diags.size() == 1);
|
2019-06-18 14:39:36 +00:00
|
|
|
CHECK(diags[0].GetCode() == Diagnostics::DiagnosticCode::UnexpectedToken);
|
2019-05-21 13:11:00 +00:00
|
|
|
CHECK(diags[0].GetStartPosition() == 3);
|
|
|
|
CHECK(diags[0].GetLength() == 1);
|
2019-06-18 15:14:18 +00:00
|
|
|
CHECK(script->Diagnostics->GetLineFromPosition(diags[0].GetStartPosition()) == 0);
|
2019-05-29 12:58:00 +00:00
|
|
|
delete script;
|
2019-05-21 13:11:00 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 15:14:18 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-06-18 17:56:47 +00:00
|
|
|
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 -> GetFullErrorMessage(diags[0]);
|
|
|
|
REQUIRE(msg == "[Error] (1, 2) 'x' is not a valid control character.");
|
|
|
|
delete script;
|
|
|
|
}
|
2019-06-18 15:14:18 +00:00
|
|
|
|
2019-05-21 13:11:00 +00:00
|
|
|
|
|
|
|
#endif
|