|
| 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(char, char) 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(char, char) 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(char, char) when string contains elements = 'find'", "[String-replace-03]") |
| 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 | +} |
| 39 | + |
| 40 | +TEST_CASE ("Testing String::replace(String, String) when string does not constain subtr 'find'", "[String-replace-04]") |
| 41 | +{ |
| 42 | + arduino::String str("Hello Arduino!"); |
| 43 | + str.replace(arduino::String("Zulu"), arduino::String("11")); |
| 44 | + REQUIRE(strcmp(str.c_str(), "Hello Arduino!") == 0); |
| 45 | +} |
| 46 | + |
| 47 | +TEST_CASE ("Testing String::replace(String, String) when string constains subtr 'find'", "[String-replace-05]") |
| 48 | +{ |
| 49 | + arduino::String str("Hello Arduino!"); |
| 50 | + str.replace(arduino::String("ll"), arduino::String("11")); |
| 51 | + REQUIRE(strcmp(str.c_str(), "He11o Arduino!") == 0); |
| 52 | +} |
0 commit comments