stb_cpp.cpp
This file
Path
tests/stb_cpp.cpp
85 lines · 2.2 KiB · C++
Last changed by
various tests and infrastructure fixesSean Barrettbefore adoption4a7a434
History of this fileTake it
1#define WIN32_MEAN_AND_LEAN2#define WIN32_LEAN_AND_MEAN3//#include <windows.h>4#include <conio.h>5#define STB_DEFINE6#ifndef _M_AMD647#define STB_NPTR8#endif9#define STB_ONLY10#include "stb.h"11//#include "stb_file.h"1213int count;14void c(int truth, const char *error)15{16 if (!truth) {17 fprintf(stderr, "Test failed: %s\n", error);18 ++count;19 }20}2122char *expects(stb_matcher *m, char *s, int result, int len, const char *str)23{24 int res2,len2=0;25 res2 = stb_lex(m, s, &len2);26 c(result == res2 && len == len2, str);27 return s + len;28}2930void test_lex(void)31{32 stb_matcher *m = stb_lex_matcher();33 // tok_en5 .3 20.1 20. .20 .134 char *s = (char*) "tok_en5.3 20.1 20. .20.1";3536 stb_lex_item(m, "[a-zA-Z_][a-zA-Z0-9_]*", 1 );37 stb_lex_item(m, "[0-9]*\\.?[0-9]*" , 2 );38 stb_lex_item(m, "[\r\n\t ]+" , 3 );39 stb_lex_item(m, "." , -99 );40 s=expects(m,s,1,7, "stb_lex 1");41 s=expects(m,s,2,2, "stb_lex 2");42 s=expects(m,s,3,1, "stb_lex 3");43 s=expects(m,s,2,4, "stb_lex 4");44 s=expects(m,s,3,1, "stb_lex 5");45 s=expects(m,s,2,3, "stb_lex 6");46 s=expects(m,s,3,1, "stb_lex 7");47 s=expects(m,s,2,3, "stb_lex 8");48 s=expects(m,s,2,2, "stb_lex 9");49 s=expects(m,s,0,0, "stb_lex 10");50 stb_matcher_free(m);51}5253int main(int argc, char **argv)54{55#if 056 char *p;57 p = (char*) "abcdefghijklmnopqrstuvwxyz";58 c(stb_ischar('c', p), "stb_ischar 1");59 c(stb_ischar('x', p), "stb_ischar 2");60 c(!stb_ischar('#', p), "stb_ischar 3");61 c(!stb_ischar('X', p), "stb_ischar 4");62 p = (char*) "0123456789";63 c(!stb_ischar('c', p), "stb_ischar 5");64 c(!stb_ischar('x', p), "stb_ischar 6");65 c(!stb_ischar('#', p), "stb_ischar 7");66 c(!stb_ischar('X', p), "stb_ischar 8");67 p = (char*) "#####";68 c(!stb_ischar('c', p), "stb_ischar a");69 c(!stb_ischar('x', p), "stb_ischar b");70 c(stb_ischar('#', p), "stb_ischar c");71 c(!stb_ischar('X', p), "stb_ischar d");72 p = (char*) "xXyY";73 c(!stb_ischar('c', p), "stb_ischar e");74 c(stb_ischar('x', p), "stb_ischar f");75 c(!stb_ischar('#', p), "stb_ischar g");76 c(stb_ischar('X', p), "stb_ischar h");77#endif7879 test_lex();8081 if (count) {82 _getch();83 }84 return 0;85}