Skip to content

Commit 41599a3

Browse files
committed
Add tests for String move
1 parent 9668aa6 commit 41599a3

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ set(TEST_SRCS
6666
src/String/test_indexOf.cpp
6767
src/String/test_lastIndexOf.cpp
6868
src/String/test_length.cpp
69+
src/String/test_move.cpp
6970
src/String/test_remove.cpp
7071
src/String/test_replace.cpp
7172
src/String/test_String.cpp

test/src/String/test_move.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <catch.hpp>
2+
3+
#include <String.h>
4+
5+
#include "StringPrinter.h"
6+
7+
#include <utility>
8+
9+
TEST_CASE("Testing String move constructor", "[String-move-01]")
10+
{
11+
arduino::String a("src");
12+
char const* const a_str = a.c_str();
13+
arduino::String b(std::move(a));
14+
REQUIRE(a.length() == 0);
15+
REQUIRE(a.c_str() == nullptr);
16+
REQUIRE(b.c_str() == a_str);
17+
REQUIRE(b.length() == 3);
18+
}
19+
20+
TEST_CASE("Testing String move assignment", "[String-move-02]")
21+
{
22+
arduino::String a("src");
23+
char const* const a_str = a.c_str();
24+
arduino::String b;
25+
b = std::move(a);
26+
REQUIRE(a.length() == 0);
27+
REQUIRE(a.c_str() == nullptr);
28+
REQUIRE(b == arduino::String("src"));
29+
REQUIRE(b.c_str() == a_str);
30+
}
31+
32+
TEST_CASE("Testing String move self assignment", "[String-move-03]")
33+
{
34+
arduino::String a("src");
35+
a = std::move(a);
36+
REQUIRE(a == "src");
37+
}

0 commit comments

Comments
 (0)