Skip to content

Commit a9bf5be

Browse files
committed
TestSuite: amend "widgets_inputtext_cursor" to test ctrl+arrow on multibyte characters.
for ocornut/imgui#7925
1 parent 22fc9b8 commit a9bf5be

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

imgui_test_suite/imgui_tests_widgets_inputtext.cpp

+41
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ void RegisterTests_WidgetsInputText(ImGuiTestEngine* e)
487487
#endif
488488

489489
// ## Test input text multiline cursor movement: left, up, right, down, origin, end, ctrl+origin, ctrl+end, page up, page down
490+
// ## Test on multi-byte characters (see Set 2)
490491
// TODO ## Test input text multiline cursor with selection: left, up, right, down, origin, end, ctrl+origin, ctrl+end, page up, page down
491492
// TODO ## Test input text multiline scroll movement only: ctrl + (left, up, right, down)
492493
// TODO ## Test input text multiline page up/page down history ?
@@ -809,6 +810,46 @@ void RegisterTests_WidgetsInputText(ImGuiTestEngine* e)
809810
// FIXME-TODO: More tests needed.
810811
}
811812

813+
// [SET 2: multibytes codepoints]
814+
ctx->KeyCharsReplace("\xE3\x83\x8F\xE3\x83\xAD\xE3\x83\xBC" "\xE3\x80\x80" "\xE4\xB8\x96\xE7\x95\x8C" "\xE3\x80\x82"); // "HARO- SEKAI. " (with double-width space)
815+
KeyPressAndDebugPrint(ImGuiKey_Home);
816+
IM_CHECK_EQ(state->GetCursorPos(), 0); // "|HARO- "
817+
if (!is_osx)
818+
{
819+
// Windows
820+
KeyPressAndDebugPrint(chord_word_next);
821+
IM_CHECK_EQ(state->GetCursorPos(), 4); // "HARO- |"
822+
KeyPressAndDebugPrint(chord_word_prev);
823+
IM_CHECK_EQ(state->GetCursorPos(), 0); // "|HARO- "
824+
for (int n = 0; n < 3; n++)
825+
KeyPressAndDebugPrint(ImGuiKey_RightArrow);
826+
IM_CHECK_EQ(state->GetCursorPos(), 3); // "HARO-| "
827+
KeyPressAndDebugPrint(chord_word_next);
828+
IM_CHECK_EQ(state->GetCursorPos(), 3+1); // "HARO- |"
829+
830+
KeyPressAndDebugPrint(chord_word_next);
831+
IM_CHECK_EQ(state->GetCursorPos(), 3+1 + 2); // "HARO- SEKAI|." // VS(Win) does this, GitHub-Web(Win) doesn't.
832+
KeyPressAndDebugPrint(chord_word_next);
833+
IM_CHECK_EQ(state->GetCursorPos(), 3+1 + 2+1); // "HARO- SEKAI.|"
834+
835+
//... not duplicating all tests, we just want basic coverage that multi-byte UTF-8 codepoints are correctly taken into account.
836+
837+
ctx->KeyPress(ImGuiKey_End);
838+
IM_CHECK_EQ(state->GetCursorPos(), 3+1 + 2+1); // "HARO- SEKAI.|"
839+
840+
KeyPressAndDebugPrint(chord_word_prev);
841+
IM_CHECK_EQ(state->GetCursorPos(), 3+1 + 2); // "HARO- SEKAI|." // VS-Win: STOP, GitHubWeb-Win: SKIP
842+
KeyPressAndDebugPrint(chord_word_prev);
843+
IM_CHECK_EQ(state->GetCursorPos(), 3+1); // "HARO- |"
844+
845+
KeyPressAndDebugPrint(chord_word_prev);
846+
IM_CHECK_EQ(state->GetCursorPos(), 0); // "|HARO- SEKAI."
847+
848+
KeyPressAndDebugPrint(chord_word_prev);
849+
IM_CHECK_EQ(state->GetCursorPos(), 0); // (no-op)
850+
}
851+
852+
// [SET 3]
812853
// [SET 2]
813854
// Delete all, Extra Test with Multiple Spaces
814855
ctx->KeyCharsReplace("Hello world.....HELLO");

0 commit comments

Comments
 (0)