diff options
author | cgyurgyik <gyurgyikcp@gmail.com> | 2020-07-31 14:04:36 -0400 |
---|---|---|
committer | cgyurgyik <gyurgyikcp@gmail.com> | 2020-07-31 14:05:27 -0400 |
commit | e2d4bf6ceca84c2ff515d6bc89da7d40d1c971fb (patch) | |
tree | 2fd8cf1f5dbf688700b62fab2c6d4a499ef9222d /libc/test | |
parent | 46591b95362325d262ca29ce13e7b5ddda624bc8 (diff) | |
download | llvm-project-e2d4bf6ceca84c2ff515d6bc89da7d40d1c971fb.tar.gz |
[libc] Add islower and isupper implementation.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D84960
Diffstat (limited to 'libc/test')
-rw-r--r-- | libc/test/src/ctype/CMakeLists.txt | 20 | ||||
-rw-r--r-- | libc/test/src/ctype/isalnum_test.cpp | 12 | ||||
-rw-r--r-- | libc/test/src/ctype/isalpha_test.cpp | 14 | ||||
-rw-r--r-- | libc/test/src/ctype/isdigit_test.cpp | 14 | ||||
-rw-r--r-- | libc/test/src/ctype/islower_test.cpp | 21 | ||||
-rw-r--r-- | libc/test/src/ctype/isupper_test.cpp | 21 |
6 files changed, 76 insertions, 26 deletions
diff --git a/libc/test/src/ctype/CMakeLists.txt b/libc/test/src/ctype/CMakeLists.txt index 7834746ab1d7..c9959465c697 100644 --- a/libc/test/src/ctype/CMakeLists.txt +++ b/libc/test/src/ctype/CMakeLists.txt @@ -29,3 +29,23 @@ add_libc_unittest( DEPENDS libc.src.ctype.isdigit ) + +add_libc_unittest( + islower + SUITE + libc_ctype_unittests + SRCS + islower_test.cpp + DEPENDS + libc.src.ctype.islower +) + +add_libc_unittest( + isupper + SUITE + libc_ctype_unittests + SRCS + isupper_test.cpp + DEPENDS + libc.src.ctype.isupper +) diff --git a/libc/test/src/ctype/isalnum_test.cpp b/libc/test/src/ctype/isalnum_test.cpp index 1c4ad7d3ff8a..ca77285c5614 100644 --- a/libc/test/src/ctype/isalnum_test.cpp +++ b/libc/test/src/ctype/isalnum_test.cpp @@ -7,21 +7,17 @@ //===----------------------------------------------------------------------===// #include "src/ctype/isalnum.h" -#include "utils/UnitTest/Test.h" -// Helper function that makes a call to isalnum a bit cleaner -// for use with testing utilities, since it explicitly requires -// a boolean value for EXPECT_TRUE and EXPECT_FALSE. -bool call_isalnum(int c) { return __llvm_libc::isalnum(c); } +#include "utils/UnitTest/Test.h" TEST(IsAlNum, DefaultLocale) { // Loops through all characters, verifying that numbers and letters - // return true and everything else returns false. + // return non-zero integer and everything else returns a zero. for (int c = 0; c < 255; ++c) { if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9')) - EXPECT_TRUE(call_isalnum(c)); + EXPECT_NE(__llvm_libc::isalnum(c), 0); else - EXPECT_FALSE(call_isalnum(c)); + EXPECT_EQ(__llvm_libc::isalnum(c), 0); } } diff --git a/libc/test/src/ctype/isalpha_test.cpp b/libc/test/src/ctype/isalpha_test.cpp index 81fc7248f871..d91219b50406 100644 --- a/libc/test/src/ctype/isalpha_test.cpp +++ b/libc/test/src/ctype/isalpha_test.cpp @@ -7,20 +7,16 @@ //===----------------------------------------------------------------------===// #include "src/ctype/isalpha.h" -#include "utils/UnitTest/Test.h" -// Helper function that makes a call to isalpha a bit cleaner -// for use with testing utilities, since it explicitly requires -// a boolean value for EXPECT_TRUE and EXPECT_FALSE. -bool call_isalpha(int c) { return __llvm_libc::isalpha(c); } +#include "utils/UnitTest/Test.h" TEST(IsAlpha, DefaultLocale) { - // Loops through all characters, verifying that letters return true - // and everything else returns false. + // Loops through all characters, verifying that letters return a + // non-zero integer and everything else returns zero. for (int ch = 0; ch < 255; ++ch) { if (('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z')) - EXPECT_TRUE(call_isalpha(ch)); + EXPECT_NE(__llvm_libc::isalpha(ch), 0); else - EXPECT_FALSE(call_isalpha(ch)); + EXPECT_EQ(__llvm_libc::isalpha(ch), 0); } } diff --git a/libc/test/src/ctype/isdigit_test.cpp b/libc/test/src/ctype/isdigit_test.cpp index 6fea9564db67..2430a92425c4 100644 --- a/libc/test/src/ctype/isdigit_test.cpp +++ b/libc/test/src/ctype/isdigit_test.cpp @@ -7,20 +7,16 @@ //===----------------------------------------------------------------------===// #include "src/ctype/isdigit.h" -#include "utils/UnitTest/Test.h" -// Helper function that makes a call to isdigit a bit cleaner -// for use with testing utilities, since it explicitly requires -// a boolean value for EXPECT_TRUE and EXPECT_FALSE. -bool call_isdigit(int c) { return __llvm_libc::isdigit(c); } +#include "utils/UnitTest/Test.h" TEST(IsDigit, DefaultLocale) { - // Loops through all characters, verifying that numbers return true - // and everything else returns false. + // Loops through all characters, verifying that numbers return a + // non-zero integer and everything else returns zero. for (int ch = 0; ch < 255; ++ch) { if ('0' <= ch && ch <= '9') - EXPECT_TRUE(call_isdigit(ch)); + EXPECT_NE(__llvm_libc::isdigit(ch), 0); else - EXPECT_FALSE(call_isdigit(ch)); + EXPECT_EQ(__llvm_libc::isdigit(ch), 0); } } diff --git a/libc/test/src/ctype/islower_test.cpp b/libc/test/src/ctype/islower_test.cpp new file mode 100644 index 000000000000..9b38cabc67aa --- /dev/null +++ b/libc/test/src/ctype/islower_test.cpp @@ -0,0 +1,21 @@ +//===-- Unittests for islower----------------------------------------------===// +// +// 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/islower.h" +#include "utils/UnitTest/Test.h" + +TEST(IsLower, DefaultLocale) { + // Loops through all characters, verifying that lowercase letters + // return a non-zero integer and everything else returns zero. + for (int ch = 0; ch < 255; ++ch) { + if ('a' <= ch && ch <= 'z') + EXPECT_NE(__llvm_libc::islower(ch), 0); + else + EXPECT_EQ(__llvm_libc::islower(ch), 0); + } +} diff --git a/libc/test/src/ctype/isupper_test.cpp b/libc/test/src/ctype/isupper_test.cpp new file mode 100644 index 000000000000..0a13f4e11b0e --- /dev/null +++ b/libc/test/src/ctype/isupper_test.cpp @@ -0,0 +1,21 @@ +//===-- Unittests for isupper----------------------------------------------===// +// +// 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/isupper.h" +#include "utils/UnitTest/Test.h" + +TEST(IsUpper, DefaultLocale) { + // Loops through all characters, verifying that uppercase letters + // return a non-zero integer and everything else returns zero. + for (int ch = 0; ch < 255; ++ch) { + if ('A' <= ch && ch <= 'Z') + EXPECT_NE(__llvm_libc::isupper(ch), 0); + else + EXPECT_EQ(__llvm_libc::isupper(ch), 0); + } +} |