1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-28 10:51:14 +00:00
C02/py65/teststr.c02

126 lines
2.9 KiB
Plaintext
Raw Normal View History

2018-02-14 00:52:14 +00:00
/******************************************
* TESTSTR - Test Common String Functions *
******************************************/
#include <py65.h02>
2018-07-31 00:06:33 +00:00
#include <stddef.h02>
2018-02-14 00:52:14 +00:00
#include <stdio.h02>
#include <string.h02>
char slen, scmp, spos, stot;
2019-03-22 23:32:08 +00:00
const char frst = "string one.";
const char scnd = "string two.";
2018-02-14 00:52:14 +00:00
char temp[32];
char dest[32];
2019-03-22 23:32:08 +00:00
const char less = "less";
const char more = "more";
const char most = "most";
const char test = "test";
const char pass = "Pass ";
const char fail = "Fail ";
2018-02-14 00:52:14 +00:00
main:
//Test strchr
puts("test="); putln(&test);
puts("strchr('t', &test): ");
spos = strchr('t', &test);
if (spos = 0) puts(&pass); else puts(&fail);
puts("strchr('s', &test): ");
spos = strchr('s', &test);
if (spos = 2) puts(&pass); else puts(&fail);
puts("strchr('x', &test): ");
spos = strchr('x', &test);
if (spos = $FF) putln(&pass); else putln(&fail);
//Test strrch
puts("strrch('t', &test): ");
spos = strrch('t', &test);
if (spos = 3) puts(&pass); else puts(&fail);
puts("strrch('s', &test): ");
spos = strrch('s', &test);
if (spos = 2) puts(&pass); else puts(&fail);
puts("strchr('x', &test): ");
spos = strchr('x', &test);
if (spos = $FF) putln(&pass); else putln(&fail);
//Test strlen
puts("strlen(&test): ");
slen = strlen(&test);
if (slen = 4) putln(&pass);
else putln(&fail);
newlin();
//Test strcmp
puts("less="); puts(&less);
puts(" more="); puts(&more);
puts(" most="); putln(&most);
putln("strdst(&more)");
strdst(&more);
puts("strcmp(&most): ");
scmp = strcmp(&most);
if (scmp :-) puts(&pass); else puts(&fail);
puts("strcmp(&more): ");
scmp = strcmp(&more);
if (!scmp) puts(&pass); else puts(&fail);
puts("strcmp(&less): ");
scmp = strcmp(&less);
if (scmp > 0) putln(&pass); else putln(&fail);
newlin();
//Test strcpy, strcat, strstr
temp[0] = 0; //Clear temp
puts("temp="); puts(&temp);
puts(" frst="); puts(&frst);
puts(" scnd="); putln(&scnd);
putln("strdst(&temp)");
strdst(&temp);
puts("strcpy(&frst): ");
strcpy(&frst);
scmp = strcmp(&frst);
if (scmp = 0) puts(&pass); else puts(&fail);
puts("strcmp(&frst): ");
scmp = strcmp(&frst);
if (scmp = 0) puts(&pass); else puts(&fail);
puts("strcat(&scnd): ");
slen = strlen(&temp);
stot = strlen(&scnd) + slen;
strcat(&scnd);
if (strlen(&temp) == stot) putln(&pass); else putln(&fail);
puts("strstr(&frst): ");
spos = strstr(&frst);
if (spos = 0) puts(&pass); else puts(&fail);
puts("strstr(&scnd): ");
spos = strstr(&scnd);
if (spos = slen) puts(&pass); else puts(&fail);
puts("strstr(&test): ");
spos = strstr(&test);
if (spos = $FF) putln(&pass); else putln(&fail);
putln("strdst(&dest);");
strdst(&dest);
puts("strcut(slen, &temp): ");
stot = strcut(slen, &temp);
scmp = strcmp(&scnd);
if (scmp = 0) putln(&pass);
else putln(&fail);
goto exit;