Home
       0005-ctype.c - scc - simple c99 compiler
  HTML git clone git://git.simple-cc.org/scc
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
   DIR README
   DIR LICENSE
       ---
       0005-ctype.c (10082B)
       ---
            1 #include <assert.h>
            2 #include <ctype.h>
            3 #include <stdio.h>
            4 #include <limits.h>
            5 
            6 /*
            7  * This test assumes an ascii representation
            8  */
            9 
           10 #define TESTW(f) fputs(#f ":" , stdout); \
           11         for (i = 0; i <= UCHAR_MAX; i++)  \
           12                 if (f(i)) printf(" %d", i); \
           13         putchar('\n')
           14 
           15 #define TESTC(f) fputs(#f ": " , stdout); \
           16         for (i = 0; i <= UCHAR_MAX; i++)  \
           17                 if (f(i)) putchar(i); \
           18         putchar('\n')
           19 
           20 #define TESTEOF(f) fputs(#f ": " , stdout); \
           21         if (!f(EOF)) putchar('!'); puts("EOF");
           22 
           23 #define TESTLU(f) \
           24         for (i = 0; i < UCHAR_MAX; i++) { \
           25                 n = f(i); \
           26                 if (!isgraph(i)) \
           27                         continue; \
           28                 printf("%s: %c <-> %c\n", #f, i, n); \
           29         }
           30 
           31 void
           32 test1()
           33 {
           34         int i;
           35 
           36         puts("\ntest1");
           37         TESTC(isalnum);
           38         TESTC(isalpha);
           39         TESTC(isdigit);
           40         TESTC(isgraph);
           41         TESTC(islower);
           42         TESTC(isupper);
           43         TESTC(isprint);
           44         TESTC(ispunct);
           45         TESTC(isxdigit);
           46         TESTC(isdigit);
           47         TESTW(iscntrl);
           48         TESTW(isspace);
           49         TESTEOF(isalpha);
           50         TESTEOF(isdigit);
           51         TESTEOF(isgraph);
           52         TESTEOF(islower);
           53         TESTEOF(isupper);
           54         TESTEOF(isprint);
           55         TESTEOF(ispunct);
           56         TESTEOF(isxdigit);
           57         TESTEOF(isdigit);
           58         TESTEOF(iscntrl);
           59         TESTEOF(isspace);
           60 }
           61 
           62 #undef isalnum
           63 #undef isalpha
           64 #undef isdigit
           65 #undef isgraph
           66 #undef islower
           67 #undef isupper
           68 #undef isprint
           69 #undef ispunct
           70 #undef isxdigit
           71 #undef isdigit
           72 
           73 void
           74 test2()
           75 {
           76         int i;
           77 
           78         puts("\ntest2");
           79         TESTC(isalnum);
           80         TESTC(isalpha);
           81         TESTC(isdigit);
           82         TESTC(isgraph);
           83         TESTC(islower);
           84         TESTC(isupper);
           85         TESTC(isprint);
           86         TESTC(ispunct);
           87         TESTC(isxdigit);
           88         TESTC(isdigit);
           89         TESTW(iscntrl);
           90         TESTW(isspace);
           91         TESTEOF(isalpha);
           92         TESTEOF(isdigit);
           93         TESTEOF(isgraph);
           94         TESTEOF(islower);
           95         TESTEOF(isupper);
           96         TESTEOF(isprint);
           97         TESTEOF(ispunct);
           98         TESTEOF(isxdigit);
           99         TESTEOF(isdigit);
          100         TESTEOF(iscntrl);
          101         TESTEOF(isspace);
          102 }
          103 
          104 void test3()
          105 {
          106         int i, n;
          107 
          108         puts("\ntest3");
          109         TESTLU(tolower);
          110         TESTLU(toupper);
          111 }        
          112 
          113 #undef tolower
          114 #undef toupper
          115 
          116 void test4()
          117 {
          118         int i, n;
          119 
          120         puts("\ntest4");
          121         TESTLU(tolower);
          122         TESTLU(toupper);
          123         assert(tolower(EOF) == EOF);
          124         assert(toupper(EOF) == EOF);
          125 }
          126 
          127 int
          128 main()
          129 {
          130         test1();
          131         test2();
          132         test3();
          133         test4();
          134 
          135         return 0;
          136 }
          137 
          138 /*
          139 output:
          140 
          141 test1
          142 isalnum: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
          143 isalpha: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
          144 isdigit: 0123456789
          145 isgraph: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
          146 islower: abcdefghijklmnopqrstuvwxyz
          147 isupper: ABCDEFGHIJKLMNOPQRSTUVWXYZ
          148 isprint:  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
          149 ispunct: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
          150 isxdigit: 0123456789ABCDEFabcdef
          151 isdigit: 0123456789
          152 iscntrl: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 127
          153 isspace: 9 10 11 12 13 32
          154 isalpha: !EOF
          155 isdigit: !EOF
          156 isgraph: !EOF
          157 islower: !EOF
          158 isupper: !EOF
          159 isprint: !EOF
          160 ispunct: !EOF
          161 isxdigit: !EOF
          162 isdigit: !EOF
          163 iscntrl: !EOF
          164 isspace: !EOF
          165 
          166 test2
          167 isalnum: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
          168 isalpha: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
          169 isdigit: 0123456789
          170 isgraph: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
          171 islower: abcdefghijklmnopqrstuvwxyz
          172 isupper: ABCDEFGHIJKLMNOPQRSTUVWXYZ
          173 isprint:  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
          174 ispunct: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
          175 isxdigit: 0123456789ABCDEFabcdef
          176 isdigit: 0123456789
          177 iscntrl: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 127
          178 isspace: 9 10 11 12 13 32
          179 isalpha: !EOF
          180 isdigit: !EOF
          181 isgraph: !EOF
          182 islower: !EOF
          183 isupper: !EOF
          184 isprint: !EOF
          185 ispunct: !EOF
          186 isxdigit: !EOF
          187 isdigit: !EOF
          188 iscntrl: !EOF
          189 isspace: !EOF
          190 
          191 test3
          192 tolower: ! <-> !
          193 tolower: " <-> "
          194 tolower: # <-> #
          195 tolower: $ <-> $
          196 tolower: % <-> %
          197 tolower: & <-> &
          198 tolower: ' <-> '
          199 tolower: ( <-> (
          200 tolower: ) <-> )
          201 tolower: * <-> *
          202 tolower: + <-> +
          203 tolower: , <-> ,
          204 tolower: - <-> -
          205 tolower: . <-> .
          206 tolower: / <-> /
          207 tolower: 0 <-> 0
          208 tolower: 1 <-> 1
          209 tolower: 2 <-> 2
          210 tolower: 3 <-> 3
          211 tolower: 4 <-> 4
          212 tolower: 5 <-> 5
          213 tolower: 6 <-> 6
          214 tolower: 7 <-> 7
          215 tolower: 8 <-> 8
          216 tolower: 9 <-> 9
          217 tolower: : <-> :
          218 tolower: ; <-> ;
          219 tolower: < <-> <
          220 tolower: = <-> =
          221 tolower: > <-> >
          222 tolower: ? <-> ?
          223 tolower: @ <-> @
          224 tolower: A <-> a
          225 tolower: B <-> b
          226 tolower: C <-> c
          227 tolower: D <-> d
          228 tolower: E <-> e
          229 tolower: F <-> f
          230 tolower: G <-> g
          231 tolower: H <-> h
          232 tolower: I <-> i
          233 tolower: J <-> j
          234 tolower: K <-> k
          235 tolower: L <-> l
          236 tolower: M <-> m
          237 tolower: N <-> n
          238 tolower: O <-> o
          239 tolower: P <-> p
          240 tolower: Q <-> q
          241 tolower: R <-> r
          242 tolower: S <-> s
          243 tolower: T <-> t
          244 tolower: U <-> u
          245 tolower: V <-> v
          246 tolower: W <-> w
          247 tolower: X <-> x
          248 tolower: Y <-> y
          249 tolower: Z <-> z
          250 tolower: [ <-> [
          251 tolower: \ <-> \
          252 tolower: ] <-> ]
          253 tolower: ^ <-> ^
          254 tolower: _ <-> _
          255 tolower: ` <-> `
          256 tolower: a <-> a
          257 tolower: b <-> b
          258 tolower: c <-> c
          259 tolower: d <-> d
          260 tolower: e <-> e
          261 tolower: f <-> f
          262 tolower: g <-> g
          263 tolower: h <-> h
          264 tolower: i <-> i
          265 tolower: j <-> j
          266 tolower: k <-> k
          267 tolower: l <-> l
          268 tolower: m <-> m
          269 tolower: n <-> n
          270 tolower: o <-> o
          271 tolower: p <-> p
          272 tolower: q <-> q
          273 tolower: r <-> r
          274 tolower: s <-> s
          275 tolower: t <-> t
          276 tolower: u <-> u
          277 tolower: v <-> v
          278 tolower: w <-> w
          279 tolower: x <-> x
          280 tolower: y <-> y
          281 tolower: z <-> z
          282 tolower: { <-> {
          283 tolower: | <-> |
          284 tolower: } <-> }
          285 tolower: ~ <-> ~
          286 toupper: ! <-> !
          287 toupper: " <-> "
          288 toupper: # <-> #
          289 toupper: $ <-> $
          290 toupper: % <-> %
          291 toupper: & <-> &
          292 toupper: ' <-> '
          293 toupper: ( <-> (
          294 toupper: ) <-> )
          295 toupper: * <-> *
          296 toupper: + <-> +
          297 toupper: , <-> ,
          298 toupper: - <-> -
          299 toupper: . <-> .
          300 toupper: / <-> /
          301 toupper: 0 <-> 0
          302 toupper: 1 <-> 1
          303 toupper: 2 <-> 2
          304 toupper: 3 <-> 3
          305 toupper: 4 <-> 4
          306 toupper: 5 <-> 5
          307 toupper: 6 <-> 6
          308 toupper: 7 <-> 7
          309 toupper: 8 <-> 8
          310 toupper: 9 <-> 9
          311 toupper: : <-> :
          312 toupper: ; <-> ;
          313 toupper: < <-> <
          314 toupper: = <-> =
          315 toupper: > <-> >
          316 toupper: ? <-> ?
          317 toupper: @ <-> @
          318 toupper: A <-> A
          319 toupper: B <-> B
          320 toupper: C <-> C
          321 toupper: D <-> D
          322 toupper: E <-> E
          323 toupper: F <-> F
          324 toupper: G <-> G
          325 toupper: H <-> H
          326 toupper: I <-> I
          327 toupper: J <-> J
          328 toupper: K <-> K
          329 toupper: L <-> L
          330 toupper: M <-> M
          331 toupper: N <-> N
          332 toupper: O <-> O
          333 toupper: P <-> P
          334 toupper: Q <-> Q
          335 toupper: R <-> R
          336 toupper: S <-> S
          337 toupper: T <-> T
          338 toupper: U <-> U
          339 toupper: V <-> V
          340 toupper: W <-> W
          341 toupper: X <-> X
          342 toupper: Y <-> Y
          343 toupper: Z <-> Z
          344 toupper: [ <-> [
          345 toupper: \ <-> \
          346 toupper: ] <-> ]
          347 toupper: ^ <-> ^
          348 toupper: _ <-> _
          349 toupper: ` <-> `
          350 toupper: a <-> A
          351 toupper: b <-> B
          352 toupper: c <-> C
          353 toupper: d <-> D
          354 toupper: e <-> E
          355 toupper: f <-> F
          356 toupper: g <-> G
          357 toupper: h <-> H
          358 toupper: i <-> I
          359 toupper: j <-> J
          360 toupper: k <-> K
          361 toupper: l <-> L
          362 toupper: m <-> M
          363 toupper: n <-> N
          364 toupper: o <-> O
          365 toupper: p <-> P
          366 toupper: q <-> Q
          367 toupper: r <-> R
          368 toupper: s <-> S
          369 toupper: t <-> T
          370 toupper: u <-> U
          371 toupper: v <-> V
          372 toupper: w <-> W
          373 toupper: x <-> X
          374 toupper: y <-> Y
          375 toupper: z <-> Z
          376 toupper: { <-> {
          377 toupper: | <-> |
          378 toupper: } <-> }
          379 toupper: ~ <-> ~
          380 
          381 test4
          382 tolower: ! <-> !
          383 tolower: " <-> "
          384 tolower: # <-> #
          385 tolower: $ <-> $
          386 tolower: % <-> %
          387 tolower: & <-> &
          388 tolower: ' <-> '
          389 tolower: ( <-> (
          390 tolower: ) <-> )
          391 tolower: * <-> *
          392 tolower: + <-> +
          393 tolower: , <-> ,
          394 tolower: - <-> -
          395 tolower: . <-> .
          396 tolower: / <-> /
          397 tolower: 0 <-> 0
          398 tolower: 1 <-> 1
          399 tolower: 2 <-> 2
          400 tolower: 3 <-> 3
          401 tolower: 4 <-> 4
          402 tolower: 5 <-> 5
          403 tolower: 6 <-> 6
          404 tolower: 7 <-> 7
          405 tolower: 8 <-> 8
          406 tolower: 9 <-> 9
          407 tolower: : <-> :
          408 tolower: ; <-> ;
          409 tolower: < <-> <
          410 tolower: = <-> =
          411 tolower: > <-> >
          412 tolower: ? <-> ?
          413 tolower: @ <-> @
          414 tolower: A <-> a
          415 tolower: B <-> b
          416 tolower: C <-> c
          417 tolower: D <-> d
          418 tolower: E <-> e
          419 tolower: F <-> f
          420 tolower: G <-> g
          421 tolower: H <-> h
          422 tolower: I <-> i
          423 tolower: J <-> j
          424 tolower: K <-> k
          425 tolower: L <-> l
          426 tolower: M <-> m
          427 tolower: N <-> n
          428 tolower: O <-> o
          429 tolower: P <-> p
          430 tolower: Q <-> q
          431 tolower: R <-> r
          432 tolower: S <-> s
          433 tolower: T <-> t
          434 tolower: U <-> u
          435 tolower: V <-> v
          436 tolower: W <-> w
          437 tolower: X <-> x
          438 tolower: Y <-> y
          439 tolower: Z <-> z
          440 tolower: [ <-> [
          441 tolower: \ <-> \
          442 tolower: ] <-> ]
          443 tolower: ^ <-> ^
          444 tolower: _ <-> _
          445 tolower: ` <-> `
          446 tolower: a <-> a
          447 tolower: b <-> b
          448 tolower: c <-> c
          449 tolower: d <-> d
          450 tolower: e <-> e
          451 tolower: f <-> f
          452 tolower: g <-> g
          453 tolower: h <-> h
          454 tolower: i <-> i
          455 tolower: j <-> j
          456 tolower: k <-> k
          457 tolower: l <-> l
          458 tolower: m <-> m
          459 tolower: n <-> n
          460 tolower: o <-> o
          461 tolower: p <-> p
          462 tolower: q <-> q
          463 tolower: r <-> r
          464 tolower: s <-> s
          465 tolower: t <-> t
          466 tolower: u <-> u
          467 tolower: v <-> v
          468 tolower: w <-> w
          469 tolower: x <-> x
          470 tolower: y <-> y
          471 tolower: z <-> z
          472 tolower: { <-> {
          473 tolower: | <-> |
          474 tolower: } <-> }
          475 tolower: ~ <-> ~
          476 toupper: ! <-> !
          477 toupper: " <-> "
          478 toupper: # <-> #
          479 toupper: $ <-> $
          480 toupper: % <-> %
          481 toupper: & <-> &
          482 toupper: ' <-> '
          483 toupper: ( <-> (
          484 toupper: ) <-> )
          485 toupper: * <-> *
          486 toupper: + <-> +
          487 toupper: , <-> ,
          488 toupper: - <-> -
          489 toupper: . <-> .
          490 toupper: / <-> /
          491 toupper: 0 <-> 0
          492 toupper: 1 <-> 1
          493 toupper: 2 <-> 2
          494 toupper: 3 <-> 3
          495 toupper: 4 <-> 4
          496 toupper: 5 <-> 5
          497 toupper: 6 <-> 6
          498 toupper: 7 <-> 7
          499 toupper: 8 <-> 8
          500 toupper: 9 <-> 9
          501 toupper: : <-> :
          502 toupper: ; <-> ;
          503 toupper: < <-> <
          504 toupper: = <-> =
          505 toupper: > <-> >
          506 toupper: ? <-> ?
          507 toupper: @ <-> @
          508 toupper: A <-> A
          509 toupper: B <-> B
          510 toupper: C <-> C
          511 toupper: D <-> D
          512 toupper: E <-> E
          513 toupper: F <-> F
          514 toupper: G <-> G
          515 toupper: H <-> H
          516 toupper: I <-> I
          517 toupper: J <-> J
          518 toupper: K <-> K
          519 toupper: L <-> L
          520 toupper: M <-> M
          521 toupper: N <-> N
          522 toupper: O <-> O
          523 toupper: P <-> P
          524 toupper: Q <-> Q
          525 toupper: R <-> R
          526 toupper: S <-> S
          527 toupper: T <-> T
          528 toupper: U <-> U
          529 toupper: V <-> V
          530 toupper: W <-> W
          531 toupper: X <-> X
          532 toupper: Y <-> Y
          533 toupper: Z <-> Z
          534 toupper: [ <-> [
          535 toupper: \ <-> \
          536 toupper: ] <-> ]
          537 toupper: ^ <-> ^
          538 toupper: _ <-> _
          539 toupper: ` <-> `
          540 toupper: a <-> A
          541 toupper: b <-> B
          542 toupper: c <-> C
          543 toupper: d <-> D
          544 toupper: e <-> E
          545 toupper: f <-> F
          546 toupper: g <-> G
          547 toupper: h <-> H
          548 toupper: i <-> I
          549 toupper: j <-> J
          550 toupper: k <-> K
          551 toupper: l <-> L
          552 toupper: m <-> M
          553 toupper: n <-> N
          554 toupper: o <-> O
          555 toupper: p <-> P
          556 toupper: q <-> Q
          557 toupper: r <-> R
          558 toupper: s <-> S
          559 toupper: t <-> T
          560 toupper: u <-> U
          561 toupper: v <-> V
          562 toupper: w <-> W
          563 toupper: x <-> X
          564 toupper: y <-> Y
          565 toupper: z <-> Z
          566 toupper: { <-> {
          567 toupper: | <-> |
          568 toupper: } <-> }
          569 toupper: ~ <-> ~
          570 end:
          571 */