mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Add negative index to Array.remove_at and Array.insert
This commit is contained in:
parent
4248411baf
commit
fe39ffeb7d
3 changed files with 33 additions and 2 deletions
|
|
@ -126,6 +126,12 @@ TEST_CASE("[Array] resize(), insert(), and erase()") {
|
|||
CHECK(int(arr[0]) == 2);
|
||||
arr.erase(2);
|
||||
CHECK(int(arr[0]) == 1);
|
||||
|
||||
// Negative index on insert.
|
||||
CHECK(arr.size() == 3);
|
||||
arr.insert(-1, 3);
|
||||
CHECK(int(arr[2]) == 3);
|
||||
CHECK(arr.size() == 4);
|
||||
}
|
||||
|
||||
TEST_CASE("[Array] front() and back()") {
|
||||
|
|
@ -154,6 +160,15 @@ TEST_CASE("[Array] remove_at()") {
|
|||
arr.remove_at(0);
|
||||
CHECK(arr.size() == 0);
|
||||
|
||||
// Negative index.
|
||||
arr.push_back(3);
|
||||
arr.push_back(4);
|
||||
arr.remove_at(-1);
|
||||
CHECK(arr.size() == 1);
|
||||
CHECK(int(arr[0]) == 3);
|
||||
arr.remove_at(-1);
|
||||
CHECK(arr.size() == 0);
|
||||
|
||||
// The array is now empty; try to use `remove_at()` again.
|
||||
// Normally, this prints an error message so we silence it.
|
||||
ERR_PRINT_OFF;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue