Skip to content

Commit 336ce65

Browse files
committed
Adding test code for String::trim
1 parent bf77b48 commit 336ce65

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

Diff for: test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ set(TEST_SRCS
4747
src/String/test_String.cpp
4848
src/String/test_toLowerCase.cpp
4949
src/String/test_toUpperCase.cpp
50+
src/String/test_trim.cpp
5051
src/WCharacter/test_isControl.cpp
5152
src/WCharacter/test_isDigit.cpp
5253
src/WCharacter/test_isHexadecimalDigit.cpp

Diff for: test/src/String/test_trim.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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::trim with space at the beginning", "[String-trim-01]")
18+
{
19+
arduino::String str(" hello");
20+
str.trim();
21+
REQUIRE(strcmp(str.c_str(), "hello") == 0);
22+
}
23+
24+
TEST_CASE ("Testing String::trim with space at the end", "[String-trim-02]")
25+
{
26+
arduino::String str("hello ");
27+
str.trim();
28+
REQUIRE(strcmp(str.c_str(), "hello") == 0);
29+
}
30+
31+
TEST_CASE ("Testing String::trim with space at both beginng and end", "[String-trim-03]")
32+
{
33+
arduino::String str(" hello ");
34+
str.trim();
35+
REQUIRE(strcmp(str.c_str(), "hello") == 0);
36+
}
37+
38+
TEST_CASE ("Testing String::trim with space in the middle", "[String-trim-04]")
39+
{
40+
arduino::String str("Hello Arduino!");
41+
str.trim();
42+
REQUIRE(strcmp(str.c_str(), "Hello Arduino!") == 0);
43+
}

0 commit comments

Comments
 (0)