Skip to content
Myr

stb_cpp.cpp

This file

Path

tests/stb_cpp.cpp

82 lines · 2.1 KiB · C++

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than 0b50f1e point at it.

Merge branch 'working' into testSean Barrettbefore adoption0b50f1e

lines 1–82why, one step back
1#define WIN32_MEAN_AND_LEAN
2#define WIN32_LEAN_AND_MEAN3//#include <windows.h>4#include <conio.h>5#define STB_STUA6#define STB_DEFINE7#define STB_NPTR8#define STB_ONLY9#include "stb.h"10//#include "stb_file.h"1112int count;13void c(int truth, char *error)14{15 if (!truth) {16 fprintf(stderr, "Test failed: %s\n", error);17 ++count;18 }19}2021char *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}2829void test_lex(void)30{31 stb_matcher *m = stb_lex_matcher();32 // tok_en5 .3 20.1 20. .20 .133 char *s = "tok_en5.3 20.1 20. .20.1";3435 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}5152int 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");7576 test_lex();7778 if (count) {79 _getch();80 }81 return 0;82}