/* token-test.c - Test program for error routines. * (C) Copyright 1999 by John Halleck * All rights reserved. */ /* Version of August 30th, 1999 */ #include #include "errors.h" /* The standard errors package. */ #include "reportframe.h" /* Lets make reporting easier */ #include "token.h" /* The routines we are planning to test.*/ /* static int someplace; */ /* Just a place */ #define SIZE 8 static char buffer[SIZE]; int size; /* Place for returned size */ /* -------------------------------------------------------------------------- */ /* Diddly character source */ static char *currentinput = 0; /* Diddly source of characters */ static error setstring (char *given) { currentinput = 0; if (!given) return ERRnil; currentinput = given; return NoError; } static error nextfromstring (int *place) { if(!place) return ERRnil; if(!currentinput) return ERRuninitialized; *place = *currentinput; if (*currentinput) currentinput++; else *place = -1; return NoError; } /* ------------------------- Housekeeping ---------------------------------- */ static error initcheck (char *name, error result) { if (result == ERRuninitialized) return NoError; if (!name) name = "NO NAME GIVEN"; printf ("%s failed to properly notice uninitialized status\n", name); if (!result) return ERRfalse; printerror (result); return result; } static error checkinitstat () { error good = 1; if(initcheck ("skipnoneolwhite", skipnoneolwhite()) ) good = 0; if(initcheck ("finalize", tokfinalize()) ) good = 0; if(initcheck ("skipwhite", skipwhite()) ) good = 0; if(initcheck ("skipnonwhite", skipnonwhite()) ) good = 0; if(initcheck ("nextchar", nextchar()) ) good = 0; if(initcheck ("prefetch", prefetch()) ) good = 0; if(initcheck ("skipeol", skipeol()) ) good = 0; if(initcheck ("skiptoeol", skiptoeol()) ) good = 0; if(initcheck ("skipto", skipto("x")) ) good = 0; if(initcheck ("nonwhitetok", nonwhitetok (SIZE, buffer, &size))) good = 0; if(initcheck ("inttok", inttok (SIZE, buffer, &size))) good = 0; if(initcheck ("flttok", flttok (SIZE, buffer, &size))) good = 0; if(initcheck ("alphatok", alphatok (SIZE, buffer, &size))) good = 0; if(initcheck ("alphanumtok", alphanumtok (SIZE, buffer, &size))) good = 0; if(initcheck ("varnamtok", varnamtok (SIZE, buffer, &size))) good = 0; if(initcheck ("puncttok", puncttok (SIZE, buffer, &size))) good = 0; if(initcheck ("sinttok", sinttok (SIZE, buffer, &size))) good = 0; if(initcheck ("sflttok", sflttok (SIZE, buffer, &size))) good = 0; if (!good) return ERRfalse; return NoError; } static error haveerrorstat (char *text, char *shouldbe, error theerror) { goterrorstat (text, theerror); if (shouldbe) { printf ("Token should have been \"%s\"\n", shouldbe); } /* make it string like. */ buffer[SIZE-1] = 0; /* And dump it. */ printf ("Token was: (Size = %d) \"%s\"\n", size, buffer); if (thischaracter == EOF) printf ("thischaracter = EOF\n"); else { printf ("thischaracter (%d) '%c'", thischaracter, thischaracter); if (validnextcharacter && nextcharacter != EOF) printf (", nextcharacter (%d) '%c'", nextcharacter, nextcharacter); else if (validnextcharacter) printf(", nextcharacter = EOF"); printf ("\n"); } if (currentinput && *currentinput != 0) printf ("Remaining unprocessed input is: \"%s\"\n", currentinput); return theerror; } static error haveerror (char *text, char *shouldbe) { return haveerrorstat(text, shouldbe, NoError); } static error havewrongstat (char *text, error theerror) { return haveerrorstat(text, 0, theerror); } static error havewrong (char *text) { return haveerrorstat (text, 0, NoError); } /* ------------------------- Housekeeping ---------------------------------- */ int main() { error problem; int i; /* Default loop index */ int outchar; /* Default character output */ inittests("token"); for (i=0;i