stb_cpp.cpp
This file
Path
tests/stb_cpp.cpp
83 lines · 2.1 KiB · C++
Last changed by
tests: 64-bit fixes, fix typo in image testsSean Barrettbefore adoptiona28a6b1
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, 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, 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 = "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 char *p;56 p = "abcdefghijklmnopqrstuvwxyz";57 c(stb_ischar('c', p), "stb_ischar 1");58 c(stb_ischar('x', p), "stb_ischar 2");59 c(!stb_ischar('#', p), "stb_ischar 3");60 c(!stb_ischar('X', p), "stb_ischar 4");61 p = "0123456789";62 c(!stb_ischar('c', p), "stb_ischar 5");63 c(!stb_ischar('x', p), "stb_ischar 6");64 c(!stb_ischar('#', p), "stb_ischar 7");65 c(!stb_ischar('X', p), "stb_ischar 8");66 p = "#####";67 c(!stb_ischar('c', p), "stb_ischar a");68 c(!stb_ischar('x', p), "stb_ischar b");69 c(stb_ischar('#', p), "stb_ischar c");70 c(!stb_ischar('X', p), "stb_ischar d");71 p = "xXyY";72 c(!stb_ischar('c', p), "stb_ischar e");73 c(stb_ischar('x', p), "stb_ischar f");74 c(!stb_ischar('#', p), "stb_ischar g");75 c(stb_ischar('X', p), "stb_ischar h");7677 test_lex();7879 if (count) {80 _getch();81 }82 return 0;83}