}END_TEST START_TEST(test_stringx_reset) { struct RFstringx s; static const struct RFstring sub1 = RF_STRING_STATIC_INIT("に"); ck_assert( rf_stringx_init( &s, "中国共産党総書記に習近平氏 新指導部の7人発表" ) ); /* resetting an unmoved string has no effect */ rf_stringx_reset(&s); ck_assert_rf_str_eq_cstr( &s, "中国共産党総書記に習近平氏 新指導部の7人発表" ); /* move and reset */ ck_assert(RF_FAILURE != rf_stringx_move_after(&s, &sub1, NULL, 0)); ck_assert_rf_str_eq_cstr(&s, "習近平氏 新指導部の7人発表"); rf_stringx_reset(&s); ck_assert_rf_str_eq_cstr( &s, "中国共産党総書記に習近平氏 新指導部の7人発表" ); rf_stringx_deinit(&s); }END_TEST
}END_TEST START_TEST(test_stringx_move_after_pair) { struct RFstringx s; struct RFstring res_str_good; struct RFstring res_str_bad; struct RFstring dependent_s; static const struct RFstring sub1 = RF_STRING_STATIC_INIT("「"); static const struct RFstring sub2 = RF_STRING_STATIC_INIT("」"); static const struct RFstring sub3 = RF_STRING_STATIC_INIT("eleos"); static const struct RFstring sub4 = RF_STRING_STATIC_INIT("notthere"); ck_assert( rf_stringx_init( &s, "これがMoveAfterPairのテストですね!「Δεν θα επιστραφω εγω" "」 Γεμιζουμε το στρινγκ " "με διαφορα 「ブラケットの中のテ" "キストは結果になる」Let's see if the function will work " "as expected." ) ); ck_assert( rf_stringx_move_after_pair(&s, &sub1, &sub2, &res_str_good, 0, 2) ); ck_assert_rf_str_eq_cstr( &s, "Let's see if the function will work as expected." ); ck_assert_rf_str_eq_cstr( &res_str_good, "ブラケットの中のテキストは結果になる" ); /* dependent string */ rf_stringx_reset(&s); ck_assert( rf_stringx_move_after_pair(&s, &sub1, &sub2, &dependent_s, RF_STRING_DEPENDENT, 2) ); ck_assert_rf_str_eq_cstr( &s, "Let's see if the function will work as expected." ); ck_assert_rf_str_eq_cstr( &dependent_s, "ブラケットの中のテキストは結果になる" ); /* non existing substrings */ ck_assert(!rf_stringx_move_after_pair(&s, &sub3, &sub4, &res_str_bad, 0, 2)); rf_stringx_deinit(&s); rf_string_deinit(&res_str_good); rf_string_deinit(&dependent_s); }END_TEST
}END_TEST START_TEST(test_textfile_read_lines) { struct RFtextfile f; static const struct RFstring fname = RF_STRING_STATIC_INIT( CLIB_TESTS_PATH"utf8stringfile" ); uint32_t buff_arr[64]; struct RFarray line_arr = RF_ARRAY_SHALLOW_INIT(buff_arr); ck_assert(rf_textfile_init(&f, &fname, RF_FILE_READ, RF_ENDIANESS_UNKNOWN, RF_UTF8, RF_EOL_LF)); rf_stringx_reset(&g_buff); /* read all lines (3 + 1 empty line) */ ck_assert_int_eq(4, rf_textfile_read_lines(&f, 0, &g_buff, &line_arr)); ck_assert_rf_str_eq_cstr(&g_buff, FIRST_LINE_UTF8"\n" SECOND_LINE_UTF8"\n" THIRD_LINE_UTF8"\n\n" ); ck_assert_int_eq(rf_array_at_unsafe(&line_arr, 0, uint32_t), 0); ck_assert_int_eq(rf_array_at_unsafe(&line_arr, 1, uint32_t), 11); ck_assert_int_eq(rf_array_at_unsafe(&line_arr, 2, uint32_t), 366); ck_assert_int_eq(rf_array_at_unsafe(&line_arr, 3, uint32_t), 1166); ck_assert(RF_SUCCESS == rf_textfile_go_to_line(&f, 1)); /* read 3 lines */ ck_assert(3 == rf_textfile_read_lines(&f, 3, &g_buff, 0)); ck_assert_rf_str_eq_cstr(&g_buff, FIRST_LINE_UTF8"\n" SECOND_LINE_UTF8"\n" THIRD_LINE_UTF8"\n" ); ck_assert(RF_SUCCESS == rf_textfile_go_to_line(&f, 1)); /* read 2 lines */ ck_assert(2 == rf_textfile_read_lines(&f, 2, &g_buff, 0)); ck_assert_rf_str_eq_cstr(&g_buff, FIRST_LINE_UTF8"\n" SECOND_LINE_UTF8"\n" ); ck_assert(RF_SUCCESS == rf_textfile_go_to_line(&f, 1)); /* read 1 line */ ck_assert(1 == rf_textfile_read_lines(&f, 1, &g_buff, 0)); ck_assert_rf_str_eq_cstr(&g_buff, FIRST_LINE_UTF8"\n"); rf_textfile_deinit(&f); }END_TEST