1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-25 06:31:25 +00:00
C02/py65/teststx.c02

116 lines
2.5 KiB
Plaintext
Raw Normal View History

2018-02-14 00:52:14 +00:00
/********************************************
* TESTSTX - Test Extended String Functions *
********************************************/
#include <py65.h02>
2019-03-22 23:32:08 +00:00
#include <stddef.h02>
2018-02-14 00:52:14 +00:00
#include <stdio.h02>
#include <string.h02>
#include <stringx.h02>
char slen, sres;
2019-03-22 23:32:08 +00:00
const char span = "abcdef";
2018-02-14 00:52:14 +00:00
char smax[128];
2019-03-22 23:32:08 +00:00
const char scba = "cba";
const char sfed = "fed";
const char sxyz = "xyz";
const char snul = "";
const char pass = "Pass ";
const char fail = "Fail ";
2018-02-14 00:52:14 +00:00
void tests(slen) {
//Test scba
puts("strspn(&scba): ");
sres = strspn(&scba);
if (sres == 3) puts(&pass); else puts(&fail);
puts("strbrk(&scba): ");
sres = strbrk(&scba);
if (sres == 0) puts(&pass); else puts(&fail);
puts("strpbk(&scba): ");
sres = strpbk(&scba);
if (sres == 0) putln(&pass); else putln(&fail);
//Test span
puts("strspn(&span): ");
sres = strspn(&span);
if (sres == 6) puts(&pass); else puts(&fail);
puts("strbrk(&span): ");
sres = strbrk(&span);
if (sres == 0) puts(&pass); else puts(&fail);
puts("strpbk(&span): ");
sres = strpbk(&span);
if (sres == 0) putln(&pass); else putln(&fail);
//Test sfed
puts("strspn(&sfed): ");
sres = strspn(&sfed);
if (sres == 0) puts(&pass); else puts(&fail);
puts("strbrk(&sfed): ");
sres = strbrk(&sfed);
if (sres == 3) puts(&pass); else puts(&fail);
puts("strpbk(&sfed): ");
sres = strpbk(&sfed);
if (sres == 3) putln(&pass); else putln(&fail);
//Test sxyz
puts("strspn(&sxyz): ");
sres = strspn(&sxyz);
if (sres == 0) puts(&pass); else puts(&fail);
puts("strbrk(&sxyz): ");
sres = strbrk(&sxyz);
if (sres == slen) puts(&pass); else puts(&fail);
puts("strpbk(&sxyz): ");
sres = strpbk(&sxyz);
if (sres == 255) putln(&pass); else putln(&fail);
//Test snull
puts("strspn(&snul): ");
sres = strspn(&snul);
if (sres == 0) puts(&pass); else puts(&fail);
puts("strbrk(&snul): ");
sres = strbrk(&snul);
if (sres == slen) puts(&pass); else puts(&fail);
puts("strpbk(&snul): ");
sres = strpbk(&snul);
if (sres == 255) putln(&pass); else puts(&fail);
newlin();
}
main:
//Initialize smax
char i;
for (i=0; i<128; i++) smax[i] = i & 15 + 'a';
//Display Test Strings
puts("span="); putln(&span);
puts("smax="); putln(&smax);
puts("scba="); putln(&scba);
puts("sxyz="); putln(&sxyz);
puts("snul="); putln(&snul);
newlin();
//Test span
putln("strdst(&span);");
strdst(&span);
tests(strlen(&span));
//Test smax
putln("strdst(&smax);");
strdst(&smax);
tests(strlen(&smax));
goto exit;