Skip to content

Commit ffc4b00

Browse files
committed
Add testcases for isAscii
1 parent c6ca793 commit ffc4b00

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

Diff for: test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ set(TEST_SRCS
8181
src/String/test_toLowerCase.cpp
8282
src/String/test_toUpperCase.cpp
8383
src/String/test_trim.cpp
84+
src/WCharacter/test_isAscii.cpp
8485
src/WCharacter/test_isControl.cpp
8586
src/WCharacter/test_isDigit.cpp
8687
src/WCharacter/test_isHexadecimalDigit.cpp

Diff for: test/src/WCharacter/test_isAscii.cpp

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2020 Arduino. All rights reserved.
3+
*/
4+
5+
/**************************************************************************************
6+
* INCLUDE
7+
**************************************************************************************/
8+
9+
#include <catch.hpp>
10+
11+
#include <vector>
12+
13+
#include <WCharacter.h>
14+
15+
/**************************************************************************************
16+
* CONSTANTS
17+
**************************************************************************************/
18+
19+
std::vector<char> const VALID_ASCII_VECT = {' ', 'a', 'b', 'q', '\n', '\r'};
20+
21+
/**************************************************************************************
22+
* TEST CODE
23+
**************************************************************************************/
24+
25+
TEST_CASE ("isAscii(...) is called with a valid ascii character", "[isAscii-01]")
26+
{
27+
std::for_each(std::begin(VALID_ASCII_VECT),
28+
std::end (VALID_ASCII_VECT),
29+
[](char const c)
30+
{
31+
REQUIRE(arduino::isAscii(c) == true);
32+
});
33+
}
34+
35+
TEST_CASE ("isAscii(...) is called with a invalid ascii character", "[isAscii-02]")
36+
{
37+
REQUIRE(arduino::isAscii(0xf7) == false);
38+
}
39+
40+
TEST_CASE ("isAscii(...) is called with a invalid casted ascii character", "[isAscii-03]")
41+
{
42+
REQUIRE(arduino::isAscii((unsigned char)0xf7) == false);
43+
}
44+
45+
TEST_CASE ("isAscii(...) is called with a character latger than 1 byte", "[isAscii-04]")
46+
{
47+
REQUIRE(arduino::isAscii(0x3030) == false);
48+
}
49+

0 commit comments

Comments
 (0)