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 3965a74

Browse files
Add test code for String::substring(...)
1 parent 5a05bb6 commit 3965a74

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
@@ -46,6 +46,7 @@ set(TEST_SRCS
4646
src/String/test_compareTo.cpp
4747
src/String/test_comparisonFunc.cpp
4848
src/String/test_characterAccessFunc.cpp
49+
src/String/test_substring.cpp
4950
src/String/test_indexOf.cpp
5051
src/String/test_lastIndexOf.cpp
5152
src/String/test_length.cpp

‎test/src/String/test_substring.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::substring(unsigned int, unsigned int)", "[String-substring-01]")
18+
{
19+
WHEN ("left higher than len")
20+
{
21+
arduino::String str("Hello");
22+
str.substring(7,9);
23+
}
24+
25+
WHEN ("right higher than len")
26+
{
27+
arduino::String str1("Hello");
28+
arduino::String str2("ello");
29+
REQUIRE(str2.compareTo(str1.substring(1,9)) == 0);
30+
}
31+
32+
WHEN ("left higher than right")
33+
{
34+
arduino::String str1("Hello");
35+
arduino::String str2("ello");
36+
REQUIRE(str2.compareTo(str1.substring(9,1)) == 0);
37+
}
38+
}

0 commit comments

Comments
(0)

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