diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core/templates/test_paged_array.h | 51 | ||||
-rw-r--r-- | tests/scene/test_text_edit.h | 44 |
2 files changed, 95 insertions, 0 deletions
diff --git a/tests/core/templates/test_paged_array.h b/tests/core/templates/test_paged_array.h index 37be3080e8..10dc4473ca 100644 --- a/tests/core/templates/test_paged_array.h +++ b/tests/core/templates/test_paged_array.h @@ -148,6 +148,57 @@ TEST_CASE("[PagedArray] Shared pool fill, including merging") { array2.reset(); //reset so pagepool can be reset pool.reset(); } + +TEST_CASE("[PagedArray] Extensive merge_unordered() test") { + for (int page_size = 1; page_size <= 128; page_size *= 2) { + PagedArrayPool<uint32_t> pool(page_size); + PagedArray<uint32_t> array1; + PagedArray<uint32_t> array2; + array1.set_page_pool(&pool); + array2.set_page_pool(&pool); + + const int max_count = 123; + // Test merging arrays of lengths 0+123, 1+122, 2+121, ..., 123+0 + for (uint32_t j = 0; j < max_count; j++) { + CHECK(array1.size() == 0); + CHECK(array2.size() == 0); + + uint32_t sum = 12345; + for (uint32_t i = 0; i < j; i++) { + // Hashing the addend makes it extremely unlikely for any values + // other than the original inputs to produce a matching sum + uint32_t addend = hash_murmur3_one_32(i) + i; + array1.push_back(addend); + sum += addend; + } + for (uint32_t i = j; i < max_count; i++) { + // See above + uint32_t addend = hash_murmur3_one_32(i) + i; + array2.push_back(addend); + sum += addend; + } + + CHECK(array1.size() == j); + CHECK(array2.size() == max_count - j); + + array1.merge_unordered(array2); + CHECK_MESSAGE(array1.size() == max_count, "merge_unordered() added/dropped elements while merging"); + + // If any elements were altered during merging, the sum will not match up. + for (uint32_t i = 0; i < array1.size(); i++) { + sum -= array1[i]; + } + CHECK_MESSAGE(sum == 12345, "merge_unordered() altered elements while merging"); + + array1.clear(); + } + + array1.reset(); + array2.reset(); + pool.reset(); + } +} + } // namespace TestPagedArray #endif // TEST_PAGED_ARRAY_H diff --git a/tests/scene/test_text_edit.h b/tests/scene/test_text_edit.h index 64ad3bd5b0..f3f2b4cb34 100644 --- a/tests/scene/test_text_edit.h +++ b/tests/scene/test_text_edit.h @@ -1779,6 +1779,50 @@ TEST_CASE("[SceneTree][TextEdit] text entry") { SIGNAL_CHECK("lines_edited_from", lines_edited_args); } + SUBCASE("[TextEdit] ui_text_backspace_word same line") { + text_edit->set_text("test test test"); + text_edit->set_caret_column(4); + text_edit->add_caret(0, 9); + text_edit->add_caret(0, 15); + + // For the second caret. + Array args2; + args2.push_back(0); + lines_edited_args.push_front(args2); + + // For the third caret. + Array args3; + args2.push_back(0); + lines_edited_args.push_front(args2); + + CHECK(text_edit->get_caret_count() == 3); + MessageQueue::get_singleton()->flush(); + + SIGNAL_DISCARD("text_set"); + SIGNAL_DISCARD("text_changed"); + SIGNAL_DISCARD("lines_edited_from"); + SIGNAL_DISCARD("caret_changed"); + + SEND_GUI_ACTION("ui_text_backspace_word"); + CHECK(text_edit->get_viewport()->is_input_handled()); + CHECK(text_edit->get_text() == " "); + CHECK(text_edit->get_caret_line() == 0); + CHECK(text_edit->get_caret_column() == 0); + CHECK_FALSE(text_edit->has_selection(0)); + + CHECK(text_edit->get_caret_line(1) == 0); + CHECK(text_edit->get_caret_column(1) == 1); + CHECK_FALSE(text_edit->has_selection(1)); + + CHECK(text_edit->get_caret_line(2) == 0); + CHECK(text_edit->get_caret_column(2) == 2); + CHECK_FALSE(text_edit->has_selection(1)); + + SIGNAL_CHECK("caret_changed", empty_signal_args); + SIGNAL_CHECK("text_changed", empty_signal_args); + SIGNAL_CHECK("lines_edited_from", lines_edited_args); + } + SUBCASE("[TextEdit] ui_text_backspace") { text_edit->set_text("\nthis is some test text.\n\nthis is some test text."); text_edit->select(1, 0, 1, 4); |