added stb, more binaryout changes"
[henge/apc.git] / stb / tests / stb_cpp.cpp
1 #define WIN32_MEAN_AND_LEAN
2 #define WIN32_LEAN_AND_MEAN
3 //#include <windows.h>
4 #include <conio.h>
5 #define STB_STUA
6 #define STB_DEFINE
7 #define STB_NPTR
8 #define STB_ONLY
9 #include "stb.h"
10 //#include "stb_file.h"
11
12 int count;
13 void c(int truth, char *error)
14 {
15 if (!truth) {
16 fprintf(stderr, "Test failed: %s\n", error);
17 ++count;
18 }
19 }
20
21 char *expects(stb_matcher *m, char *s, int result, int len, char *str)
22 {
23 int res2,len2=0;
24 res2 = stb_lex(m, s, &len2);
25 c(result == res2 && len == len2, str);
26 return s + len;
27 }
28
29 void test_lex(void)
30 {
31 stb_matcher *m = stb_lex_matcher();
32 // tok_en5 .3 20.1 20. .20 .1
33 char *s = "tok_en5.3 20.1 20. .20.1";
34
35 stb_lex_item(m, "[a-zA-Z_][a-zA-Z0-9_]*", 1 );
36 stb_lex_item(m, "[0-9]*\\.?[0-9]*" , 2 );
37 stb_lex_item(m, "[\r\n\t ]+" , 3 );
38 stb_lex_item(m, "." , -99 );
39 s=expects(m,s,1,7, "stb_lex 1");
40 s=expects(m,s,2,2, "stb_lex 2");
41 s=expects(m,s,3,1, "stb_lex 3");
42 s=expects(m,s,2,4, "stb_lex 4");
43 s=expects(m,s,3,1, "stb_lex 5");
44 s=expects(m,s,2,3, "stb_lex 6");
45 s=expects(m,s,3,1, "stb_lex 7");
46 s=expects(m,s,2,3, "stb_lex 8");
47 s=expects(m,s,2,2, "stb_lex 9");
48 s=expects(m,s,0,0, "stb_lex 10");
49 stb_matcher_free(m);
50 }
51
52 int main(int argc, char **argv)
53 {
54 char *p;
55 p = "abcdefghijklmnopqrstuvwxyz";
56 c(stb_ischar('c', p), "stb_ischar 1");
57 c(stb_ischar('x', p), "stb_ischar 2");
58 c(!stb_ischar('#', p), "stb_ischar 3");
59 c(!stb_ischar('X', p), "stb_ischar 4");
60 p = "0123456789";
61 c(!stb_ischar('c', p), "stb_ischar 5");
62 c(!stb_ischar('x', p), "stb_ischar 6");
63 c(!stb_ischar('#', p), "stb_ischar 7");
64 c(!stb_ischar('X', p), "stb_ischar 8");
65 p = "#####";
66 c(!stb_ischar('c', p), "stb_ischar a");
67 c(!stb_ischar('x', p), "stb_ischar b");
68 c(stb_ischar('#', p), "stb_ischar c");
69 c(!stb_ischar('X', p), "stb_ischar d");
70 p = "xXyY";
71 c(!stb_ischar('c', p), "stb_ischar e");
72 c(stb_ischar('x', p), "stb_ischar f");
73 c(!stb_ischar('#', p), "stb_ischar g");
74 c(stb_ischar('X', p), "stb_ischar h");
75
76 test_lex();
77
78 if (count) {
79 _getch();
80 }
81 return 0;
82 }