diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-04-08 13:14:27 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-04-08 13:15:01 +0200 |
| commit | cf534d762754860ed5b714974f99acd282d48b3b (patch) | |
| tree | bf22341cedfb50ee7bcd4e15f85add2329783f31 /src/std/test_string.c | |
| parent | 630fcb1846aed16b9ab62bcf700f668883f4521f (diff) | |
Restructure into src/{std,json}/
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'src/std/test_string.c')
| -rw-r--r-- | src/std/test_string.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/std/test_string.c b/src/std/test_string.c new file mode 100644 index 0000000..d6bc716 --- /dev/null +++ b/src/std/test_string.c @@ -0,0 +1,41 @@ +#include "str.h" +#include "testing.h" +#include "types.h" +#include <stdio.h> + +i32 test_string_literal_equality() { + t_assert_strequal(S("Bonjour"), S("Bonjour")); + return 0; +} + +i32 test_string_copy() { + Arena perm = Arena_new(128e3); + Str src = S("Hello"); + + Str cpy = Str_copy(&perm, src.data, src.len); + + t_assert_strequal(src, cpy); + t_assert_equal(Arena_get_used(perm), 5); + + return 0; +} + +i32 test_fast_string() { + bytex32 quote_mask = _mm256_set1_epi8('"'); + byte *s = malloc(32 * sizeof(byte)); + s = "abcdefghijklmnopqrstuvwxyzabcdef"; + + bytex32 chunk = _mm256_loadu_si256((bytex32 *)s); + bytex32 cmp = _mm256_cmpeq_epi8(chunk, quote_mask); + i32 mask = _mm256_movemask_epi8(cmp); + t_assert_equal(_mm_popcnt_u32(mask), 0); + + s = "abcdefghijklm\"nopqrstuvwxyzabcde"; + + chunk = _mm256_loadu_si256((bytex32 *)s); + cmp = _mm256_cmpeq_epi8(chunk, quote_mask); + mask = _mm256_movemask_epi8(cmp); + t_assert_equal(_mm_popcnt_u32(mask), 1); + + return 0; +} |
