1 | //===-- Unittests for ispunct----------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "src/ctype/ispunct.h" |
10 | #include "test/UnitTest/Test.h" |
11 | |
12 | // Helper function to mark the sections of the ASCII table that are |
13 | // punctuation characters. These are listed below: |
14 | // Decimal | Symbol |
15 | // ----------------------------------------- |
16 | // 33 - 47 | ! " $ % & ' ( ) * + , - . / |
17 | // 58 - 64 | : ; < = > ? @ |
18 | // 91 - 96 | [ \ ] ^ _ ` |
19 | // 123 - 126 | { | } ~ |
20 | static inline int is_punctuation_character(int c) { |
21 | return ('!' <= c && c <= '/') || (':' <= c && c <= '@') || |
22 | ('[' <= c && c <= '`') || ('{' <= c && c <= '~'); |
23 | } |
24 | |
25 | TEST(LlvmLibcIsPunct, DefaultLocale) { |
26 | // Loops through all characters, verifying that punctuation characters |
27 | // return a non-zero integer, and everything else returns zero. |
28 | for (int ch = -255; ch < 255; ++ch) { |
29 | if (is_punctuation_character(c: ch)) |
30 | EXPECT_NE(LIBC_NAMESPACE::ispunct(ch), 0); |
31 | else |
32 | EXPECT_EQ(LIBC_NAMESPACE::ispunct(ch), 0); |
33 | } |
34 | } |
35 | |