[libc-commits] [PATCH] D147873: [libc] Add a test condition for EOF	in ctype
    Shivam Gupta via Phabricator via libc-commits 
    libc-commits at lists.llvm.org
       
    Sun Apr  9 00:13:46 PDT 2023
    
    
  
xgupta created this revision.
xgupta added reviewers: rillig, michaelrj, lntue, sivachandra.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added projects: libc-project, All.
xgupta requested review of this revision.
This address https://github.com/llvm/llvm-project/issues/62000.
Header stdio.h is included because EOF define there.
The loop condition changed from <255 to <=255 to include EOF.
Repository:
  rG LLVM Github Monorepo
https://reviews.llvm.org/D147873
Files:
  libc/test/src/ctype/isalpha_test.cpp
Index: libc/test/src/ctype/isalpha_test.cpp
===================================================================
--- libc/test/src/ctype/isalpha_test.cpp
+++ libc/test/src/ctype/isalpha_test.cpp
@@ -6,17 +6,22 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <stdio.h>
+
 #include "src/ctype/isalpha.h"
 
 #include "test/UnitTest/Test.h"
 
 TEST(LlvmLibcIsAlpha, DefaultLocale) {
   // 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'))
+  // non-zero integer and everything else including EOF returns zero.
+  for (int ch = 0; ch < 256; ++ch) {
+    if (('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z')) {
       EXPECT_NE(__llvm_libc::isalpha(ch), 0);
-    else
+    } else if (ch == EOF) {
+      EXPECT_EQ(__llvm_libc::isalpha(ch), 0);
+    } else {
       EXPECT_EQ(__llvm_libc::isalpha(ch), 0);
+    }
   }
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147873.511959.patch
Type: text/x-patch
Size: 1040 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230409/5f9e091a/attachment.bin>
    
    
More information about the libc-commits
mailing list