diff --git a/src/Diagnostics/DiagnosticsHolder.cpp b/src/Diagnostics/DiagnosticsHolder.cpp index 9fa7e5f..2ada5cd 100644 --- a/src/Diagnostics/DiagnosticsHolder.cpp +++ b/src/Diagnostics/DiagnosticsHolder.cpp @@ -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; } diff --git a/tests/integration/DiagnosticsTests.cpp b/tests/integration/DiagnosticsTests.cpp index 17f3818..52f2235 100644 --- a/tests/integration/DiagnosticsTests.cpp +++ b/tests/integration/DiagnosticsTests.cpp @@ -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"