-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathtest_replace.cpp
61 lines (51 loc) · 2.08 KB
/
test_replace.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <catch.hpp>
#include <String.h>
/**************************************************************************************
* TEST CODE
**************************************************************************************/
TEST_CASE ("Testing String::replace(char, char) when string is empty", "[String-replace-01]")
{
arduino::String str;
str.replace('a', 'b');
REQUIRE(str.length() == 0);
}
TEST_CASE ("Testing String::replace(char, char) when string contains elements != 'find'", "[String-replace-02]")
{
arduino::String str("Hello Arduino!");
str.replace('Z', '0');
REQUIRE(strcmp(str.c_str(), "Hello Arduino!") == 0);
}
TEST_CASE ("Testing String::replace(char, char) when string contains elements = 'find'", "[String-replace-03]")
{
arduino::String str("Hello Arduino!");
str.replace('o', '0');
str.replace('e', '3');
str.replace('i', '1');
REQUIRE(strcmp(str.c_str(), "H3ll0 Ardu1n0!") == 0);
}
TEST_CASE ("Testing String::replace(String, String) when string does not constain subtr 'find'", "[String-replace-04]")
{
arduino::String str("Hello Arduino!");
str.replace(arduino::String("Zulu"), arduino::String("11"));
REQUIRE(strcmp(str.c_str(), "Hello Arduino!") == 0);
}
TEST_CASE ("Testing String::replace(String, String) when string constains subtr 'find'", "[String-replace-05]")
{
arduino::String str("Hello Arduino!");
str.replace(arduino::String("ll"), arduino::String("11"));
REQUIRE(strcmp(str.c_str(), "He11o Arduino!") == 0);
}
TEST_CASE ("Testing String::replace(String, String) substr 'find' smaller than 'replace'", "[String-replace-06]")
{
arduino::String str("Hello Arduino!");
str.replace(arduino::String("ll"), arduino::String("111"));
REQUIRE(strcmp(str.c_str(), "He111o Arduino!") == 0);
//REQUIRE(strcmp("He11 Arduino!", "He11 Arduino!") == 0);
//REQUIRE(str.startsWith("Hel1o") == 0);
}