Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3156de9

Browse files
Adding test code for String::replace(...)
1 parent 336ce65 commit 3156de9

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-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_replace.cpp
4748
src/String/test_String.cpp
4849
src/String/test_toLowerCase.cpp
4950
src/String/test_toUpperCase.cpp

‎test/src/String/test_replace.cpp‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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::replace when string is empty", "[String-replace-01]")
18+
{
19+
arduino::String str;
20+
str.replace('a', 'b');
21+
REQUIRE(str.length() == 0);
22+
}
23+
24+
TEST_CASE ("Testing String::replace when string contains elements != 'find'", "[String-replace-02]")
25+
{
26+
arduino::String str("Hello Arduino!");
27+
str.replace('Z', '0');
28+
REQUIRE(strcmp(str.c_str(), "Hello Arduino!") == 0);
29+
}
30+
31+
TEST_CASE ("Testing String::replace when string contains elements = 'find'", "[String-replace-02]")
32+
{
33+
arduino::String str("Hello Arduino!");
34+
str.replace('o', '0');
35+
str.replace('e', '3');
36+
str.replace('i', '1');
37+
REQUIRE(strcmp(str.c_str(), "H3ll0 Ardu1n0!") == 0);
38+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /