[libc] add isascii and toascii implementations
[lldb.git] / libc / test / src / ctype / toascii_test.cpp
1 //===-- Unittests for toascii----------------------------------------------===//
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/toascii.h"
10
11 #include "utils/UnitTest/Test.h"
12
13 TEST(ToAscii, DefaultLocale) {
14   // Loops through all characters, verifying that ascii characters
15   //    (which are all 7 bit unsigned integers)
16   // return themself, and that all other characters return themself
17   // mod 128 (which is equivalent to & 0x7f)
18   for (int ch = 0; ch < 255; ++ch) {
19     if (ch <= 0x7f)
20       EXPECT_EQ(__llvm_libc::toascii(ch), ch);
21     else
22       EXPECT_EQ(__llvm_libc::toascii(ch), ch & 0x7f);
23   }
24 }