wcsstr.c 999 B

123456789101112131415161718192021222324252627
  1. #include <assert.h>
  2. #include <wchar.h>
  3. int main(void) {
  4. wchar_t *haystack = L"Hello, World!";
  5. wchar_t *haystack_empty = L"";
  6. wchar_t *needle_expected = L"World";
  7. wchar_t *needle_expected_multiple = L"l";
  8. wchar_t *needle_not_expected = L"Rust";
  9. wchar_t *needle_too_long = L"Hello, World!!!";
  10. wchar_t *needle_empty = L"";
  11. assert(wcsstr(haystack, needle_expected) == haystack + 7);
  12. assert(wcsstr(haystack, needle_expected_multiple) == haystack + 2);
  13. assert(wcsstr(haystack, needle_not_expected) == NULL);
  14. assert(wcsstr(haystack, needle_too_long) == NULL);
  15. assert(wcsstr(haystack, needle_empty) == haystack);
  16. assert(wcsstr(haystack_empty, needle_expected) == NULL);
  17. assert(wcsstr(haystack_empty, needle_expected_multiple) == NULL);
  18. assert(wcsstr(haystack_empty, needle_not_expected) == NULL);
  19. assert(wcsstr(haystack_empty, needle_too_long) == NULL);
  20. assert(wcsstr(haystack_empty, needle_empty) == haystack_empty);
  21. return 0;
  22. }