/** * The Mojibake library * * This file is distributed under the MIT License. See LICENSE for details. */ #include "test.h" // clang-format off // Example definitions are automatically generated. Do not edit. // Example definitions for mjb_utf8_vsnprintf // A printf-style function of your own that never ends with a partial codepoint static int format_utf8(char *buffer, size_t buffer_size, const char *format, ...) { va_list args; va_start(args, format); int required = mjb_utf8_vsnprintf(buffer, buffer_size, format, args); va_end(args); return required; } // Example definitions for mjb_utf8_grapheme_vsnprintf // A printf-style function of your own that never splits a grapheme cluster static int format_graphemes(char *buffer, size_t buffer_size, const char *format, ...) { va_list args; va_start(args, format); int required = mjb_utf8_grapheme_vsnprintf(buffer, buffer_size, format, args); va_end(args); return required; } // Example definitions for mjb_set_allocator // An allocator that counts the bytes in use. The context points to the counter. static void *counting_alloc(void *context, size_t size) { void *ptr = malloc(size); if(ptr) { *(size_t *)context += size; } return ptr; } static void *counting_realloc(void *context, void *ptr, size_t old_size, size_t new_size) { void *new_ptr = realloc(ptr, new_size); if(new_ptr) { *(size_t *)context = *(size_t *)context - old_size + new_size; } return new_ptr; } static void counting_free(void *context, void *ptr, size_t size) { *(size_t *)context -= size; free(ptr); } // End of generated example definitions. ATT_TEST(example) { char test_buffer[256]; // This function is automatically generated. Do not edit. { // Example for mjb_codepoint_info MJB_TEST_COVERAGE(mjb_codepoint_info); // Added by the script mjb_character character; // U+0665 ARABIC-INDIC DIGIT FIVE if(mjb_codepoint_info(0x0665, &character) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_codepoint_info test failed"); // Added by the script return; } bool is_digit = character.category == MJB_CATEGORY_ND; // Decimal digit: yes, value: 5 // printf("Decimal digit: %s, value: %d", is_digit ? "yes" : "no", character.decimal); snprintf(test_buffer, sizeof(test_buffer), "Decimal digit: %s, value: %d", is_digit ? "yes" : "no", character.decimal); // Added by the script ATT_ASSERT(test_buffer, "Decimal digit: yes, value: 5", "mjb_codepoint_info test failed"); // Added by the script } { // Example for mjb_normalize MJB_TEST_COVERAGE(mjb_normalize); // Added by the script // "Cafe" + U+0301 COMBINING ACUTE ACCENT mjb_text input = mjb_text_utf8("Cafe\xCC\x81", MJB_NUL_TERMINATED); mjb_result result; if(mjb_normalize(&input, MJB_MALFORMED_STOP, MJB_NORMALIZATION_NFC, MJB_ENC_UTF_8, &result, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_normalize test failed"); // Added by the script return; } // NFC: Café // printf("NFC: %.*s", (int)result.output_size, result.output); snprintf(test_buffer, sizeof(test_buffer), "NFC: %.*s", (int)result.output_size, result.output); // Added by the script ATT_ASSERT(test_buffer, "NFC: Café", "mjb_normalize test failed"); // Added by the script mjb_result_free(&result); } { // Example for mjb_normalize_into MJB_TEST_COVERAGE(mjb_normalize_into); // Added by the script const char *cafe = "Cafe\xCC\x81"; // "Cafe" + U+0301 COMBINING ACUTE ACCENT mjb_text input = mjb_text_utf8(cafe, strlen(cafe)); mjb_buffer output = mjb_buffer_make(NULL, 0, MJB_ENC_UTF_8); // Query the required size if(mjb_normalize_into(&input, MJB_MALFORMED_STOP, MJB_NORMALIZATION_NFC, &output, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_normalize_into test failed"); // Added by the script return; } char storage[5]; if(output.size > sizeof(storage)) { ATT_ASSERT(0, 1, "mjb_normalize_into test failed"); // Added by the script return; } output = mjb_buffer_make(storage, sizeof(storage), MJB_ENC_UTF_8); if(mjb_normalize_into(&input, MJB_MALFORMED_STOP, MJB_NORMALIZATION_NFC, &output, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_normalize_into test failed"); // Added by the script return; } // NFC payload (no terminator): Café // printf("NFC payload (no terminator): %.*s", (int)output.size, storage); snprintf(test_buffer, sizeof(test_buffer), "NFC payload (no terminator): %.*s", (int)output.size, storage); // Added by the script ATT_ASSERT(test_buffer, "NFC payload (no terminator): Café", "mjb_normalize_into test failed"); // Added by the script } { // Example for mjb_filter MJB_TEST_COVERAGE(mjb_filter); // Added by the script mjb_text mixed_whitespace = mjb_text_utf8("Hello\t\t\n\nworld", MJB_NUL_TERMINATED); mjb_result result; if(mjb_filter(&mixed_whitespace, MJB_MALFORMED_STOP, MJB_FILTER_COLLAPSE_SPACES, MJB_ENC_UTF_8, &result, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_filter test failed"); // Added by the script return; } // Filtered: Hello world // printf("Filtered: %.*s", (int)result.output_size, result.output); snprintf(test_buffer, sizeof(test_buffer), "Filtered: %.*s", (int)result.output_size, result.output); // Added by the script ATT_ASSERT(test_buffer, "Filtered: Hello world", "mjb_filter test failed"); // Added by the script mjb_result_free(&result); mjb_text controls = mjb_text_utf8("\x1\x2\t\n\v\f\r\x1f", MJB_NUL_TERMINATED); if(mjb_filter(&controls, MJB_MALFORMED_STOP, MJB_FILTER_CONTROLS, MJB_ENC_UTF_8, &result, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_filter test failed"); // Added by the script return; } // Filtered: \t\n\v\f\r // printf("Filtered: %.*s", (int)result.output_size, result.output); snprintf(test_buffer, sizeof(test_buffer), "Filtered: %.*s", (int)result.output_size, result.output); // Added by the script ATT_ASSERT(test_buffer, "Filtered: \t\n\v\f\r", "mjb_filter test failed"); // Added by the script mjb_result_free(&result); } { // Example for mjb_filter_into MJB_TEST_COVERAGE(mjb_filter_into); // Added by the script mjb_text input = mjb_text_utf8("Hello\t\t\nworld", MJB_NUL_TERMINATED); mjb_buffer output = mjb_buffer_make(NULL, 0, MJB_ENC_UTF_8); // Query the required size if(mjb_filter_into(&input, MJB_MALFORMED_STOP, MJB_FILTER_COLLAPSE_SPACES, &output, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_filter_into test failed"); // Added by the script return; } char storage[11]; if(output.size > sizeof(storage)) { ATT_ASSERT(0, 1, "mjb_filter_into test failed"); // Added by the script return; } output = mjb_buffer_make(storage, sizeof(storage), MJB_ENC_UTF_8); if(mjb_filter_into(&input, MJB_MALFORMED_STOP, MJB_FILTER_COLLAPSE_SPACES, &output, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_filter_into test failed"); // Added by the script return; } // Filtered payload (no terminator): Hello world // printf("Filtered payload (no terminator): %.*s", (int)output.size, storage); snprintf(test_buffer, sizeof(test_buffer), "Filtered payload (no terminator): %.*s", (int)output.size, storage); // Added by the script ATT_ASSERT(test_buffer, "Filtered payload (no terminator): Hello world", "mjb_filter_into test failed"); // Added by the script } { // Example for mjb_nfkc_casefold MJB_TEST_COVERAGE(mjb_nfkc_casefold); // Added by the script mjb_text input = mjb_text_utf8("Stra\xC3\x9F" "e\xC2\xAD", MJB_NUL_TERMINATED); mjb_result result; if(mjb_nfkc_casefold(&input, MJB_MALFORMED_STOP, MJB_ENC_UTF_8, &result, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_nfkc_casefold test failed"); // Added by the script return; } // strasse // printf("%.*s", (int)result.output_size, result.output); snprintf(test_buffer, sizeof(test_buffer), "%.*s", (int)result.output_size, result.output); // Added by the script ATT_ASSERT(test_buffer, "strasse", "mjb_nfkc_casefold test failed"); // Added by the script mjb_result_free(&result); } { // Example for mjb_nfkc_casefold_into MJB_TEST_COVERAGE(mjb_nfkc_casefold_into); // Added by the script mjb_text input = mjb_text_utf8("Stra\xC3\x9F" "e\xC2\xAD", MJB_NUL_TERMINATED); mjb_buffer output = mjb_buffer_make(NULL, 0, MJB_ENC_UTF_8); // Query the required size if(mjb_nfkc_casefold_into(&input, MJB_MALFORMED_STOP, &output, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_nfkc_casefold_into test failed"); // Added by the script return; } char storage[7]; if(output.size > sizeof(storage)) { ATT_ASSERT(0, 1, "mjb_nfkc_casefold_into test failed"); // Added by the script return; } output = mjb_buffer_make(storage, sizeof(storage), MJB_ENC_UTF_8); if(mjb_nfkc_casefold_into(&input, MJB_MALFORMED_STOP, &output, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_nfkc_casefold_into test failed"); // Added by the script return; } // NFKC casefold payload (no terminator): strasse // printf("NFKC casefold payload (no terminator): %.*s", (int)output.size, storage); snprintf(test_buffer, sizeof(test_buffer), "NFKC casefold payload (no terminator): %.*s", (int)output.size, storage); // Added by the script ATT_ASSERT(test_buffer, "NFKC casefold payload (no terminator): strasse", "mjb_nfkc_casefold_into test failed"); // Added by the script } #if MJB_FEATURE_IDNA { // Example for mjb_idna_to_ascii MJB_TEST_COVERAGE(mjb_idna_to_ascii); // Added by the script // "bücher.example" mjb_text domain = mjb_text_utf8("b\xC3\xBC" "cher.example", MJB_NUL_TERMINATED); mjb_idna_info info; mjb_result result; if(mjb_idna_to_ascii(&domain, MJB_ENC_UTF_8, &info, &result) != MJB_STATUS_OK || info.errors != MJB_IDNA_ERROR_NONE) { ATT_ASSERT(0, 1, "mjb_idna_to_ascii test failed"); // Added by the script return; } // xn--bcher-kva.example // printf("%.*s", (int)result.output_size, result.output); snprintf(test_buffer, sizeof(test_buffer), "%.*s", (int)result.output_size, result.output); // Added by the script ATT_ASSERT(test_buffer, "xn--bcher-kva.example", "mjb_idna_to_ascii test failed"); // Added by the script mjb_result_free(&result); } #endif // MJB_FEATURE_IDNA #if MJB_FEATURE_IDNA { // Example for mjb_idna_to_ascii_into MJB_TEST_COVERAGE(mjb_idna_to_ascii_into); // Added by the script // "bücher.example" mjb_text domain = mjb_text_utf8("b\xC3\xBC" "cher.example", MJB_NUL_TERMINATED); mjb_buffer output = mjb_buffer_make(NULL, 0, MJB_ENC_UTF_8); mjb_idna_info info; // Query the required size if(mjb_idna_to_ascii_into(&domain, &info, &output) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_idna_to_ascii_into test failed"); // Added by the script return; } char storage[21]; if(output.size > sizeof(storage)) { ATT_ASSERT(0, 1, "mjb_idna_to_ascii_into test failed"); // Added by the script return; } output = mjb_buffer_make(storage, sizeof(storage), MJB_ENC_UTF_8); if(mjb_idna_to_ascii_into(&domain, &info, &output) != MJB_STATUS_OK || info.errors != MJB_IDNA_ERROR_NONE) { ATT_ASSERT(0, 1, "mjb_idna_to_ascii_into test failed"); // Added by the script return; } // ASCII payload (no terminator): xn--bcher-kva.example // printf("ASCII payload (no terminator): %.*s", (int)output.size, storage); snprintf(test_buffer, sizeof(test_buffer), "ASCII payload (no terminator): %.*s", (int)output.size, storage); // Added by the script ATT_ASSERT(test_buffer, "ASCII payload (no terminator): xn--bcher-kva.example", "mjb_idna_to_ascii_into test failed"); // Added by the script } #endif // MJB_FEATURE_IDNA #if MJB_FEATURE_IDNA { // Example for mjb_idna_to_unicode MJB_TEST_COVERAGE(mjb_idna_to_unicode); // Added by the script mjb_text domain = mjb_text_utf8("xn--bcher-kva.example", MJB_NUL_TERMINATED); mjb_idna_info info; mjb_result result; if(mjb_idna_to_unicode(&domain, MJB_ENC_UTF_8, &info, &result) != MJB_STATUS_OK || info.errors != MJB_IDNA_ERROR_NONE) { ATT_ASSERT(0, 1, "mjb_idna_to_unicode test failed"); // Added by the script return; } // bücher.example // printf("%.*s", (int)result.output_size, result.output); snprintf(test_buffer, sizeof(test_buffer), "%.*s", (int)result.output_size, result.output); // Added by the script ATT_ASSERT(test_buffer, "bücher.example", "mjb_idna_to_unicode test failed"); // Added by the script mjb_result_free(&result); } #endif // MJB_FEATURE_IDNA #if MJB_FEATURE_IDNA { // Example for mjb_idna_to_unicode_into MJB_TEST_COVERAGE(mjb_idna_to_unicode_into); // Added by the script mjb_text domain = mjb_text_utf8("xn--bcher-kva.example", MJB_NUL_TERMINATED); mjb_buffer output = mjb_buffer_make(NULL, 0, MJB_ENC_UTF_8); mjb_idna_info info; // Query the required size if(mjb_idna_to_unicode_into(&domain, &info, &output) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_idna_to_unicode_into test failed"); // Added by the script return; } char storage[15]; if(output.size > sizeof(storage)) { ATT_ASSERT(0, 1, "mjb_idna_to_unicode_into test failed"); // Added by the script return; } output = mjb_buffer_make(storage, sizeof(storage), MJB_ENC_UTF_8); if(mjb_idna_to_unicode_into(&domain, &info, &output) != MJB_STATUS_OK || info.errors != MJB_IDNA_ERROR_NONE) { ATT_ASSERT(0, 1, "mjb_idna_to_unicode_into test failed"); // Added by the script return; } // Unicode payload (no terminator): bücher.example // printf("Unicode payload (no terminator): %.*s", (int)output.size, storage); snprintf(test_buffer, sizeof(test_buffer), "Unicode payload (no terminator): %.*s", (int)output.size, storage); // Added by the script ATT_ASSERT(test_buffer, "Unicode payload (no terminator): bücher.example", "mjb_idna_to_unicode_into test failed"); // Added by the script } #endif // MJB_FEATURE_IDNA { // Example for mjb_normalization_quick_check MJB_TEST_COVERAGE(mjb_normalization_quick_check); // Added by the script mjb_text input = mjb_text_utf8("caf\xC3\xA9", MJB_NUL_TERMINATED); mjb_quick_check_result check; if(mjb_normalization_quick_check(&input, MJB_NORMALIZATION_NFC, &check) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_normalization_quick_check test failed"); // Added by the script return; } // NFC normalized: yes // printf("NFC normalized: %s", check == MJB_QC_YES ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "NFC normalized: %s", check == MJB_QC_YES ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "NFC normalized: yes", "mjb_normalization_quick_check test failed"); // Added by the script } { // Example for mjb_detect_encoding MJB_TEST_COVERAGE(mjb_detect_encoding); // Added by the script const char utf16le[] = "\xFF\xFEH\0i\0"; mjb_encoding detected = mjb_detect_encoding(utf16le, sizeof(utf16le) - 1); bool is_utf16le = detected == (MJB_ENC_UTF_16 | MJB_ENC_UTF_16LE); // UTF-16LE detected: yes // printf("UTF-16LE detected: %s", is_utf16le ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "UTF-16LE detected: %s", is_utf16le ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "UTF-16LE detected: yes", "mjb_detect_encoding test failed"); // Added by the script } { // Example for mjb_is_ascii MJB_TEST_COVERAGE(mjb_is_ascii); // Added by the script const char *input = "Plain ASCII"; // ASCII: yes // printf("ASCII: %s", mjb_is_ascii(input, strlen(input)) ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "ASCII: %s", mjb_is_ascii(input, strlen(input)) ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "ASCII: yes", "mjb_is_ascii test failed"); // Added by the script } { // Example for mjb_is_utf8 MJB_TEST_COVERAGE(mjb_is_utf8); // Added by the script const char *input = "caf\xC3\xA9"; // Valid UTF-8: yes // printf("Valid UTF-8: %s", mjb_is_utf8(input, strlen(input)) ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Valid UTF-8: %s", mjb_is_utf8(input, strlen(input)) ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Valid UTF-8: yes", "mjb_is_utf8 test failed"); // Added by the script } { // Example for mjb_is_utf16 MJB_TEST_COVERAGE(mjb_is_utf16); // Added by the script const char utf16be[] = "\xFE\xFF\0H\0i"; // BOM + "Hi" in UTF-16BE // UTF-16: yes // printf("UTF-16: %s", mjb_is_utf16(utf16be, sizeof(utf16be) - 1) ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "UTF-16: %s", mjb_is_utf16(utf16be, sizeof(utf16be) - 1) ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "UTF-16: yes", "mjb_is_utf16 test failed"); // Added by the script } { // Example for mjb_validate_encoding MJB_TEST_COVERAGE(mjb_validate_encoding); // Added by the script const char invalid[] = "\xE2\x82"; mjb_text text = mjb_text_utf8(invalid, sizeof(invalid) - 1); mjb_diagnostic diagnostic; if(mjb_validate_encoding(&text, &diagnostic) != MJB_STATUS_MALFORMED_INPUT || diagnostic.byte_offset != 0) { ATT_ASSERT(0, 1, "mjb_validate_encoding test failed"); // Added by the script return; } } { // Example for mjb_nul_terminated_length MJB_TEST_COVERAGE(mjb_nul_terminated_length); // Added by the script const char utf16le[] = "H\0i\0\0\0"; // "Hi" in UTF-16LE size_t byte_length; if(mjb_nul_terminated_length(utf16le, MJB_ENC_UTF_16LE, &byte_length) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_nul_terminated_length test failed"); // Added by the script return; } // Byte length: 4 // printf("Byte length: %zu", byte_length); snprintf(test_buffer, sizeof(test_buffer), "Byte length: %zu", byte_length); // Added by the script ATT_ASSERT(test_buffer, "Byte length: 4", "mjb_nul_terminated_length test failed"); // Added by the script } { // Example for mjb_decode_next MJB_TEST_COVERAGE(mjb_decode_next); // Added by the script // "été" const char *word = "\xC3\xA9t\xC3\xA9"; mjb_text input = mjb_text_utf8(word, strlen(word)); size_t offset = 0; size_t count = 0; mjb_codepoint codepoint; mjb_status status; while((status = mjb_decode_next(&input, MJB_MALFORMED_STOP, &offset, &codepoint, NULL)) == MJB_STATUS_OK) { ++count; } if(status != MJB_STATUS_END_OF_INPUT) { ATT_ASSERT(0, 1, "mjb_decode_next test failed"); // Added by the script return; } // 3 codepoints in 5 bytes // printf("%zu codepoints in %zu bytes", count, offset); snprintf(test_buffer, sizeof(test_buffer), "%zu codepoints in %zu bytes", count, offset); // Added by the script ATT_ASSERT(test_buffer, "3 codepoints in 5 bytes", "mjb_decode_next test failed"); // Added by the script } { // Example for mjb_decode_previous MJB_TEST_COVERAGE(mjb_decode_previous); // Added by the script // "été" const char *word = "\xC3\xA9t\xC3\xA9"; mjb_text input = mjb_text_utf8(word, strlen(word)); size_t offset = strlen(word); // Start at the end mjb_codepoint codepoint; if(mjb_decode_previous(&input, MJB_MALFORMED_STOP, &offset, &codepoint, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_decode_previous test failed"); // Added by the script return; } // Last codepoint: U+00E9 at byte 3 // printf("Last codepoint: U+%04X at byte %zu", (unsigned)codepoint, offset); snprintf(test_buffer, sizeof(test_buffer), "Last codepoint: U+%04X at byte %zu", (unsigned)codepoint, offset); // Added by the script ATT_ASSERT(test_buffer, "Last codepoint: U+00E9 at byte 3", "mjb_decode_previous test failed"); // Added by the script } { // Example for mjb_codepoint_count MJB_TEST_COVERAGE(mjb_codepoint_count); // Added by the script // The "Héllö" string is five Unicode characters, but has different byte lengths in different encodings. mjb_text utf8 = mjb_text_utf8("H\xC3\xA9ll\xC3\xB6", 7); // 7 bytes mjb_text utf16le = mjb_text_utf16le("H\0\xE9\0l\0l\0\xF6\0", 10); // 10 bytes size_t count; if(mjb_codepoint_count(&utf8, MJB_MALFORMED_STOP, &count, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_codepoint_count test failed"); // Added by the script return; } // 5 UTF-8 characters // printf("%zu UTF-8 characters", count); snprintf(test_buffer, sizeof(test_buffer), "%zu UTF-8 characters", count); // Added by the script ATT_ASSERT(test_buffer, "5 UTF-8 characters", "mjb_codepoint_count test failed"); // Added by the script if(mjb_codepoint_count(&utf16le, MJB_MALFORMED_STOP, &count, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_codepoint_count test failed"); // Added by the script return; } // 5 UTF-16LE characters // printf("%zu UTF-16LE characters", count); snprintf(test_buffer, sizeof(test_buffer), "%zu UTF-16LE characters", count); // Added by the script ATT_ASSERT(test_buffer, "5 UTF-16LE characters", "mjb_codepoint_count test failed"); // Added by the script } { // Example for mjb_for_each_codepoint MJB_TEST_COVERAGE(mjb_for_each_codepoint); // Added by the script mjb_text input = mjb_text_utf8("ABC", 3); mjb_status status = mjb_for_each_codepoint(&input, MJB_MALFORMED_STOP, NULL, NULL, NULL); // A callback is required: yes bool callback_required = status == MJB_STATUS_INVALID_ARGUMENT; // A callback is required: yes // printf("A callback is required: %s", callback_required ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "A callback is required: %s", callback_required ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "A callback is required: yes", "mjb_for_each_codepoint test failed"); // Added by the script } { // Example for mjb_codepoint_property_binary MJB_TEST_COVERAGE(mjb_codepoint_property_binary); // Added by the script bool is_alphabetic; if(mjb_codepoint_property_binary('A', MJB_PR_ALPHABETIC, &is_alphabetic) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_codepoint_property_binary test failed"); // Added by the script return; } // U+0041 is alphabetic: yes // printf("U+0041 is alphabetic: %s", is_alphabetic ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "U+0041 is alphabetic: %s", is_alphabetic ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "U+0041 is alphabetic: yes", "mjb_codepoint_property_binary test failed"); // Added by the script } { // Example for mjb_codepoint_property_int MJB_TEST_COVERAGE(mjb_codepoint_property_int); // Added by the script int32_t script; if(mjb_codepoint_property_int('A', MJB_PR_SCRIPT, &script) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_codepoint_property_int test failed"); // Added by the script return; } // U+0041 uses the Latin script: yes // printf("U+0041 uses the Latin script: %s", script == MJB_SC_LATN ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "U+0041 uses the Latin script: %s", script == MJB_SC_LATN ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "U+0041 uses the Latin script: yes", "mjb_codepoint_property_int test failed"); // Added by the script } { // Example for mjb_codepoint_numeric_value MJB_TEST_COVERAGE(mjb_codepoint_numeric_value); // Added by the script mjb_numeric_value num; if(mjb_codepoint_numeric_value(0x0031, &num) != MJB_STATUS_OK) { // U+0031 = 1 ATT_ASSERT(0, 1, "mjb_codepoint_numeric_value test failed"); // Added by the script return; } // decimal=1, digit=1, numeric=1 // printf("decimal=%d, digit=%d, numeric=%s", num.decimal, num.digit, num.numeric); snprintf(test_buffer, sizeof(test_buffer), "decimal=%d, digit=%d, numeric=%s", num.decimal, num.digit, num.numeric); // Added by the script ATT_ASSERT(test_buffer, "decimal=1, digit=1, numeric=1", "mjb_codepoint_numeric_value test failed"); // Added by the script if(mjb_codepoint_numeric_value(0x00BD, &num) != MJB_STATUS_OK) { // U+00BD = '½' ATT_ASSERT(0, 1, "mjb_codepoint_numeric_value test failed"); // Added by the script return; } // decimal=-1, digit=-1, numeric=1/2 // printf("decimal=%d, digit=%d, numeric=%s", num.decimal, num.digit, num.numeric); snprintf(test_buffer, sizeof(test_buffer), "decimal=%d, digit=%d, numeric=%s", num.decimal, num.digit, num.numeric); // Added by the script ATT_ASSERT(test_buffer, "decimal=-1, digit=-1, numeric=1/2", "mjb_codepoint_numeric_value test failed"); // Added by the script } { // Example for mjb_codepoint_block MJB_TEST_COVERAGE(mjb_codepoint_block); // Added by the script mjb_block_info block; if(mjb_codepoint_block('A', &block) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_codepoint_block test failed"); // Added by the script return; } // Block: Basic Latin // printf("Block: %s", block.name); snprintf(test_buffer, sizeof(test_buffer), "Block: %s", block.name); // Added by the script ATT_ASSERT(test_buffer, "Block: Basic Latin", "mjb_codepoint_block test failed"); // Added by the script } { // Example for mjb_codepoint_script MJB_TEST_COVERAGE(mjb_codepoint_script); // Added by the script mjb_script script = mjb_codepoint_script(0x03A9); // Greek capital omega // Greek script: yes // printf("Greek script: %s", script == MJB_SC_GREK ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Greek script: %s", script == MJB_SC_GREK ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Greek script: yes", "mjb_codepoint_script test failed"); // Added by the script } { // Example for mjb_codepoint_script_extensions MJB_TEST_COVERAGE(mjb_codepoint_script_extensions); // Added by the script size_t count = 0; if(mjb_codepoint_script_extensions(0x30FC, NULL, &count) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_codepoint_script_extensions test failed"); // Added by the script return; } mjb_script scripts[3]; if(count > 3 || mjb_codepoint_script_extensions(0x30FC, scripts, &count) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_codepoint_script_extensions test failed"); // Added by the script return; } // U+30FC has 2 Script_Extensions // printf("U+30FC has %zu Script_Extensions", count); snprintf(test_buffer, sizeof(test_buffer), "U+30FC has %zu Script_Extensions", count); // Added by the script ATT_ASSERT(test_buffer, "U+30FC has 2 Script_Extensions", "mjb_codepoint_script_extensions test failed"); // Added by the script } { // Example for mjb_codepoint_encode MJB_TEST_COVERAGE(mjb_codepoint_encode); // Added by the script char encoded[4]; unsigned int size = mjb_codepoint_encode(0x20AC, encoded, sizeof(encoded), MJB_ENC_UTF_8); // € sign uses 3 UTF-8 bytes // printf("%.*s sign uses %u UTF-8 bytes", (int)size, encoded, size); snprintf(test_buffer, sizeof(test_buffer), "%.*s sign uses %u UTF-8 bytes", (int)size, encoded, size); // Added by the script ATT_ASSERT(test_buffer, "€ sign uses 3 UTF-8 bytes", "mjb_codepoint_encode test failed"); // Added by the script } { // Example for mjb_convert_encoding MJB_TEST_COVERAGE(mjb_convert_encoding); // Added by the script mjb_text input = mjb_text_utf8("caf\xC3\xA9", MJB_NUL_TERMINATED); mjb_result result; if(mjb_convert_encoding(&input, MJB_MALFORMED_STOP, MJB_ENC_UTF_16LE, &result, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_convert_encoding test failed"); // Added by the script return; } // UTF-16LE bytes: 8 // printf("UTF-16LE bytes: %zu", result.output_size); snprintf(test_buffer, sizeof(test_buffer), "UTF-16LE bytes: %zu", result.output_size); // Added by the script ATT_ASSERT(test_buffer, "UTF-16LE bytes: 8", "mjb_convert_encoding test failed"); // Added by the script mjb_result_free(&result); } { // Example for mjb_convert_encoding_into MJB_TEST_COVERAGE(mjb_convert_encoding_into); // Added by the script mjb_text input = mjb_text_utf8("caf\xC3\xA9", MJB_NUL_TERMINATED); mjb_buffer output = mjb_buffer_make(NULL, 0, MJB_ENC_UTF_16LE); // Query the required size if(mjb_convert_encoding_into(&input, MJB_MALFORMED_STOP, &output, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_convert_encoding_into test failed"); // Added by the script return; } unsigned char storage[8]; if(output.size > sizeof(storage)) { ATT_ASSERT(0, 1, "mjb_convert_encoding_into test failed"); // Added by the script return; } output = mjb_buffer_make(storage, sizeof(storage), MJB_ENC_UTF_16LE); if(mjb_convert_encoding_into(&input, MJB_MALFORMED_STOP, &output, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_convert_encoding_into test failed"); // Added by the script return; } // UTF-16LE payload bytes (no terminator): 8 // printf("UTF-16LE payload bytes (no terminator): %zu", output.size); snprintf(test_buffer, sizeof(test_buffer), "UTF-16LE payload bytes (no terminator): %zu", output.size); // Added by the script ATT_ASSERT(test_buffer, "UTF-16LE payload bytes (no terminator): 8", "mjb_convert_encoding_into test failed"); // Added by the script } { // Example for mjb_caseless_match MJB_TEST_COVERAGE(mjb_caseless_match); // Added by the script mjb_text left = mjb_text_utf8("Stra\xC3\x9F" "e", MJB_NUL_TERMINATED); mjb_text right = mjb_text_utf8("STRASSE", MJB_NUL_TERMINATED); bool matches; if(mjb_caseless_match(&left, &right, MJB_MALFORMED_STOP, MJB_CASELESS_CANONICAL, &matches, NULL, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_caseless_match test failed"); // Added by the script return; } // Canonical caseless match: yes // printf("Canonical caseless match: %s", matches ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Canonical caseless match: %s", matches ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Canonical caseless match: yes", "mjb_caseless_match test failed"); // Added by the script } #if MJB_FEATURE_COLLATION { // Example for mjb_collation_compare MJB_TEST_COVERAGE(mjb_collation_compare); // Added by the script mjb_text apple = mjb_text_utf8("apple", 5); mjb_text banana = mjb_text_utf8("banana", 6); int order; if(mjb_collation_compare(&apple, &banana, MJB_MALFORMED_STOP, MJB_COLLATION_NON_IGNORABLE, MJB_COLLATION_TERTIARY, &order, NULL, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_collation_compare test failed"); // Added by the script return; } // apple sorts before banana: yes // printf("apple sorts before banana: %s", order < 0 ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "apple sorts before banana: %s", order < 0 ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "apple sorts before banana: yes", "mjb_collation_compare test failed"); // Added by the script } #endif // MJB_FEATURE_COLLATION #if MJB_FEATURE_COLLATION { // Example for mjb_collation_key MJB_TEST_COVERAGE(mjb_collation_key); // Added by the script mjb_text input = mjb_text_utf8("r\xC3\xA9sum\xC3\xA9", 8); mjb_result key; if(mjb_collation_key(&input, MJB_MALFORMED_STOP, MJB_COLLATION_NON_IGNORABLE, MJB_COLLATION_TERTIARY, &key, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_collation_key test failed"); // Added by the script return; } // Sort key is non-empty: yes // printf("Sort key is non-empty: %s", key.output_size > 0 ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Sort key is non-empty: %s", key.output_size > 0 ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Sort key is non-empty: yes", "mjb_collation_key test failed"); // Added by the script mjb_result_free(&key); } #endif // MJB_FEATURE_COLLATION #if MJB_FEATURE_COLLATION { // Example for mjb_collation_key_into MJB_TEST_COVERAGE(mjb_collation_key_into); // Added by the script mjb_text input = mjb_text_utf8("r\xC3\xA9sum\xC3\xA9", 8); // A collation key is binary, so the buffer encoding is ignored mjb_buffer output = mjb_buffer_make(NULL, 0, MJB_ENC_UNKNOWN); // Query the required size if(mjb_collation_key_into(&input, MJB_MALFORMED_STOP, MJB_COLLATION_NON_IGNORABLE, MJB_COLLATION_TERTIARY, &output, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_collation_key_into test failed"); // Added by the script return; } unsigned char storage[64]; if(output.size > sizeof(storage)) { ATT_ASSERT(0, 1, "mjb_collation_key_into test failed"); // Added by the script return; } output = mjb_buffer_make(storage, sizeof(storage), MJB_ENC_UNKNOWN); if(mjb_collation_key_into(&input, MJB_MALFORMED_STOP, MJB_COLLATION_NON_IGNORABLE, MJB_COLLATION_TERTIARY, &output, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_collation_key_into test failed"); // Added by the script return; } // Sort key is non-empty: yes // printf("Sort key is non-empty: %s", output.size > 0 ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Sort key is non-empty: %s", output.size > 0 ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Sort key is non-empty: yes", "mjb_collation_key_into test failed"); // Added by the script } #endif // MJB_FEATURE_COLLATION { // Example for mjb_map_case MJB_TEST_COVERAGE(mjb_map_case); // Added by the script mjb_text input = mjb_text_utf8("Stra\xC3\x9F""e", MJB_NUL_TERMINATED); // "Straße" mjb_result result; if(mjb_map_case(&input, MJB_MALFORMED_STOP, MJB_CASE_UPPER, MJB_LOCALE_NOT_SET, MJB_ENC_UTF_8, &result, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_map_case test failed"); // Added by the script return; } // Upper: STRASSE // printf("Upper: %.*s", (int)result.output_size, result.output); snprintf(test_buffer, sizeof(test_buffer), "Upper: %.*s", (int)result.output_size, result.output); // Added by the script ATT_ASSERT(test_buffer, "Upper: STRASSE", "mjb_map_case test failed"); // Added by the script mjb_result_free(&result); mjb_text istanbul = mjb_text_utf8("istanbul", MJB_NUL_TERMINATED); if(mjb_map_case(&istanbul, MJB_MALFORMED_STOP, MJB_CASE_UPPER, MJB_LOCALE_TR, MJB_ENC_UTF_8, &result, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_map_case test failed"); // Added by the script return; } // Turkish upper: \xC4\xB0STANBUL // printf("Turkish upper: %.*s", (int)result.output_size, result.output); snprintf(test_buffer, sizeof(test_buffer), "Turkish upper: %.*s", (int)result.output_size, result.output); // Added by the script ATT_ASSERT(test_buffer, "Turkish upper: \xC4\xB0STANBUL", "mjb_map_case test failed"); // Added by the script mjb_result_free(&result); } { // Example for mjb_map_case_into MJB_TEST_COVERAGE(mjb_map_case_into); // Added by the script mjb_text input = mjb_text_utf8("Stra\xC3\x9F""e", MJB_NUL_TERMINATED); // "Straße" mjb_buffer output = mjb_buffer_make(NULL, 0, MJB_ENC_UTF_8); // Query the required size if(mjb_map_case_into(&input, MJB_MALFORMED_STOP, MJB_CASE_UPPER, MJB_LOCALE_NOT_SET, &output, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_map_case_into test failed"); // Added by the script return; } char storage[7]; if(output.size > sizeof(storage)) { ATT_ASSERT(0, 1, "mjb_map_case_into test failed"); // Added by the script return; } output = mjb_buffer_make(storage, sizeof(storage), MJB_ENC_UTF_8); if(mjb_map_case_into(&input, MJB_MALFORMED_STOP, MJB_CASE_UPPER, MJB_LOCALE_NOT_SET, &output, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_map_case_into test failed"); // Added by the script return; } // Upper payload (no terminator): STRASSE // printf("Upper payload (no terminator): %.*s", (int)output.size, storage); snprintf(test_buffer, sizeof(test_buffer), "Upper payload (no terminator): %.*s", (int)output.size, storage); // Added by the script ATT_ASSERT(test_buffer, "Upper payload (no terminator): STRASSE", "mjb_map_case_into test failed"); // Added by the script } { // Example for mjb_codepoint_is_valid MJB_TEST_COVERAGE(mjb_codepoint_is_valid); // Added by the script // U+10FFFD valid: yes // printf("U+10FFFD valid: %s", mjb_codepoint_is_valid(0x10FFFD) ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "U+10FFFD valid: %s", mjb_codepoint_is_valid(0x10FFFD) ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "U+10FFFD valid: yes", "mjb_codepoint_is_valid test failed"); // Added by the script } { // Example for mjb_codepoint_is_graphic MJB_TEST_COVERAGE(mjb_codepoint_is_graphic); // Added by the script // Letter A is graphic: yes // printf("Letter A is graphic: %s", mjb_codepoint_is_graphic('A') ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Letter A is graphic: %s", mjb_codepoint_is_graphic('A') ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Letter A is graphic: yes", "mjb_codepoint_is_graphic test failed"); // Added by the script } { // Example for mjb_codepoint_is_combining MJB_TEST_COVERAGE(mjb_codepoint_is_combining); // Added by the script // U+0301 is combining: yes // printf("U+0301 is combining: %s", mjb_codepoint_is_combining(0x0301) ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "U+0301 is combining: %s", mjb_codepoint_is_combining(0x0301) ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "U+0301 is combining: yes", "mjb_codepoint_is_combining test failed"); // Added by the script } { // Example for mjb_codepoint_is_hangul_leading_jamo MJB_TEST_COVERAGE(mjb_codepoint_is_hangul_leading_jamo); // Added by the script // U+1100 is a leading Jamo: yes // printf("U+1100 is a leading Jamo: %s", mjb_codepoint_is_hangul_leading_jamo(0x1100) ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "U+1100 is a leading Jamo: %s", mjb_codepoint_is_hangul_leading_jamo(0x1100) ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "U+1100 is a leading Jamo: yes", "mjb_codepoint_is_hangul_leading_jamo test failed"); // Added by the script } { // Example for mjb_codepoint_is_hangul_vowel_jamo MJB_TEST_COVERAGE(mjb_codepoint_is_hangul_vowel_jamo); // Added by the script // U+1161 is a vowel Jamo: yes // printf("U+1161 is a vowel Jamo: %s", mjb_codepoint_is_hangul_vowel_jamo(0x1161) ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "U+1161 is a vowel Jamo: %s", mjb_codepoint_is_hangul_vowel_jamo(0x1161) ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "U+1161 is a vowel Jamo: yes", "mjb_codepoint_is_hangul_vowel_jamo test failed"); // Added by the script } { // Example for mjb_codepoint_is_hangul_trailing_jamo MJB_TEST_COVERAGE(mjb_codepoint_is_hangul_trailing_jamo); // Added by the script // U+11A8 is a trailing Jamo: yes // printf("U+11A8 is a trailing Jamo: %s", mjb_codepoint_is_hangul_trailing_jamo(0x11A8) ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "U+11A8 is a trailing Jamo: %s", mjb_codepoint_is_hangul_trailing_jamo(0x11A8) ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "U+11A8 is a trailing Jamo: yes", "mjb_codepoint_is_hangul_trailing_jamo test failed"); // Added by the script } { // Example for mjb_codepoint_is_hangul_jamo MJB_TEST_COVERAGE(mjb_codepoint_is_hangul_jamo); // Added by the script // U+1100 is Hangul Jamo: yes // printf("U+1100 is Hangul Jamo: %s", mjb_codepoint_is_hangul_jamo(0x1100) ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "U+1100 is Hangul Jamo: %s", mjb_codepoint_is_hangul_jamo(0x1100) ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "U+1100 is Hangul Jamo: yes", "mjb_codepoint_is_hangul_jamo test failed"); // Added by the script } { // Example for mjb_codepoint_is_hangul_syllable MJB_TEST_COVERAGE(mjb_codepoint_is_hangul_syllable); // Added by the script // U+AC00 is a Hangul syllable: yes // printf("U+AC00 is a Hangul syllable: %s", mjb_codepoint_is_hangul_syllable(0xAC00) ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "U+AC00 is a Hangul syllable: %s", mjb_codepoint_is_hangul_syllable(0xAC00) ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "U+AC00 is a Hangul syllable: yes", "mjb_codepoint_is_hangul_syllable test failed"); // Added by the script } { // Example for mjb_codepoint_is_cjk_ideograph MJB_TEST_COVERAGE(mjb_codepoint_is_cjk_ideograph); // Added by the script // U+4E00 is a CJK ideograph: yes // printf("U+4E00 is a CJK ideograph: %s", mjb_codepoint_is_cjk_ideograph(0x4E00) ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "U+4E00 is a CJK ideograph: %s", mjb_codepoint_is_cjk_ideograph(0x4E00) ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "U+4E00 is a CJK ideograph: yes", "mjb_codepoint_is_cjk_ideograph test failed"); // Added by the script } { // Example for mjb_codepoint_is_cjk_extension_ideograph MJB_TEST_COVERAGE(mjb_codepoint_is_cjk_extension_ideograph); // Added by the script // U+20000 is a CJK extension ideograph: yes // printf("U+20000 is a CJK extension ideograph: %s", mjb_codepoint_is_cjk_extension_ideograph(0x20000) ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "U+20000 is a CJK extension ideograph: %s", mjb_codepoint_is_cjk_extension_ideograph(0x20000) ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "U+20000 is a CJK extension ideograph: yes", "mjb_codepoint_is_cjk_extension_ideograph test failed"); // Added by the script } { // Example for mjb_category_is_graphic MJB_TEST_COVERAGE(mjb_category_is_graphic); // Added by the script // Uppercase letters are graphic: yes bool graphic = mjb_category_is_graphic(MJB_CATEGORY_LU); // Uppercase letters are graphic: yes // printf("Uppercase letters are graphic: %s", graphic ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Uppercase letters are graphic: %s", graphic ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Uppercase letters are graphic: yes", "mjb_category_is_graphic test failed"); // Added by the script } { // Example for mjb_category_is_combining MJB_TEST_COVERAGE(mjb_category_is_combining); // Added by the script // Nonspacing marks are combining: yes bool combining = mjb_category_is_combining(MJB_CATEGORY_MN); // Nonspacing marks are combining: yes // printf("Nonspacing marks are combining: %s", combining ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Nonspacing marks are combining: %s", combining ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Nonspacing marks are combining: yes", "mjb_category_is_combining test failed"); // Added by the script } { // Example for mjb_line_break_next MJB_TEST_COVERAGE(mjb_line_break_next); // Added by the script mjb_text input = mjb_text_utf8("Hello world", 11); mjb_line_break_state state; state.index = 0; mjb_break_type type = mjb_line_break_next(&input, &state); // First line-break result is set: yes // printf("First line-break result is set: %s", type != MJB_BT_NOT_SET ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "First line-break result is set: %s", type != MJB_BT_NOT_SET ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "First line-break result is set: yes", "mjb_line_break_next test failed"); // Added by the script } { // Example for mjb_word_break_next MJB_TEST_COVERAGE(mjb_word_break_next); // Added by the script mjb_text input = mjb_text_utf8("Hello world", 11); mjb_word_break_state state; state.index = 0; size_t boundaries = 0; while(mjb_word_break_next(&input, &state) != MJB_BT_NOT_SET) { ++boundaries; } // Word-break positions: 11 // printf("Word-break positions: %zu", boundaries); snprintf(test_buffer, sizeof(test_buffer), "Word-break positions: %zu", boundaries); // Added by the script ATT_ASSERT(test_buffer, "Word-break positions: 11", "mjb_word_break_next test failed"); // Added by the script } { // Example for mjb_sentence_break_next MJB_TEST_COVERAGE(mjb_sentence_break_next); // Added by the script mjb_sentence_break_state state; state.index = 0; size_t boundaries = 0; mjb_text input = mjb_text_utf8("Hello. Goodbye.", 15); while(mjb_sentence_break_next(&input, &state) != MJB_BT_NOT_SET) { ++boundaries; } // Sentence-break positions: 15 // printf("Sentence-break positions: %zu", boundaries); snprintf(test_buffer, sizeof(test_buffer), "Sentence-break positions: %zu", boundaries); // Added by the script ATT_ASSERT(test_buffer, "Sentence-break positions: 15", "mjb_sentence_break_next test failed"); // Added by the script } { // Example for mjb_sentence_count MJB_TEST_COVERAGE(mjb_sentence_count); // Added by the script mjb_text input = mjb_text_utf8("Hello. How are you? Fine!", MJB_NUL_TERMINATED); size_t count; if(mjb_sentence_count(&input, MJB_MALFORMED_STOP, &count, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_sentence_count test failed"); // Added by the script return; } // Sentences: 3 // printf("Sentences: %zu", count); snprintf(test_buffer, sizeof(test_buffer), "Sentences: %zu", count); // Added by the script ATT_ASSERT(test_buffer, "Sentences: 3", "mjb_sentence_count test failed"); // Added by the script } { // Example for mjb_grapheme_break_next MJB_TEST_COVERAGE(mjb_grapheme_break_next); // Added by the script mjb_text input = mjb_text_utf8("e\xCC\x81", 3); // e + combining acute accent mjb_grapheme_break_state state; state.index = 0; size_t codepoints = 0; while(mjb_grapheme_break_next(&input, &state) != MJB_BT_NOT_SET) { ++codepoints; } // Codepoints examined: 2 // printf("Codepoints examined: %zu", codepoints); snprintf(test_buffer, sizeof(test_buffer), "Codepoints examined: %zu", codepoints); // Added by the script ATT_ASSERT(test_buffer, "Codepoints examined: 2", "mjb_grapheme_break_next test failed"); // Added by the script } { // Example for mjb_grapheme_prefix_length MJB_TEST_COVERAGE(mjb_grapheme_prefix_length); // Added by the script mjb_text input = mjb_text_utf8("A\xF0\x9F\x87\xAE\xF0\x9F\x87\xB9Z", MJB_NUL_TERMINATED); // A🇮🇹Z size_t bytes = mjb_grapheme_prefix_length(&input, 2); // First two graphemes use 9 bytes // printf("First two graphemes use %zu bytes", bytes); snprintf(test_buffer, sizeof(test_buffer), "First two graphemes use %zu bytes", bytes); // Added by the script ATT_ASSERT(test_buffer, "First two graphemes use 9 bytes", "mjb_grapheme_prefix_length test failed"); // Added by the script } { // Example for mjb_grapheme_count MJB_TEST_COVERAGE(mjb_grapheme_count); // Added by the script mjb_text input = mjb_text_utf8("A\xF0\x9F\x87\xAE\xF0\x9F\x87\xB9", MJB_NUL_TERMINATED); // A🇮🇹 size_t count; if(mjb_grapheme_count(&input, MJB_MALFORMED_STOP, &count, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_grapheme_count test failed"); // Added by the script return; } // Grapheme clusters: 2 // printf("Grapheme clusters: %zu", count); snprintf(test_buffer, sizeof(test_buffer), "Grapheme clusters: %zu", count); // Added by the script ATT_ASSERT(test_buffer, "Grapheme clusters: 2", "mjb_grapheme_count test failed"); // Added by the script } { // Example for mjb_grapheme_prefix_length_for_width MJB_TEST_COVERAGE(mjb_grapheme_prefix_length_for_width); // Added by the script mjb_text input = mjb_text_utf8("A\xE7\x95\x8C", MJB_NUL_TERMINATED); // A界 size_t bytes = mjb_grapheme_prefix_length_for_width(&input, MJB_TERMINAL_WIDTH_NARROW, 2); // Two columns include 1 byte // printf("Two columns include %zu byte", bytes); snprintf(test_buffer, sizeof(test_buffer), "Two columns include %zu byte", bytes); // Added by the script ATT_ASSERT(test_buffer, "Two columns include 1 byte", "mjb_grapheme_prefix_length_for_width test failed"); // Added by the script } { // Example for mjb_word_prefix_length MJB_TEST_COVERAGE(mjb_word_prefix_length); // Added by the script mjb_text input = mjb_text_utf8("Hello world", MJB_NUL_TERMINATED); size_t bytes = mjb_word_prefix_length(&input, 1); // First word segment uses 5 bytes // printf("First word segment uses %zu bytes", bytes); snprintf(test_buffer, sizeof(test_buffer), "First word segment uses %zu bytes", bytes); // Added by the script ATT_ASSERT(test_buffer, "First word segment uses 5 bytes", "mjb_word_prefix_length test failed"); // Added by the script } { // Example for mjb_word_count MJB_TEST_COVERAGE(mjb_word_count); // Added by the script mjb_text input = mjb_text_utf8("Hello, world! It works.", MJB_NUL_TERMINATED); size_t count; if(mjb_word_count(&input, MJB_MALFORMED_STOP, &count, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_word_count test failed"); // Added by the script return; } // Words: 4 // printf("Words: %zu", count); snprintf(test_buffer, sizeof(test_buffer), "Words: %zu", count); // Added by the script ATT_ASSERT(test_buffer, "Words: 4", "mjb_word_count test failed"); // Added by the script } { // Example for mjb_word_prefix_length_for_width MJB_TEST_COVERAGE(mjb_word_prefix_length_for_width); // Added by the script mjb_text input = mjb_text_utf8("Hello world", MJB_NUL_TERMINATED); size_t bytes = mjb_word_prefix_length_for_width(&input, MJB_TERMINAL_WIDTH_NARROW, 6); // Six columns include 6 bytes // printf("Six columns include %zu bytes", bytes); snprintf(test_buffer, sizeof(test_buffer), "Six columns include %zu bytes", bytes); // Added by the script ATT_ASSERT(test_buffer, "Six columns include 6 bytes", "mjb_word_prefix_length_for_width test failed"); // Added by the script } { // Example for mjb_bidi_resolve MJB_TEST_COVERAGE(mjb_bidi_resolve); // Added by the script mjb_text input = mjb_text_utf8("abc \xD7\x90\xD7\x91\xD7\x92", MJB_NUL_TERMINATED); // abc אבג mjb_bidi_paragraph paragraph; if(mjb_bidi_resolve(&input, MJB_DIRECTION_AUTO, ¶graph) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_bidi_resolve test failed"); // Added by the script return; } // Paragraph codepoints: 7 // printf("Paragraph codepoints: %zu", paragraph.count); snprintf(test_buffer, sizeof(test_buffer), "Paragraph codepoints: %zu", paragraph.count); // Added by the script ATT_ASSERT(test_buffer, "Paragraph codepoints: 7", "mjb_bidi_resolve test failed"); // Added by the script mjb_bidi_paragraph_free(¶graph); } { // Example for mjb_bidi_reorder_line MJB_TEST_COVERAGE(mjb_bidi_reorder_line); // Added by the script mjb_text input = mjb_text_utf8("\xD7\x90\xD7\x91\xD7\x92", MJB_NUL_TERMINATED); // אבג mjb_bidi_paragraph paragraph; size_t visual_order[3]; if(mjb_bidi_resolve(&input, MJB_DIRECTION_AUTO, ¶graph) != MJB_STATUS_OK || mjb_bidi_reorder_line(¶graph, 0, paragraph.count, visual_order) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_bidi_reorder_line test failed"); // Added by the script return; } // First visual index: 2 // printf("First visual index: %zu", visual_order[0]); snprintf(test_buffer, sizeof(test_buffer), "First visual index: %zu", visual_order[0]); // Added by the script ATT_ASSERT(test_buffer, "First visual index: 2", "mjb_bidi_reorder_line test failed"); // Added by the script mjb_bidi_paragraph_free(¶graph); } { // Example for mjb_bidi_line_runs MJB_TEST_COVERAGE(mjb_bidi_line_runs); // Added by the script mjb_text input = mjb_text_utf8("abc", 3); mjb_bidi_paragraph paragraph; size_t visual_order[3]; size_t run_count = 0; if(mjb_bidi_resolve(&input, MJB_DIRECTION_LTR, ¶graph) != MJB_STATUS_OK || mjb_bidi_reorder_line(¶graph, 0, 3, visual_order) != MJB_STATUS_OK || mjb_bidi_line_runs(¶graph, visual_order, 3, NULL, &run_count) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_bidi_line_runs test failed"); // Added by the script return; } // Visual runs: 1 // printf("Visual runs: %zu", run_count); snprintf(test_buffer, sizeof(test_buffer), "Visual runs: %zu", run_count); // Added by the script ATT_ASSERT(test_buffer, "Visual runs: 1", "mjb_bidi_line_runs test failed"); // Added by the script mjb_bidi_paragraph_free(¶graph); } { // Example for mjb_bidi_paragraph_free MJB_TEST_COVERAGE(mjb_bidi_paragraph_free); // Added by the script mjb_text input = mjb_text_utf8("abc", 3); mjb_bidi_paragraph paragraph; if(mjb_bidi_resolve(&input, MJB_DIRECTION_LTR, ¶graph) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_bidi_paragraph_free test failed"); // Added by the script return; } mjb_bidi_paragraph_free(¶graph); // Paragraph released: yes // printf("Paragraph released: %s", paragraph.chars == NULL ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Paragraph released: %s", paragraph.chars == NULL ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Paragraph released: yes", "mjb_bidi_paragraph_free test failed"); // Added by the script } { // Example for mjb_codepoint_is_id_start MJB_TEST_COVERAGE(mjb_codepoint_is_id_start); // Added by the script // Greek alpha starts an identifier: yes bool starts = mjb_codepoint_is_id_start(0x03B1); // Greek alpha starts an identifier: yes // printf("Greek alpha starts an identifier: %s", starts ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Greek alpha starts an identifier: %s", starts ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Greek alpha starts an identifier: yes", "mjb_codepoint_is_id_start test failed"); // Added by the script } { // Example for mjb_codepoint_is_id_continue MJB_TEST_COVERAGE(mjb_codepoint_is_id_continue); // Added by the script // Digit 7 continues an identifier: yes bool continues = mjb_codepoint_is_id_continue('7'); // Digit 7 continues an identifier: yes // printf("Digit 7 continues an identifier: %s", continues ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Digit 7 continues an identifier: %s", continues ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Digit 7 continues an identifier: yes", "mjb_codepoint_is_id_continue test failed"); // Added by the script } { // Example for mjb_codepoint_is_xid_start MJB_TEST_COVERAGE(mjb_codepoint_is_xid_start); // Added by the script // Letter A is XID_Start: yes // printf("Letter A is XID_Start: %s", mjb_codepoint_is_xid_start('A') ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Letter A is XID_Start: %s", mjb_codepoint_is_xid_start('A') ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Letter A is XID_Start: yes", "mjb_codepoint_is_xid_start test failed"); // Added by the script } { // Example for mjb_codepoint_is_xid_continue MJB_TEST_COVERAGE(mjb_codepoint_is_xid_continue); // Added by the script // Underscore is XID_Continue: yes bool continues = mjb_codepoint_is_xid_continue('_'); // Underscore is XID_Continue: yes // printf("Underscore is XID_Continue: %s", continues ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Underscore is XID_Continue: %s", continues ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Underscore is XID_Continue: yes", "mjb_codepoint_is_xid_continue test failed"); // Added by the script } { // Example for mjb_codepoint_is_pattern_syntax MJB_TEST_COVERAGE(mjb_codepoint_is_pattern_syntax); // Added by the script // Plus sign is Pattern_Syntax: yes bool syntax = mjb_codepoint_is_pattern_syntax('+'); // Plus sign is Pattern_Syntax: yes // printf("Plus sign is Pattern_Syntax: %s", syntax ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Plus sign is Pattern_Syntax: %s", syntax ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Plus sign is Pattern_Syntax: yes", "mjb_codepoint_is_pattern_syntax test failed"); // Added by the script } { // Example for mjb_codepoint_is_pattern_white_space MJB_TEST_COVERAGE(mjb_codepoint_is_pattern_white_space); // Added by the script // Space is Pattern_White_Space: yes bool whitespace = mjb_codepoint_is_pattern_white_space(' '); // Space is Pattern_White_Space: yes // printf("Space is Pattern_White_Space: %s", whitespace ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Space is Pattern_White_Space: %s", whitespace ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Space is Pattern_White_Space: yes", "mjb_codepoint_is_pattern_white_space test failed"); // Added by the script } { // Example for mjb_is_identifier MJB_TEST_COVERAGE(mjb_is_identifier); // Added by the script mjb_text identifier = mjb_text_utf8("delta_2", MJB_NUL_TERMINATED); bool valid = mjb_is_identifier(&identifier, MJB_IDENTIFIER_NFKC); // Valid identifier: yes // printf("Valid identifier: %s", valid ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Valid identifier: %s", valid ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Valid identifier: yes", "mjb_is_identifier test failed"); // Added by the script } #if MJB_FEATURE_SECURITY { // Example for mjb_resolved_script_set MJB_TEST_COVERAGE(mjb_resolved_script_set); // Added by the script mjb_text input = mjb_text_utf8("\xE3\x81\xAD\xE3\x82\xAC", MJB_NUL_TERMINATED); // Hiragana + Katakana mjb_script scripts[1]; size_t count = 1; mjb_script_set_kind kind; if(mjb_resolved_script_set(&input, scripts, &count, &kind) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_resolved_script_set test failed"); // Added by the script return; } bool japanese = kind == MJB_SCRIPT_SET_RESOLVED && count == 1 && scripts[0] == MJB_SC_JPAN; // Japanese writing system: yes // printf("Japanese writing system: %s", japanese ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Japanese writing system: %s", japanese ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Japanese writing system: yes", "mjb_resolved_script_set test failed"); // Added by the script } #endif // MJB_FEATURE_SECURITY { // Example for mjb_property_name MJB_TEST_COVERAGE(mjb_property_name); // Added by the script const char *name = mjb_property_name(MJB_PR_ALPHABETIC); // Property: Alphabetic // printf("Property: %s", name); snprintf(test_buffer, sizeof(test_buffer), "Property: %s", name); // Added by the script ATT_ASSERT(test_buffer, "Property: Alphabetic", "mjb_property_name test failed"); // Added by the script } #if MJB_FEATURE_SECURITY { // Example for mjb_confusable_skeleton MJB_TEST_COVERAGE(mjb_confusable_skeleton); // Added by the script // Cyrillic U+0435 in place of e mjb_text input = mjb_text_utf8("h\xD0\xB5llo", MJB_NUL_TERMINATED); mjb_result result; if(mjb_confusable_skeleton(&input, MJB_ENC_UTF_8, &result) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_confusable_skeleton test failed"); // Added by the script return; } // hello // printf("%.*s", (int)result.output_size, result.output); snprintf(test_buffer, sizeof(test_buffer), "%.*s", (int)result.output_size, result.output); // Added by the script ATT_ASSERT(test_buffer, "hello", "mjb_confusable_skeleton test failed"); // Added by the script mjb_result_free(&result); } #endif // MJB_FEATURE_SECURITY #if MJB_FEATURE_SECURITY { // Example for mjb_confusable_skeleton_into MJB_TEST_COVERAGE(mjb_confusable_skeleton_into); // Added by the script // Cyrillic U+0435 in place of e mjb_text input = mjb_text_utf8("h\xD0\xB5llo", MJB_NUL_TERMINATED); mjb_buffer output = mjb_buffer_make(NULL, 0, MJB_ENC_UTF_8); // Query the required size if(mjb_confusable_skeleton_into(&input, &output) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_confusable_skeleton_into test failed"); // Added by the script return; } char storage[5]; if(output.size > sizeof(storage)) { ATT_ASSERT(0, 1, "mjb_confusable_skeleton_into test failed"); // Added by the script return; } output = mjb_buffer_make(storage, sizeof(storage), MJB_ENC_UTF_8); if(mjb_confusable_skeleton_into(&input, &output) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_confusable_skeleton_into test failed"); // Added by the script return; } // Skeleton payload (no terminator): hello // printf("Skeleton payload (no terminator): %.*s", (int)output.size, storage); snprintf(test_buffer, sizeof(test_buffer), "Skeleton payload (no terminator): %.*s", (int)output.size, storage); // Added by the script ATT_ASSERT(test_buffer, "Skeleton payload (no terminator): hello", "mjb_confusable_skeleton_into test failed"); // Added by the script } #endif // MJB_FEATURE_SECURITY #if MJB_FEATURE_SECURITY { // Example for mjb_confusable_match MJB_TEST_COVERAGE(mjb_confusable_match); // Added by the script mjb_text latin = mjb_text_utf8("hello", MJB_NUL_TERMINATED); mjb_text mixed = mjb_text_utf8("h\xD0\xB5llo", MJB_NUL_TERMINATED); // Cyrillic е bool confusable; if(mjb_confusable_match(&latin, &mixed, MJB_MALFORMED_STOP, &confusable, NULL, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_confusable_match test failed"); // Added by the script return; } // Visually confusable: yes // printf("Visually confusable: %s", confusable ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Visually confusable: %s", confusable ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Visually confusable: yes", "mjb_confusable_match test failed"); // Added by the script } #endif // MJB_FEATURE_SECURITY { // Example for mjb_codepoint_emoji_properties MJB_TEST_COVERAGE(mjb_codepoint_emoji_properties); // Added by the script mjb_emoji_properties emoji; if(mjb_codepoint_emoji_properties(0x1F600, &emoji) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_codepoint_emoji_properties test failed"); // Added by the script return; } // U+1F600 has Emoji_Presentation: yes // printf("U+1F600 has Emoji_Presentation: %s", emoji.presentation ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "U+1F600 has Emoji_Presentation: %s", emoji.presentation ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "U+1F600 has Emoji_Presentation: yes", "mjb_codepoint_emoji_properties test failed"); // Added by the script } { // Example for mjb_codepoint_is_emoji MJB_TEST_COVERAGE(mjb_codepoint_is_emoji); // Added by the script // Number sign has the Emoji property: yes bool emoji = mjb_codepoint_is_emoji('#'); // Number sign has the Emoji property: yes // printf("Number sign has the Emoji property: %s", emoji ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Number sign has the Emoji property: %s", emoji ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Number sign has the Emoji property: yes", "mjb_codepoint_is_emoji test failed"); // Added by the script } { // Example for mjb_codepoint_is_emoji_presentation MJB_TEST_COVERAGE(mjb_codepoint_is_emoji_presentation); // Added by the script // Grinning face defaults to emoji presentation: yes bool presentation = mjb_codepoint_is_emoji_presentation(0x1F600); // Grinning face defaults to emoji presentation: yes // printf("Grinning face defaults to emoji presentation: %s", presentation ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Grinning face defaults to emoji presentation: %s", presentation ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Grinning face defaults to emoji presentation: yes", "mjb_codepoint_is_emoji_presentation test failed"); // Added by the script } { // Example for mjb_codepoint_is_emoji_modifier MJB_TEST_COVERAGE(mjb_codepoint_is_emoji_modifier); // Added by the script // Medium skin tone is an emoji modifier: yes bool modifier = mjb_codepoint_is_emoji_modifier(0x1F3FD); // Medium skin tone is an emoji modifier: yes // printf("Medium skin tone is an emoji modifier: %s", modifier ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Medium skin tone is an emoji modifier: %s", modifier ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Medium skin tone is an emoji modifier: yes", "mjb_codepoint_is_emoji_modifier test failed"); // Added by the script } { // Example for mjb_codepoint_is_emoji_modifier_base MJB_TEST_COVERAGE(mjb_codepoint_is_emoji_modifier_base); // Added by the script // Waving hand accepts an emoji modifier: yes bool modifier_base = mjb_codepoint_is_emoji_modifier_base(0x1F44B); // Waving hand accepts an emoji modifier: yes // printf("Waving hand accepts an emoji modifier: %s", modifier_base ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Waving hand accepts an emoji modifier: %s", modifier_base ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Waving hand accepts an emoji modifier: yes", "mjb_codepoint_is_emoji_modifier_base test failed"); // Added by the script } { // Example for mjb_codepoint_is_emoji_component MJB_TEST_COVERAGE(mjb_codepoint_is_emoji_component); // Added by the script // Zero-width joiner is an emoji component: yes bool component = mjb_codepoint_is_emoji_component(0x200D); // Zero-width joiner is an emoji component: yes // printf("Zero-width joiner is an emoji component: %s", component ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Zero-width joiner is an emoji component: %s", component ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Zero-width joiner is an emoji component: yes", "mjb_codepoint_is_emoji_component test failed"); // Added by the script } { // Example for mjb_codepoint_is_extended_pictographic MJB_TEST_COVERAGE(mjb_codepoint_is_extended_pictographic); // Added by the script // Red heart is Extended_Pictographic: yes bool pictographic = mjb_codepoint_is_extended_pictographic(0x2764); // Red heart is Extended_Pictographic: yes // printf("Red heart is Extended_Pictographic: %s", pictographic ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Red heart is Extended_Pictographic: %s", pictographic ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Red heart is Extended_Pictographic: yes", "mjb_codepoint_is_extended_pictographic test failed"); // Added by the script } { // Example for mjb_codepoint_plane MJB_TEST_COVERAGE(mjb_codepoint_plane); // Added by the script mjb_plane plane = mjb_codepoint_plane(0x1F600); // U+1F600 is in the SMP: yes // printf("U+1F600 is in the SMP: %s", plane == MJB_PLANE_SMP ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "U+1F600 is in the SMP: %s", plane == MJB_PLANE_SMP ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "U+1F600 is in the SMP: yes", "mjb_codepoint_plane test failed"); // Added by the script } { // Example for mjb_plane_is_valid MJB_TEST_COVERAGE(mjb_plane_is_valid); // Added by the script // Plane 16 is valid: yes // printf("Plane 16 is valid: %s", mjb_plane_is_valid(MJB_PLANE_PUA_B) ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Plane 16 is valid: %s", mjb_plane_is_valid(MJB_PLANE_PUA_B) ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Plane 16 is valid: yes", "mjb_plane_is_valid test failed"); // Added by the script } { // Example for mjb_plane_name MJB_TEST_COVERAGE(mjb_plane_name); // Added by the script // Plane: Basic Multilingual Plane // printf("Plane: %s", mjb_plane_name(MJB_PLANE_BMP, false)); snprintf(test_buffer, sizeof(test_buffer), "Plane: %s", mjb_plane_name(MJB_PLANE_BMP, false)); // Added by the script ATT_ASSERT(test_buffer, "Plane: Basic Multilingual Plane", "mjb_plane_name test failed"); // Added by the script } { // Example for mjb_emoji_sequence_info MJB_TEST_COVERAGE(mjb_emoji_sequence_info); // Added by the script mjb_text flag = mjb_text_utf8("\xF0\x9F\x87\xAE\xF0\x9F\x87\xB9", MJB_NUL_TERMINATED); // 🇮🇹 mjb_emoji_sequence emoji; if(mjb_emoji_sequence_info(&flag, &emoji) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_emoji_sequence_info test failed"); // Added by the script return; } // Sequence codepoints: 2 // printf("Sequence codepoints: %zu", emoji.codepoint_count); snprintf(test_buffer, sizeof(test_buffer), "Sequence codepoints: %zu", emoji.codepoint_count); // Added by the script ATT_ASSERT(test_buffer, "Sequence codepoints: 2", "mjb_emoji_sequence_info test failed"); // Added by the script } { // Example for mjb_is_emoji_sequence MJB_TEST_COVERAGE(mjb_is_emoji_sequence); // Added by the script mjb_text keycap = mjb_text_utf8("1\xEF\xB8\x8F\xE2\x83\xA3", MJB_NUL_TERMINATED); // 1️⃣ bool listed = mjb_is_emoji_sequence(&keycap); // Listed emoji sequence: yes // printf("Listed emoji sequence: %s", listed ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Listed emoji sequence: %s", listed ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Listed emoji sequence: yes", "mjb_is_emoji_sequence test failed"); // Added by the script } { // Example for mjb_is_rgi_emoji MJB_TEST_COVERAGE(mjb_is_rgi_emoji); // Added by the script mjb_text flag = mjb_text_utf8("\xF0\x9F\x87\xAE\xF0\x9F\x87\xB9", MJB_NUL_TERMINATED); // 🇮🇹 bool rgi = mjb_is_rgi_emoji(&flag); // RGI emoji: yes // printf("RGI emoji: %s", rgi ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "RGI emoji: %s", rgi ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "RGI emoji: yes", "mjb_is_rgi_emoji test failed"); // Added by the script } { // Example for mjb_hangul_syllable_name MJB_TEST_COVERAGE(mjb_hangul_syllable_name); // Added by the script char name[32]; if(mjb_hangul_syllable_name(0xAC01, name, sizeof(name)) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_hangul_syllable_name test failed"); // Added by the script return; } // Name: HANGUL SYLLABLE GAG // printf("Name: %s", name); snprintf(test_buffer, sizeof(test_buffer), "Name: %s", name); // Added by the script ATT_ASSERT(test_buffer, "Name: HANGUL SYLLABLE GAG", "mjb_hangul_syllable_name test failed"); // Added by the script } { // Example for mjb_hangul_syllable_decompose MJB_TEST_COVERAGE(mjb_hangul_syllable_decompose); // Added by the script mjb_codepoint decomposition[3]; if(mjb_hangul_syllable_decompose(0xAC01, decomposition) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_hangul_syllable_decompose test failed"); // Added by the script return; } // Decomposition starts with: U+1100 // printf("Decomposition starts with: U+%04X", decomposition[0]); snprintf(test_buffer, sizeof(test_buffer), "Decomposition starts with: U+%04X", decomposition[0]); // Added by the script ATT_ASSERT(test_buffer, "Decomposition starts with: U+1100", "mjb_hangul_syllable_decompose test failed"); // Added by the script } { // Example for mjb_hangul_syllable_compose MJB_TEST_COVERAGE(mjb_hangul_syllable_compose); // Added by the script mjb_codepoint syllable; // Choseong kiyeok, jungseong a, jongseong kiyeok if(mjb_hangul_syllable_compose(0x1100, 0x1161, 0x11A8, &syllable) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_hangul_syllable_compose test failed"); // Added by the script return; } // Syllable: U+AC01 // printf("Syllable: U+%04X", syllable); snprintf(test_buffer, sizeof(test_buffer), "Syllable: U+%04X", syllable); // Added by the script ATT_ASSERT(test_buffer, "Syllable: U+AC01", "mjb_hangul_syllable_compose test failed"); // Added by the script } { // Example for mjb_codepoint_east_asian_width MJB_TEST_COVERAGE(mjb_codepoint_east_asian_width); // Added by the script mjb_east_asian_width width; if(mjb_codepoint_east_asian_width(0x754C, &width) != MJB_STATUS_OK) { // 界 ATT_ASSERT(0, 1, "mjb_codepoint_east_asian_width test failed"); // Added by the script return; } // U+754C is wide: yes // printf("U+754C is wide: %s", width == MJB_EAW_WIDE ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "U+754C is wide: %s", width == MJB_EAW_WIDE ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "U+754C is wide: yes", "mjb_codepoint_east_asian_width test failed"); // Added by the script } { // Example for mjb_terminal_width MJB_TEST_COVERAGE(mjb_terminal_width); // Added by the script mjb_text input = mjb_text_utf8("A\xE7\x95\x8C", MJB_NUL_TERMINATED); // A界 size_t width; if(mjb_terminal_width(&input, MJB_MALFORMED_STOP, MJB_TERMINAL_WIDTH_NARROW, &width, NULL) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_terminal_width test failed"); // Added by the script return; } // Terminal cells: 3 // printf("Terminal cells: %zu", width); snprintf(test_buffer, sizeof(test_buffer), "Terminal cells: %zu", width); // Added by the script ATT_ASSERT(test_buffer, "Terminal cells: 3", "mjb_terminal_width test failed"); // Added by the script } { // Example for mjb_locale_parse MJB_TEST_COVERAGE(mjb_locale_parse); // Added by the script mjb_text id = mjb_text_utf8("sr-Latn-RS", MJB_NUL_TERMINATED); mjb_locale_id locale; if(mjb_locale_parse(&id, &locale) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_locale_parse test failed"); // Added by the script return; } // Locale: sr Latn RS // printf("Locale: %s %s %s", locale.language, locale.script, locale.region); snprintf(test_buffer, sizeof(test_buffer), "Locale: %s %s %s", locale.language, locale.script, locale.region); // Added by the script ATT_ASSERT(test_buffer, "Locale: sr Latn RS", "mjb_locale_parse test failed"); // Added by the script } { // Example for mjb_locale_code MJB_TEST_COVERAGE(mjb_locale_code); // Added by the script // Locale code: tr // printf("Locale code: %s", mjb_locale_code(MJB_LOCALE_TR)); snprintf(test_buffer, sizeof(test_buffer), "Locale code: %s", mjb_locale_code(MJB_LOCALE_TR)); // Added by the script ATT_ASSERT(test_buffer, "Locale code: tr", "mjb_locale_code test failed"); // Added by the script } { // Example for mjb_script_code MJB_TEST_COVERAGE(mjb_script_code); // Added by the script // Script code: Latn // printf("Script code: %s", mjb_script_code(MJB_SC_LATN)); snprintf(test_buffer, sizeof(test_buffer), "Script code: %s", mjb_script_code(MJB_SC_LATN)); // Added by the script ATT_ASSERT(test_buffer, "Script code: Latn", "mjb_script_code test failed"); // Added by the script } { // Example for mjb_result_free MJB_TEST_COVERAGE(mjb_result_free); // Added by the script mjb_result result; mjb_text input = mjb_text_utf8("A", 1); if(mjb_convert_encoding(&input, MJB_MALFORMED_STOP, MJB_ENC_UTF_16LE, &result, NULL) != MJB_STATUS_OK || mjb_result_free(&result) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_result_free test failed"); // Added by the script return; } // Result released: yes // printf("Result released: %s", result.output == NULL ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Result released: %s", result.output == NULL ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Result released: yes", "mjb_result_free test failed"); // Added by the script } { // Example for mjb_utf8_snprintf MJB_TEST_COVERAGE(mjb_utf8_snprintf); // Added by the script char buffer[4]; int required = mjb_utf8_snprintf(buffer, sizeof(buffer), "%s", "\xC3\xA9\xC3\xA9"); // éé // 4: é // printf("%d: %s", required, buffer); snprintf(test_buffer, sizeof(test_buffer), "%d: %s", required, buffer); // Added by the script ATT_ASSERT(test_buffer, "4: é", "mjb_utf8_snprintf test failed"); // Added by the script } { // Example for mjb_utf8_vsnprintf MJB_TEST_COVERAGE(mjb_utf8_vsnprintf); // Added by the script char buffer[4]; int required = format_utf8(buffer, sizeof(buffer), "%s", "\xC3\xA9\xC3\xA9"); // éé // 4: é // printf("%d: %s", required, buffer); snprintf(test_buffer, sizeof(test_buffer), "%d: %s", required, buffer); // Added by the script ATT_ASSERT(test_buffer, "4: é", "mjb_utf8_vsnprintf test failed"); // Added by the script } { // Example for mjb_utf8_grapheme_snprintf MJB_TEST_COVERAGE(mjb_utf8_grapheme_snprintf); // Added by the script char buffer[4]; int required = mjb_utf8_grapheme_snprintf(buffer, sizeof(buffer), "%s", "Ae\xCC\x81" "B"); // A, e + combining acute accent, B // 5: A // printf("%d: %s", required, buffer); snprintf(test_buffer, sizeof(test_buffer), "%d: %s", required, buffer); // Added by the script ATT_ASSERT(test_buffer, "5: A", "mjb_utf8_grapheme_snprintf test failed"); // Added by the script } { // Example for mjb_utf8_grapheme_vsnprintf MJB_TEST_COVERAGE(mjb_utf8_grapheme_vsnprintf); // Added by the script char buffer[4]; int required = format_graphemes(buffer, sizeof(buffer), "%s", "Ae\xCC\x81" "B"); // A, e + combining acute accent, B // 5: A // printf("%d: %s", required, buffer); snprintf(test_buffer, sizeof(test_buffer), "%d: %s", required, buffer); // Added by the script ATT_ASSERT(test_buffer, "5: A", "mjb_utf8_grapheme_vsnprintf test failed"); // Added by the script } { // Example for mjb_status_message MJB_TEST_COVERAGE(mjb_status_message); // Added by the script const char *message = mjb_status_message(MJB_STATUS_INVALID_ARGUMENT); // Error message: One or more arguments are invalid or inconsistent with the requested operation // printf("Error message: %s", message); snprintf(test_buffer, sizeof(test_buffer), "Error message: %s", message); // Added by the script ATT_ASSERT(test_buffer, "Error message: One or more arguments are invalid or inconsistent with the requested operation", "mjb_status_message test failed"); // Added by the script } { // Example for mjb_version MJB_TEST_COVERAGE(mjb_version); // Added by the script const char *version = mjb_version(); // Version is available: yes // printf("Version is available: %s", version[0] != '\0' ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Version is available: %s", version[0] != '\0' ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Version is available: yes", "mjb_version test failed"); // Added by the script } { // Example for mjb_version_number MJB_TEST_COVERAGE(mjb_version_number); // Added by the script unsigned int version = mjb_version_number(); // Version number is positive: yes // printf("Version number is positive: %s", version > 0 ? "yes" : "no"); snprintf(test_buffer, sizeof(test_buffer), "Version number is positive: %s", version > 0 ? "yes" : "no"); // Added by the script ATT_ASSERT(test_buffer, "Version number is positive: yes", "mjb_version_number test failed"); // Added by the script } { // Example for mjb_unicode_version MJB_TEST_COVERAGE(mjb_unicode_version); // Added by the script const char *version = mjb_unicode_version(); // Unicode version: 18.0.0 // printf("Unicode version: %s", version); snprintf(test_buffer, sizeof(test_buffer), "Unicode version: %s", version); // Added by the script ATT_ASSERT(test_buffer, "Unicode version: 18.0.0", "mjb_unicode_version test failed"); // Added by the script } { // Example for mjb_set_allocator MJB_TEST_COVERAGE(mjb_set_allocator); // Added by the script volatile bool run_example = false; // Added by the script if(run_example) { // Added by the script static size_t bytes_in_use = 0; mjb_allocator allocator = { &bytes_in_use, counting_alloc, counting_realloc, counting_free }; // Install it once, before any other library call if(mjb_set_allocator(&allocator) != MJB_STATUS_OK) { ATT_ASSERT(0, 1, "mjb_set_allocator test failed"); // Added by the script return; } } // Added by the script } // End of generated examples. } // clang-format on