Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.1 KiB

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