diff options
author | cgyurgyik <gyurgyikcp@gmail.com> | 2020-08-05 10:42:30 -0400 |
---|---|---|
committer | cgyurgyik <gyurgyikcp@gmail.com> | 2020-08-05 10:51:43 -0400 |
commit | 1fdab96130fc86f2635d26b617adf10608b8e63b (patch) | |
tree | aa0d4dd1e5e1636f2794e7452b26f740b1f32c9e /libc/test | |
parent | 6a06c7a0a7688ce142865e92d879b8bece79de7a (diff) | |
download | llvm-project-1fdab96130fc86f2635d26b617adf10608b8e63b.tar.gz |
[libc] Add isspace, isprint, isxdigit implementations.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D85270
Diffstat (limited to 'libc/test')
-rw-r--r-- | libc/test/src/ctype/CMakeLists.txt | 30 | ||||
-rw-r--r-- | libc/test/src/ctype/isprint_test.cpp | 19 | ||||
-rw-r--r-- | libc/test/src/ctype/isspace_test.cpp | 28 | ||||
-rw-r--r-- | libc/test/src/ctype/isxdigit_test.cpp | 20 |
4 files changed, 97 insertions, 0 deletions
diff --git a/libc/test/src/ctype/CMakeLists.txt b/libc/test/src/ctype/CMakeLists.txt index 3adf5739d72a..0d77134b95eb 100644 --- a/libc/test/src/ctype/CMakeLists.txt +++ b/libc/test/src/ctype/CMakeLists.txt @@ -71,6 +71,16 @@ add_libc_unittest( ) add_libc_unittest( + isprint + SUITE + libc_ctype_unittests + SRCS + isprint_test.cpp + DEPENDS + libc.src.ctype.isprint +) + +add_libc_unittest( ispunct SUITE libc_ctype_unittests @@ -81,6 +91,16 @@ add_libc_unittest( ) add_libc_unittest( + isspace + SUITE + libc_ctype_unittests + SRCS + isspace_test.cpp + DEPENDS + libc.src.ctype.isspace +) + +add_libc_unittest( isupper SUITE libc_ctype_unittests @@ -89,3 +109,13 @@ add_libc_unittest( DEPENDS libc.src.ctype.isupper ) + +add_libc_unittest( + isxdigit + SUITE + libc_ctype_unittests + SRCS + isxdigit_test.cpp + DEPENDS + libc.src.ctype.isxdigit +) diff --git a/libc/test/src/ctype/isprint_test.cpp b/libc/test/src/ctype/isprint_test.cpp new file mode 100644 index 000000000000..565453e0013c --- /dev/null +++ b/libc/test/src/ctype/isprint_test.cpp @@ -0,0 +1,19 @@ +//===-- Unittests for isprint----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/ctype/isprint.h" +#include "utils/UnitTest/Test.h" + +TEST(IsPrint, DefaultLocale) { + for (int ch = 0; ch < 255; ++ch) { + if (' ' <= ch && ch <= '~') // A-Z, a-z, 0-9, punctuation, space. + EXPECT_NE(__llvm_libc::isprint(ch), 0); + else + EXPECT_EQ(__llvm_libc::isprint(ch), 0); + } +} diff --git a/libc/test/src/ctype/isspace_test.cpp b/libc/test/src/ctype/isspace_test.cpp new file mode 100644 index 000000000000..e1caded67452 --- /dev/null +++ b/libc/test/src/ctype/isspace_test.cpp @@ -0,0 +1,28 @@ +//===-- Unittests for isspace----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/ctype/isspace.h" +#include "utils/UnitTest/Test.h" + +TEST(IsSpace, DefaultLocale) { + // Loops through all characters, verifying that space characters + // return true and everything else returns false. + // Hexadecimal | Symbol + // --------------------------- + // 0x09 | horizontal tab + // 0x0a | line feed + // 0x0b | vertical tab + // 0x0d | carriage return + // 0x20 | space + for (int ch = 0; ch < 255; ++ch) { + if (ch == 0x20 || (0x09 <= ch && ch <= 0x0d)) + EXPECT_NE(__llvm_libc::isspace(ch), 0); + else + EXPECT_EQ(__llvm_libc::isspace(ch), 0); + } +} diff --git a/libc/test/src/ctype/isxdigit_test.cpp b/libc/test/src/ctype/isxdigit_test.cpp new file mode 100644 index 000000000000..570cb82b3c78 --- /dev/null +++ b/libc/test/src/ctype/isxdigit_test.cpp @@ -0,0 +1,20 @@ +//===-- Unittests for isxdigit---------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/ctype/isxdigit.h" +#include "utils/UnitTest/Test.h" + +TEST(IsXDigit, DefaultLocale) { + for (int ch = 0; ch < 255; ++ch) { + if (('0' <= ch && ch <= '9') || ('a' <= ch && ch <= 'f') || + ('A' <= ch && ch <= 'F')) + EXPECT_NE(__llvm_libc::isxdigit(ch), 0); + else + EXPECT_EQ(__llvm_libc::isxdigit(ch), 0); + } +} |