-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathtest_parseInt.cpp
105 lines (92 loc) · 2.89 KB
/
test_parseInt.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <catch.hpp>
#include <StreamMock.h>
/**************************************************************************************
* TEST CODE
**************************************************************************************/
using namespace arduino;
TEST_CASE ("Testing parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR)", "[Stream-parseInt-01]")
{
StreamMock mock;
WHEN ("A positive integer is contained in stream")
{
mock << "1234";
REQUIRE(mock.parseInt() == 1234);
}
WHEN ("A negative integer is contained in stream")
{
mock << "-1234";
REQUIRE(mock.parseInt() == -1234);
}
WHEN ("A integer is prepended by digits")
{
mock << "abcdef1234";
REQUIRE(mock.parseInt() == 1234);
}
WHEN ("A integer is prepended by whitespace chars")
{
mock << "\r\n\t 1234";
REQUIRE(mock.parseInt() == 1234);
}
}
TEST_CASE ("Testing parseInt(LookaheadMode lookahead = SKIP_NONE, char ignore = NO_IGNORE_CHAR)", "[Stream-parseInt-02]")
{
StreamMock mock;
WHEN ("A positive integer is contained in stream")
{
mock << "1234";
REQUIRE(mock.parseInt(SKIP_NONE) == 1234);
REQUIRE(mock.readString() == arduino::String(""));
}
WHEN ("A integer is prepended by digits")
{
mock << "abcdef1234";
REQUIRE(mock.parseInt(SKIP_NONE) == 0);
REQUIRE(mock.readString() == arduino::String("abcdef1234"));
}
WHEN ("A integer is prepended by whitespace chars")
{
mock << "\r\n\t 1234";
REQUIRE(mock.parseInt(SKIP_NONE) == 0);
REQUIRE(mock.readString() == arduino::String("\r\n\t 1234"));
}
}
TEST_CASE ("Testing parseInt(LookaheadMode lookahead = SKIP_WHITESPACE, char ignore = NO_IGNORE_CHAR)", "[Stream-parseInt-03]")
{
StreamMock mock;
WHEN ("A integer is prepended by whitespace chars")
{
mock << "\r\n\t 1234";
REQUIRE(mock.parseInt(SKIP_WHITESPACE) == 1234);
REQUIRE(mock.readString() == arduino::String(""));
}
}
TEST_CASE ("Testing parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = 'a')", "[Stream-parseInt-04]")
{
StreamMock mock;
WHEN ("A positive integer is contained in stream")
{
mock << "1234";
REQUIRE(mock.parseInt(SKIP_ALL, 'a') == 1234);
REQUIRE(mock.readString() == arduino::String(""));
}
WHEN ("A integer contains only ignore char values")
{
mock << "12a3a4a";
REQUIRE(mock.parseInt(SKIP_ALL, 'a') == 1234);
REQUIRE(mock.readString() == arduino::String(""));
}
WHEN ("A integer contains other than ignore chars")
{
mock << "1bed234";
REQUIRE(mock.parseInt(SKIP_ALL, 'a') == 1);
REQUIRE(mock.readString() == arduino::String("bed234"));
}
}