test.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include <stddef.h>
  2. #include <stdint.h>
  3. #include "../uch.h"
  4. #include "munit/munit.h"
  5. static MunitResult
  6. test_uch(const MunitParameter params[], void *data)
  7. {
  8. Uch ch;
  9. Ch_len len;
  10. const char *str = "😊a¢";
  11. munit_assert_int(ch_len_f("a"), ==, 1);
  12. munit_assert_int(ch_len_f("¢"), ==, 2);
  13. munit_assert_int(ch_len_f("€"), ==, 3);
  14. munit_assert_int(ch_len_f("😊"), ==, 4);
  15. ch = uch("a", &len);
  16. munit_assert_int(ch_len(ch), ==, len);
  17. munit_assert_int(len, ==, 1);
  18. ch = uch("¢", &len);
  19. munit_assert_int(ch_len(ch), ==, len);
  20. munit_assert_int(len, ==, 2);
  21. ch = uch("€", &len);
  22. munit_assert_int(ch_len(ch), ==, len);
  23. munit_assert_int(len, ==, 3);
  24. ch = uch("😊", &len);
  25. munit_assert_int(ch_len(ch), ==, len);
  26. munit_assert_int(len, ==, 4);
  27. str += ch_len_f(str);
  28. str += ch_len_f(str);
  29. str += ch_len_f(str);
  30. munit_assert_int((len = ch_len_b(str)), ==, 2);
  31. str -= len;
  32. munit_assert_int((len = ch_len_b(str)), ==, 1);
  33. str -= len;
  34. munit_assert_int((len = ch_len_b(str)), ==, 4);
  35. return MUNIT_OK;
  36. }
  37. static MunitTest test_suite_tests[] = {
  38. { (char *) "/uch", test_uch,
  39. NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
  40. { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
  41. };
  42. static const MunitSuite test_suite = {
  43. (char*) "uch",
  44. test_suite_tests,
  45. NULL,
  46. 1,
  47. MUNIT_SUITE_OPTION_NONE
  48. };
  49. int
  50. main(int argc, char *argv[MUNIT_ARRAY_PARAM(argc + 1)])
  51. {
  52. return munit_suite_main(&test_suite, NULL, argc, argv);
  53. }