-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bugs in CharToColumnMapper (#16787)
Aside from overall simplifying `CharToColumnMapper` this fixes 2 bugs: * The backward search loop may have iterated 1 column too far, because it didn't stop at `*current <= *target`, but rather at `*(current - 1) <= *target`. This issue was only apparent when surrogate pairs were being used in a row. * When the target offset is that of a trailing surrogate pair the forward search loop may have iterated 1 column too far. It's somewhat unlikely for this to happen since this code is only used through ICU, but you never know. This is a continuation of PR #16775.
- Loading branch information
Showing
6 changed files
with
101 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#include "precomp.h" | ||
|
||
#include "WexTestClass.h" | ||
#include "../textBuffer.hpp" | ||
#include "../../renderer/inc/DummyRenderer.hpp" | ||
|
||
template<> | ||
class WEX::TestExecution::VerifyOutputTraits<std::vector<til::point_span>> | ||
{ | ||
public: | ||
static WEX::Common::NoThrowString ToString(const std::vector<til::point_span>& vec) | ||
{ | ||
WEX::Common::NoThrowString str; | ||
str.Append(L"{ "); | ||
for (size_t i = 0; i < vec.size(); ++i) | ||
{ | ||
const auto& s = vec[i]; | ||
if (i != 0) | ||
{ | ||
str.Append(L", "); | ||
} | ||
str.AppendFormat(L"{(%d, %d), (%d, %d)}", s.start.x, s.start.y, s.end.x, s.end.y); | ||
} | ||
str.Append(L" }"); | ||
return str; | ||
} | ||
}; | ||
|
||
class UTextAdapterTests | ||
{ | ||
TEST_CLASS(UTextAdapterTests); | ||
|
||
TEST_METHOD(Unicode) | ||
{ | ||
DummyRenderer renderer; | ||
TextBuffer buffer{ til::size{ 24, 1 }, TextAttribute{}, 0, false, renderer }; | ||
|
||
RowWriteState state{ | ||
.text = L"abc 𝒶𝒷𝒸 abc ネコちゃん", | ||
}; | ||
buffer.Write(0, TextAttribute{}, state); | ||
VERIFY_IS_TRUE(state.text.empty()); | ||
|
||
static constexpr auto s = [](til::CoordType beg, til::CoordType end) -> til::point_span { | ||
return { { beg, 0 }, { end, 0 } }; | ||
}; | ||
|
||
auto expected = std::vector{ s(0, 2), s(8, 10) }; | ||
auto actual = buffer.SearchText(L"abc", false); | ||
VERIFY_ARE_EQUAL(expected, actual); | ||
|
||
expected = std::vector{ s(5, 5) }; | ||
actual = buffer.SearchText(L"𝒷", false); | ||
VERIFY_ARE_EQUAL(expected, actual); | ||
|
||
expected = std::vector{ s(12, 15) }; | ||
actual = buffer.SearchText(L"ネコ", false); | ||
VERIFY_ARE_EQUAL(expected, actual); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters