diff options
author | Alfred Reinold Baudisch <alfred@alfredbaudisch.com> | 2022-10-28 15:27:52 +0200 |
---|---|---|
committer | Alfred Reinold Baudisch <alfred@alfredbaudisch.com> | 2022-10-28 15:35:43 +0200 |
commit | e46e70f8ee5e2a073ca8c9f87affdabbd6457352 (patch) | |
tree | 45d101890420fe78c47200fa137381434cb27b37 /tests/scene | |
parent | 028db9f2b5b6d2ca9a00d3b08c17f82b5298e149 (diff) |
Improved TextEdit::add_selection_for_next_occurrence test case
It covers additional selections of different words, as well manually adding a cursor in between and selecting the next occurrence. The previous test also was outdated in regards of not testing the implicit call to `select_word_under_caret` made by `add_selection_for_next_occurrence` in case there's no selection.
Diffstat (limited to 'tests/scene')
-rw-r--r-- | tests/scene/test_text_edit.h | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/tests/scene/test_text_edit.h b/tests/scene/test_text_edit.h index 4b92b9daff..9640caf189 100644 --- a/tests/scene/test_text_edit.h +++ b/tests/scene/test_text_edit.h @@ -734,13 +734,20 @@ TEST_CASE("[SceneTree][TextEdit] text entry") { } SUBCASE("[TextEdit] add selection for next occurrence") { - text_edit->set_text("\ntest other_test\nrandom test\nword test word"); + text_edit->set_text("\ntest other_test\nrandom test\nword test word nonrandom"); text_edit->set_caret_column(0); text_edit->set_caret_line(1); - text_edit->select_word_under_caret(); - CHECK(text_edit->has_selection(0)); + // First selection made by the implicit select_word_under_caret call + text_edit->add_selection_for_next_occurrence(); + CHECK(text_edit->get_caret_count() == 1); CHECK(text_edit->get_selected_text(0) == "test"); + CHECK(text_edit->get_selection_from_line(0) == 1); + CHECK(text_edit->get_selection_from_column(0) == 0); + CHECK(text_edit->get_selection_to_line(0) == 1); + CHECK(text_edit->get_selection_to_column(0) == 4); + CHECK(text_edit->get_caret_line(0) == 1); + CHECK(text_edit->get_caret_column(0) == 4); text_edit->add_selection_for_next_occurrence(); CHECK(text_edit->get_caret_count() == 2); @@ -771,6 +778,27 @@ TEST_CASE("[SceneTree][TextEdit] text entry") { CHECK(text_edit->get_selection_to_column(3) == 9); CHECK(text_edit->get_caret_line(3) == 3); CHECK(text_edit->get_caret_column(3) == 9); + + // A different word with a new manually added caret + text_edit->add_caret(2, 1); + text_edit->select(2, 0, 2, 4, 4); + CHECK(text_edit->get_selected_text(4) == "rand"); + + text_edit->add_selection_for_next_occurrence(); + CHECK(text_edit->get_caret_count() == 6); + CHECK(text_edit->get_selected_text(5) == "rand"); + CHECK(text_edit->get_selection_from_line(5) == 3); + CHECK(text_edit->get_selection_from_column(5) == 18); + CHECK(text_edit->get_selection_to_line(5) == 3); + CHECK(text_edit->get_selection_to_column(5) == 22); + CHECK(text_edit->get_caret_line(5) == 3); + CHECK(text_edit->get_caret_column(5) == 22); + + // Make sure the previous selections are still active + CHECK(text_edit->get_selected_text(0) == "test"); + CHECK(text_edit->get_selected_text(1) == "test"); + CHECK(text_edit->get_selected_text(2) == "test"); + CHECK(text_edit->get_selected_text(3) == "test"); } SUBCASE("[TextEdit] deselect on focus loss") { |