Skip to content

Commit b76e0af

Browse files
committed
Adding test code for String::toInt()
1 parent 27cfc4e commit b76e0af

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ set(TEST_SRCS
4646
src/String/test_length.cpp
4747
src/String/test_replace.cpp
4848
src/String/test_String.cpp
49+
src/String/test_toInt.cpp
4950
src/String/test_toLowerCase.cpp
5051
src/String/test_toUpperCase.cpp
5152
src/String/test_trim.cpp

test/src/String/test_toInt.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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::toInt when string is empty", "[String-toInt-01]")
18+
{
19+
arduino::String str;
20+
int const val = str.toInt();
21+
REQUIRE(val == 0);
22+
}
23+
24+
TEST_CASE ("Testing String::toInt when string contains no number", "[String-toInt-02]")
25+
{
26+
arduino::String str("abc");
27+
int const val = str.toInt();
28+
REQUIRE(val == 0);
29+
}
30+
31+
TEST_CASE ("Testing String::toInt when string contains a number", "[String-toInt-03]")
32+
{
33+
arduino::String str("-1");
34+
int const val = str.toInt();
35+
REQUIRE(val == -1);
36+
}

0 commit comments

Comments
 (0)