diff options
author | cgyurgyik <gyurgyikcp@gmail.com> | 2020-08-06 15:21:07 -0400 |
---|---|---|
committer | cgyurgyik <gyurgyikcp@gmail.com> | 2020-08-06 15:21:38 -0400 |
commit | 128bf458ab8c5bdbb02e5b13769a618b357d5ae2 (patch) | |
tree | 1d5fe7631a6dda4bf83b77c8c91ac4fdd883fc26 /libc/test | |
parent | a7478fab6ce82532c1545614362a3688e8a4ed36 (diff) | |
download | llvm-project-128bf458ab8c5bdbb02e5b13769a618b357d5ae2.tar.gz |
[libc] Add tolower, toupper implementation.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D85326
Diffstat (limited to 'libc/test')
-rw-r--r-- | libc/test/src/ctype/CMakeLists.txt | 20 | ||||
-rw-r--r-- | libc/test/src/ctype/tolower_test.cpp | 20 | ||||
-rw-r--r-- | libc/test/src/ctype/toupper_test.cpp | 20 |
3 files changed, 60 insertions, 0 deletions
diff --git a/libc/test/src/ctype/CMakeLists.txt b/libc/test/src/ctype/CMakeLists.txt index 0d77134b95eb..4141708fc2b4 100644 --- a/libc/test/src/ctype/CMakeLists.txt +++ b/libc/test/src/ctype/CMakeLists.txt @@ -119,3 +119,23 @@ add_libc_unittest( DEPENDS libc.src.ctype.isxdigit ) + +add_libc_unittest( + tolower + SUITE + libc_ctype_unittests + SRCS + tolower_test.cpp + DEPENDS + libc.src.ctype.tolower +) + +add_libc_unittest( + toupper + SUITE + libc_ctype_unittests + SRCS + toupper_test.cpp + DEPENDS + libc.src.ctype.toupper +) diff --git a/libc/test/src/ctype/tolower_test.cpp b/libc/test/src/ctype/tolower_test.cpp new file mode 100644 index 000000000000..096ef969bf63 --- /dev/null +++ b/libc/test/src/ctype/tolower_test.cpp @@ -0,0 +1,20 @@ +//===-- Unittests for tolower----------------------------------------------===// +// +// 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/tolower.h" +#include "utils/UnitTest/Test.h" + +TEST(ToLower, DefaultLocale) { + for (int ch = 0; ch < 255; ++ch) { + // This follows pattern 'A' + 32 = 'a'. + if ('A' <= ch && ch <= 'Z') + EXPECT_EQ(__llvm_libc::tolower(ch), ch + 32); + else + EXPECT_EQ(__llvm_libc::tolower(ch), ch); + } +} diff --git a/libc/test/src/ctype/toupper_test.cpp b/libc/test/src/ctype/toupper_test.cpp new file mode 100644 index 000000000000..4d6a1b3d4f65 --- /dev/null +++ b/libc/test/src/ctype/toupper_test.cpp @@ -0,0 +1,20 @@ +//===-- Unittests for toupper----------------------------------------------===// +// +// 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/toupper.h" +#include "utils/UnitTest/Test.h" + +TEST(ToUpper, DefaultLocale) { + for (int ch = 0; ch < 255; ++ch) { + // This follows pattern 'a' - 32 = 'A'. + if ('a' <= ch && ch <= 'z') + EXPECT_EQ(__llvm_libc::toupper(ch), ch - 32); + else + EXPECT_EQ(__llvm_libc::toupper(ch), ch); + } +} |