From 1fdab96130fc86f2635d26b617adf10608b8e63b Mon Sep 17 00:00:00 2001 From: cgyurgyik Date: Wed, 5 Aug 2020 10:42:30 -0400 Subject: [libc] Add isspace, isprint, isxdigit implementations. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D85270 --- libc/test/src/ctype/CMakeLists.txt | 30 ++++++++++++++++++++++++++++++ libc/test/src/ctype/isprint_test.cpp | 19 +++++++++++++++++++ libc/test/src/ctype/isspace_test.cpp | 28 ++++++++++++++++++++++++++++ libc/test/src/ctype/isxdigit_test.cpp | 20 ++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 libc/test/src/ctype/isprint_test.cpp create mode 100644 libc/test/src/ctype/isspace_test.cpp create mode 100644 libc/test/src/ctype/isxdigit_test.cpp (limited to 'libc/test') 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 @@ -70,6 +70,16 @@ add_libc_unittest( libc.src.ctype.islower ) +add_libc_unittest( + isprint + SUITE + libc_ctype_unittests + SRCS + isprint_test.cpp + DEPENDS + libc.src.ctype.isprint +) + add_libc_unittest( ispunct SUITE @@ -80,6 +90,16 @@ add_libc_unittest( libc.src.ctype.ispunct ) +add_libc_unittest( + isspace + SUITE + libc_ctype_unittests + SRCS + isspace_test.cpp + DEPENDS + libc.src.ctype.isspace +) + add_libc_unittest( isupper SUITE @@ -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); + } +} -- cgit v1.2.3