MCPcopy Create free account
hub / github.com/buke/quickjs-go / normalization_test

Function normalization_test

deps/quickjs/unicode_gen.c:2953–3007  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2951}
2952
2953void normalization_test(const char *filename)
2954{
2955 FILE *f;
2956 char line[4096], *p;
2957 int *in_str, *nfc_str, *nfd_str, *nfkc_str, *nfkd_str;
2958 int in_len, nfc_len, nfd_len, nfkc_len, nfkd_len;
2959 int *buf, buf_len, pos;
2960
2961 f = fopen(filename, "rb");
2962 if (!f) {
2963 perror(filename);
2964 exit(1);
2965 }
2966 pos = 0;
2967 for(;;) {
2968 if (!get_line(line, sizeof(line), f))
2969 break;
2970 pos++;
2971 p = line;
2972 while (isspace(*p))
2973 p++;
2974 if (*p == '#' || *p == '@')
2975 continue;
2976 in_str = get_field_str(&in_len, p, 0);
2977 nfc_str = get_field_str(&nfc_len, p, 1);
2978 nfd_str = get_field_str(&nfd_len, p, 2);
2979 nfkc_str = get_field_str(&nfkc_len, p, 3);
2980 nfkd_str = get_field_str(&nfkd_len, p, 4);
2981
2982 // dump_str("in", in_str, in_len);
2983
2984 buf_len = unicode_normalize((uint32_t **)&buf, (uint32_t *)in_str, in_len, UNICODE_NFD, NULL, NULL);
2985 check_str("nfd", pos, in_str, in_len, buf, buf_len, nfd_str, nfd_len);
2986 free(buf);
2987
2988 buf_len = unicode_normalize((uint32_t **)&buf, (uint32_t *)in_str, in_len, UNICODE_NFKD, NULL, NULL);
2989 check_str("nfkd", pos, in_str, in_len, buf, buf_len, nfkd_str, nfkd_len);
2990 free(buf);
2991
2992 buf_len = unicode_normalize((uint32_t **)&buf, (uint32_t *)in_str, in_len, UNICODE_NFC, NULL, NULL);
2993 check_str("nfc", pos, in_str, in_len, buf, buf_len, nfc_str, nfc_len);
2994 free(buf);
2995
2996 buf_len = unicode_normalize((uint32_t **)&buf, (uint32_t *)in_str, in_len, UNICODE_NFKC, NULL, NULL);
2997 check_str("nfkc", pos, in_str, in_len, buf, buf_len, nfkc_str, nfkc_len);
2998 free(buf);
2999
3000 free(in_str);
3001 free(nfc_str);
3002 free(nfd_str);
3003 free(nfkc_str);
3004 free(nfkd_str);
3005 }
3006 fclose(f);
3007}
3008#endif
3009
3010int main(int argc, char **argv)

Callers 1

mainFunction · 0.85

Calls 5

exitFunction · 0.85
get_lineFunction · 0.85
get_field_strFunction · 0.85
unicode_normalizeFunction · 0.85
check_strFunction · 0.85

Tested by

no test coverage detected