Fixed infinite loop in diagnostics
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2019-07-21 12:03:56 +02:00
parent bb6c7edcf2
commit 40e45b0112
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 17 additions and 1 deletions

View File

@ -57,7 +57,11 @@ size_t DiagnosticsHolder::GetLineFromPosition(size_t i) {
if (pos > i){
topLimit = half;
} else if (pos < i){
bottomLimit = half;
if (bottomLimit == half){
bottomLimit = half + 1;
} else{
bottomLimit = half;
}
} else{
return half;
}

View File

@ -41,6 +41,18 @@ TEST_CASE( "Get diagnostic line", "[integration]" ) {
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"