Skip to content

Commit 153a1f1

Browse files
committed
Adding test code for String::remove(...)
1 parent a46aef0 commit 153a1f1

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ set(TEST_SRCS
4444
src/Ringbuffer/test_store_char.cpp
4545
src/String/test_concat.cpp
4646
src/String/test_length.cpp
47+
src/String/test_remove.cpp
4748
src/String/test_replace.cpp
4849
src/String/test_String.cpp
4950
src/String/test_toDouble.cpp

test/src/String/test_remove.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2020 Arduino. All rights reserved.
3+
*/
4+
5+
/**************************************************************************************
6+
* INCLUDE
7+
**************************************************************************************/
8+
9+
#include <catch.hpp>
10+
11+
#include <String.h>
12+
13+
/**************************************************************************************
14+
* TEST CODE
15+
**************************************************************************************/
16+
17+
TEST_CASE ("Testing String::remove(index) when string is empty", "[String-remove-01]")
18+
{
19+
arduino::String str;
20+
str.remove(0);
21+
REQUIRE(str.length() == 0);
22+
}
23+
24+
TEST_CASE ("Testing String::remove(index) when index is > string length", "[String-remove-02]")
25+
{
26+
arduino::String str("Hello Arduino!");
27+
str.remove(100);
28+
REQUIRE(strcmp(str.c_str(), "Hello Arduino!") == 0);
29+
}
30+
31+
TEST_CASE ("Testing String::remove(index) when index is < string length", "[String-remove-03]")
32+
{
33+
arduino::String str("Hello Arduino!");
34+
str.remove(5);
35+
REQUIRE(strcmp(str.c_str(), "Hello") == 0);
36+
}
37+
38+
TEST_CASE ("Testing String::remove(index,count) when string is empty", "[String-remove-04]")
39+
{
40+
arduino::String str;
41+
str.remove(0, 10);
42+
REQUIRE(str.length() == 0);
43+
}
44+
45+
TEST_CASE ("Testing String::remove(index,count) when index is > string length", "[String-remove-05]")
46+
{
47+
arduino::String str("Hello Arduino!");
48+
str.remove(100, 10);
49+
REQUIRE(strcmp(str.c_str(), "Hello Arduino!") == 0);
50+
}
51+
52+
TEST_CASE ("Testing String::remove(index,count) when index is < string length && count is > remaining length", "[String-remove-06]")
53+
{
54+
arduino::String str("Hello Arduino!");
55+
str.remove(5, 100);
56+
REQUIRE(strcmp(str.c_str(), "Hello") == 0);
57+
}
58+
59+
TEST_CASE ("Testing String::remove(index,count) when index is < string length && count is < remaining length", "[String-remove-07]")
60+
{
61+
arduino::String str("Hello Arduino!");
62+
str.remove(5, 1);
63+
REQUIRE(strcmp(str.c_str(), "HelloArduino!") == 0);
64+
}

0 commit comments

Comments
 (0)