Skip to content

Commit c304971

Browse files
committed
Add list_remove() function
1 parent 06f551e commit c304971

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/scratch/list_functions.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ extern "C"
1212
{
1313
list->clear();
1414
}
15+
16+
void list_remove(List *list, size_t index)
17+
{
18+
list->removeAt(index);
19+
}
1520
}

src/scratch/list_functions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#pragma once
44

5+
#include <cstddef>
6+
57
namespace libscratchcpp
68
{
79

@@ -10,6 +12,7 @@ class List;
1012
extern "C"
1113
{
1214
void list_clear(List *list);
15+
void list_remove(List *list, size_t index);
1316
}
1417

1518
} // namespace libscratchcpp

test/scratch_classes/list_functions_test.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,24 @@ TEST(ListFunctionsTest, Clear)
1414

1515
list_clear(&list);
1616
}
17+
18+
TEST(ListFunctionsTest, Remove)
19+
{
20+
List list("", "test list");
21+
list.append("Lorem");
22+
list.append("ipsum");
23+
list.append("dolor");
24+
list.append("sit");
25+
list.append("amet");
26+
27+
list_remove(&list, 1);
28+
ASSERT_EQ(list.toString(), "Lorem dolor sit amet");
29+
list_remove(&list, 3);
30+
ASSERT_EQ(list.toString(), "Lorem dolor sit");
31+
list_remove(&list, 0);
32+
ASSERT_EQ(list.toString(), "dolor sit");
33+
list_remove(&list, 1);
34+
ASSERT_EQ(list.toString(), "dolor");
35+
list_remove(&list, 0);
36+
ASSERT_TRUE(list.empty());
37+
}

0 commit comments

Comments
 (0)