aboutsummaryrefslogtreecommitdiff
path: root/libc/test
diff options
context:
space:
mode:
authorcgyurgyik <gyurgyikcp@gmail.com>2020-08-04 14:55:12 -0400
committercgyurgyik <gyurgyikcp@gmail.com>2020-08-04 15:16:58 -0400
commit6cd50e7b75ed39ba1218c724401117cb6e12748d (patch)
treed5015bafa627848d8a5ed7542eb665230c63a8cd /libc/test
parentf2942f9c26a39340f8604857c7c90e6ade02a381 (diff)
downloadllvm-project-6cd50e7b75ed39ba1218c724401117cb6e12748d.tar.gz
[libc] Add implementations for isblank, iscntrl, isgraph, ispunct.
Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D85059
Diffstat (limited to 'libc/test')
-rw-r--r--libc/test/src/ctype/CMakeLists.txt40
-rw-r--r--libc/test/src/ctype/isblank_test.cpp21
-rw-r--r--libc/test/src/ctype/iscntrl_test.cpp21
-rw-r--r--libc/test/src/ctype/isgraph_test.cpp21
-rw-r--r--libc/test/src/ctype/ispunct_test.cpp34
5 files changed, 137 insertions, 0 deletions
diff --git a/libc/test/src/ctype/CMakeLists.txt b/libc/test/src/ctype/CMakeLists.txt
index c9959465c697..3adf5739d72a 100644
--- a/libc/test/src/ctype/CMakeLists.txt
+++ b/libc/test/src/ctype/CMakeLists.txt
@@ -21,6 +21,26 @@ add_libc_unittest(
)
add_libc_unittest(
+ isblank
+ SUITE
+ libc_ctype_unittests
+ SRCS
+ isblank_test.cpp
+ DEPENDS
+ libc.src.ctype.isblank
+)
+
+add_libc_unittest(
+ iscntrl
+ SUITE
+ libc_ctype_unittests
+ SRCS
+ iscntrl_test.cpp
+ DEPENDS
+ libc.src.ctype.iscntrl
+)
+
+add_libc_unittest(
isdigit
SUITE
libc_ctype_unittests
@@ -31,6 +51,16 @@ add_libc_unittest(
)
add_libc_unittest(
+ isgraph
+ SUITE
+ libc_ctype_unittests
+ SRCS
+ isgraph_test.cpp
+ DEPENDS
+ libc.src.ctype.isgraph
+)
+
+add_libc_unittest(
islower
SUITE
libc_ctype_unittests
@@ -41,6 +71,16 @@ add_libc_unittest(
)
add_libc_unittest(
+ ispunct
+ SUITE
+ libc_ctype_unittests
+ SRCS
+ ispunct_test.cpp
+ DEPENDS
+ libc.src.ctype.ispunct
+)
+
+add_libc_unittest(
isupper
SUITE
libc_ctype_unittests
diff --git a/libc/test/src/ctype/isblank_test.cpp b/libc/test/src/ctype/isblank_test.cpp
new file mode 100644
index 000000000000..f024ef67f9f6
--- /dev/null
+++ b/libc/test/src/ctype/isblank_test.cpp
@@ -0,0 +1,21 @@
+//===-- Unittests for isblank----------------------------------------------===//
+//
+// 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/isblank.h"
+#include "utils/UnitTest/Test.h"
+
+TEST(IsBlank, DefaultLocale) {
+ // Loops through all characters, verifying that space and horizontal tab
+ // return a non-zero integer and everything else returns zero.
+ for (int ch = 0; ch < 255; ++ch) {
+ if (ch == ' ' || ch == '\t')
+ EXPECT_NE(__llvm_libc::isblank(ch), 0);
+ else
+ EXPECT_EQ(__llvm_libc::isblank(ch), 0);
+ }
+}
diff --git a/libc/test/src/ctype/iscntrl_test.cpp b/libc/test/src/ctype/iscntrl_test.cpp
new file mode 100644
index 000000000000..5af7457cbda4
--- /dev/null
+++ b/libc/test/src/ctype/iscntrl_test.cpp
@@ -0,0 +1,21 @@
+//===-- Unittests for iscntrl----------------------------------------------===//
+//
+// 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/iscntrl.h"
+#include "utils/UnitTest/Test.h"
+
+TEST(IsCntrl, DefaultLocale) {
+ // Loops through all characters, verifying that control characters
+ // return a non-zero integer, all others return zero.
+ for (int ch = 0; ch < 255; ++ch) {
+ if ((0 <= ch && ch <= 0x1f /*US*/) || ch == 0x7f /*DEL*/)
+ EXPECT_NE(__llvm_libc::iscntrl(ch), 0);
+ else
+ EXPECT_EQ(__llvm_libc::iscntrl(ch), 0);
+ }
+}
diff --git a/libc/test/src/ctype/isgraph_test.cpp b/libc/test/src/ctype/isgraph_test.cpp
new file mode 100644
index 000000000000..1ed1ec7145f6
--- /dev/null
+++ b/libc/test/src/ctype/isgraph_test.cpp
@@ -0,0 +1,21 @@
+//===-- Unittests for isgraph----------------------------------------------===//
+//
+// 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/isgraph.h"
+#include "utils/UnitTest/Test.h"
+
+TEST(IsGraph, DefaultLocale) {
+ // Loops through all characters, verifying that graphical characters
+ // return a non-zero integer, everything else returns zero.
+ for (int ch = 0; ch < 255; ++ch) {
+ if ('!' <= ch && ch <= '~') // A-Z, a-z, 0-9, punctuation.
+ EXPECT_NE(__llvm_libc::isgraph(ch), 0);
+ else
+ EXPECT_EQ(__llvm_libc::isgraph(ch), 0);
+ }
+}
diff --git a/libc/test/src/ctype/ispunct_test.cpp b/libc/test/src/ctype/ispunct_test.cpp
new file mode 100644
index 000000000000..07e83fb36c7c
--- /dev/null
+++ b/libc/test/src/ctype/ispunct_test.cpp
@@ -0,0 +1,34 @@
+//===-- Unittests for ispunct----------------------------------------------===//
+//
+// 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/ispunct.h"
+#include "utils/UnitTest/Test.h"
+
+// Helper function to mark the sections of the ASCII table that are
+// punctuation characters. These are listed below:
+// Decimal | Symbol
+// -----------------------------------------
+// 33 - 47 | ! " $ % & ' ( ) * + , - . /
+// 58 - 64 | : ; < = > ? @
+// 91 - 96 | [ \ ] ^ _ `
+// 123 - 126 | { | } ~
+static inline int is_punctuation_character(int c) {
+ return ('!' <= c && c <= '/') || (':' <= c && c <= '@') ||
+ ('[' <= c && c <= '`') || ('{' <= c && c <= '~');
+}
+
+TEST(IsPunct, DefaultLocale) {
+ // Loops through all characters, verifying that punctuation characters
+ // return a non-zero integer, and everything else returns zero.
+ for (int ch = 0; ch < 255; ++ch) {
+ if (is_punctuation_character(ch))
+ EXPECT_NE(__llvm_libc::ispunct(ch), 0);
+ else
+ EXPECT_EQ(__llvm_libc::ispunct(ch), 0);
+ }
+}