From 587084d2002d05c73d28eacf041816d96266cbe6 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 1 Oct 2026 20:33:00 -0500 Subject: [PATCH] Progress: Begin working on extended list, embedded list, and anything else. --- level_1/fl_fss/c/fss/basic_list.c | 2 +- level_1/fl_fss/c/fss/extended_list.c | 15 + .../embedded_list-combining_read-1.txt | 2 + .../embedded_list-combining_read-2.txt | 2 +- .../embedded_list-combining_read-3.txt | 2 +- .../embedded_list-combining_read-4.txt | 3 +- .../extended_list-combining_read-1.txt | 2 + .../extended_list-combining_read-2.txt | 2 +- .../extended_list-combining_read-3.txt | 2 +- .../extended_list-combining_read-4.txt | 3 +- .../extended_list-combining_read-5.txt | 1 - .../counts/extended_list-combining_read.txt | 5 + .../objects/embedded_list-combining_read.txt | 1 - .../objects/extended_list-combining_read.txt | 1 - .../strings/embedded_list-combining_read.txt | 6 +- .../strings/extended_list-combining_read.txt | 8 +- .../unit/c/test-fss-basic_content_read.c | 4 +- .../unit/c/test-fss-basic_list_content_read.c | 16 +- .../unit/c/test-fss-basic_list_object_read.c | 2 +- .../tests/unit/c/test-fss-basic_object_read.c | 5 +- .../c/test-fss-embedded_list_content_read.c | 16 +- .../c/test-fss-embedded_list_object_read.c | 4 +- .../unit/c/test-fss-extended_content_read.c | 5 +- .../c/test-fss-extended_list_content_read.c | 312 ++++++++++++------ .../c/test-fss-extended_list_object_read.c | 4 +- .../unit/c/test-fss-extended_object_read.c | 5 +- level_1/fl_fss/tests/unit/c/test-fss.c | 2 +- 27 files changed, 270 insertions(+), 162 deletions(-) delete mode 100644 level_1/fl_fss/data/tests/contents/extended_list-combining_read-5.txt create mode 100644 level_1/fl_fss/data/tests/counts/extended_list-combining_read.txt diff --git a/level_1/fl_fss/c/fss/basic_list.c b/level_1/fl_fss/c/fss/basic_list.c index a6477ca81..57f3fd1d3 100644 --- a/level_1/fl_fss/c/fss/basic_list.c +++ b/level_1/fl_fss/c/fss/basic_list.c @@ -49,12 +49,12 @@ extern "C" { const f_number_unsigned_t begin = range->start; found->array[found->used].start = range->start; + f_number_unsigned_t comment_delimit = 0; f_number_unsigned_t newline_last = begin; f_number_unsigned_t previous = 0; f_number_unsigned_t slash_first = 0; f_number_unsigned_t slash_count = 0; f_number_unsigned_t start = begin; - f_number_unsigned_t comment_delimit = 0; uint8_t flag_fl = ___fl_flag_has_graph_first___; diff --git a/level_1/fl_fss/c/fss/extended_list.c b/level_1/fl_fss/c/fss/extended_list.c index 7b7ea9ee9..ca367a9fd 100644 --- a/level_1/fl_fss/c/fss/extended_list.c +++ b/level_1/fl_fss/c/fss/extended_list.c @@ -37,14 +37,23 @@ extern "C" { state->status = f_memory_array_increase(state->step_small, sizeof(f_range_t), (void **) &found->array, &found->used, &found->size); if (F_status_is_error(state->status)) return; + #define ___fl_flag_do_escape___ 0x1 + #define ___fl_flag_has_graph_first___ 0x2 + #define ___fl_flag_has_graph_first_do_escape___ 0x3 + #define ___fl_flag_has_delimit_comment___ 0x4 + #define ___fl_flag_has_delimit_comment_graph_first___ 0x6 + const f_number_unsigned_t delimits_used = delimits->used; const f_number_unsigned_t comments_used = comments->used; f_number_unsigned_t line_start = range->start; f_number_unsigned_t newline_last = range->start; + f_number_unsigned_t previous = 0; f_number_unsigned_t slash_first = 0; f_number_unsigned_t comment_start = 0; + uint8_t flag_fl = ___fl_flag_has_graph_first___; + found->array[found->used].start = range->start; // Identify where the content ends. @@ -59,6 +68,7 @@ extern "C" { if (F_status_is_error(state->status)) break; if (state->status == F_okay_eol) { + flag_fl |= ___fl_flag_has_graph_first___; newline_last = range->start++; line_start = range->start; @@ -225,6 +235,11 @@ extern "C" { } state->status = F_fss_found_content_not; + + #undef ___fl_flag_do_escape___ + #undef ___fl_flag_has_graph_first___ + #undef ___fl_flag_has_delimit_comment___ + #undef ___fl_flag_has_delimit_comment_graph_first___ } #endif // _di_fl_fss_extended_list_content_read_ diff --git a/level_1/fl_fss/data/tests/contents/embedded_list-combining_read-1.txt b/level_1/fl_fss/data/tests/contents/embedded_list-combining_read-1.txt index 311e0a561..dc1e83021 100644 --- a/level_1/fl_fss/data/tests/contents/embedded_list-combining_read-1.txt +++ b/level_1/fl_fss/data/tests/contents/embedded_list-combining_read-1.txt @@ -1 +1,3 @@ is_second and content 2. + ́{ + has ́ content 3. diff --git a/level_1/fl_fss/data/tests/contents/embedded_list-combining_read-2.txt b/level_1/fl_fss/data/tests/contents/embedded_list-combining_read-2.txt index 652a208a4..96487d57a 100644 --- a/level_1/fl_fss/data/tests/contents/embedded_list-combining_read-2.txt +++ b/level_1/fl_fss/data/tests/contents/embedded_list-combining_read-2.txt @@ -1 +1 @@ - has ́ content 3. + has ͜no_space content 4. diff --git a/level_1/fl_fss/data/tests/contents/embedded_list-combining_read-3.txt b/level_1/fl_fss/data/tests/contents/embedded_list-combining_read-3.txt index 96487d57a..78c611949 100644 --- a/level_1/fl_fss/data/tests/contents/embedded_list-combining_read-3.txt +++ b/level_1/fl_fss/data/tests/contents/embedded_list-combining_read-3.txt @@ -1 +1 @@ - has ͜no_space content 4. + content 5. diff --git a/level_1/fl_fss/data/tests/contents/embedded_list-combining_read-4.txt b/level_1/fl_fss/data/tests/contents/embedded_list-combining_read-4.txt index 78c611949..a5e0c698b 100644 --- a/level_1/fl_fss/data/tests/contents/embedded_list-combining_read-4.txt +++ b/level_1/fl_fss/data/tests/contents/embedded_list-combining_read-4.txt @@ -1 +1,2 @@ - content 5. + sixtẖ̚ is content 6. + not a valid list {́ diff --git a/level_1/fl_fss/data/tests/contents/extended_list-combining_read-1.txt b/level_1/fl_fss/data/tests/contents/extended_list-combining_read-1.txt index 311e0a561..518af0b8f 100644 --- a/level_1/fl_fss/data/tests/contents/extended_list-combining_read-1.txt +++ b/level_1/fl_fss/data/tests/contents/extended_list-combining_read-1.txt @@ -1 +1,3 @@ + ́ is_second and content 2. + does have ́ content 3. diff --git a/level_1/fl_fss/data/tests/contents/extended_list-combining_read-2.txt b/level_1/fl_fss/data/tests/contents/extended_list-combining_read-2.txt index 652a208a4..96487d57a 100644 --- a/level_1/fl_fss/data/tests/contents/extended_list-combining_read-2.txt +++ b/level_1/fl_fss/data/tests/contents/extended_list-combining_read-2.txt @@ -1 +1 @@ - has ́ content 3. + has ͜no_space content 4. diff --git a/level_1/fl_fss/data/tests/contents/extended_list-combining_read-3.txt b/level_1/fl_fss/data/tests/contents/extended_list-combining_read-3.txt index 96487d57a..78c611949 100644 --- a/level_1/fl_fss/data/tests/contents/extended_list-combining_read-3.txt +++ b/level_1/fl_fss/data/tests/contents/extended_list-combining_read-3.txt @@ -1 +1 @@ - has ͜no_space content 4. + content 5. diff --git a/level_1/fl_fss/data/tests/contents/extended_list-combining_read-4.txt b/level_1/fl_fss/data/tests/contents/extended_list-combining_read-4.txt index 78c611949..51eaa89ac 100644 --- a/level_1/fl_fss/data/tests/contents/extended_list-combining_read-4.txt +++ b/level_1/fl_fss/data/tests/contents/extended_list-combining_read-4.txt @@ -1 +1,2 @@ - content 5. + sixtẖ̚ is content 6. + not a valid list{:́ diff --git a/level_1/fl_fss/data/tests/contents/extended_list-combining_read-5.txt b/level_1/fl_fss/data/tests/contents/extended_list-combining_read-5.txt deleted file mode 100644 index d7656943e..000000000 --- a/level_1/fl_fss/data/tests/contents/extended_list-combining_read-5.txt +++ /dev/null @@ -1 +0,0 @@ - sixtẖ̚ is content 6. diff --git a/level_1/fl_fss/data/tests/counts/extended_list-combining_read.txt b/level_1/fl_fss/data/tests/counts/extended_list-combining_read.txt new file mode 100644 index 000000000..627e1097c --- /dev/null +++ b/level_1/fl_fss/data/tests/counts/extended_list-combining_read.txt @@ -0,0 +1,5 @@ +1 +1 +1 +1 +1 diff --git a/level_1/fl_fss/data/tests/objects/embedded_list-combining_read.txt b/level_1/fl_fss/data/tests/objects/embedded_list-combining_read.txt index d2132bf51..b540243f9 100644 --- a/level_1/fl_fss/data/tests/objects/embedded_list-combining_read.txt +++ b/level_1/fl_fss/data/tests/objects/embedded_list-combining_read.txt @@ -1,6 +1,5 @@ first valid. is_second and does not have embedded new line. - ́ fourth ͜no_space fifth is valid. sixtẖ̚ is valid with two combiners. diff --git a/level_1/fl_fss/data/tests/objects/extended_list-combining_read.txt b/level_1/fl_fss/data/tests/objects/extended_list-combining_read.txt index d2132bf51..b540243f9 100644 --- a/level_1/fl_fss/data/tests/objects/extended_list-combining_read.txt +++ b/level_1/fl_fss/data/tests/objects/extended_list-combining_read.txt @@ -1,6 +1,5 @@ first valid. is_second and does not have embedded new line. - ́ fourth ͜no_space fifth is valid. sixtẖ̚ is valid with two combiners. diff --git a/level_1/fl_fss/data/tests/strings/embedded_list-combining_read.txt b/level_1/fl_fss/data/tests/strings/embedded_list-combining_read.txt index 433b56920..a20d70e1a 100644 --- a/level_1/fl_fss/data/tests/strings/embedded_list-combining_read.txt +++ b/level_1/fl_fss/data/tests/strings/embedded_list-combining_read.txt @@ -3,10 +3,10 @@ first valid.{ } is_second and does not have embedded new line.{ is_second and content 2. -} ́{ has ́ content 3. } +} fourth ͜no_space{ has ͜no_space content 4. } @@ -15,6 +15,6 @@ fifth is valid.{ } sixtẖ̚ is valid with two combiners.{ sixtẖ̚ is content 6. -} - not a valid list{́ + not a valid list {́ + } } diff --git a/level_1/fl_fss/data/tests/strings/extended_list-combining_read.txt b/level_1/fl_fss/data/tests/strings/extended_list-combining_read.txt index 433b56920..9b8083371 100644 --- a/level_1/fl_fss/data/tests/strings/extended_list-combining_read.txt +++ b/level_1/fl_fss/data/tests/strings/extended_list-combining_read.txt @@ -2,10 +2,9 @@ first valid.{ content 1. } is_second and does not have embedded new line.{ +́ is_second and content 2. -} - ́{ - has ́ content 3. + does have ́ content 3. } fourth ͜no_space{ has ͜no_space content 4. @@ -15,6 +14,5 @@ fifth is valid.{ } sixtẖ̚ is valid with two combiners.{ sixtẖ̚ is content 6. -} - not a valid list{́ + not a valid list{:́ } diff --git a/level_1/fl_fss/tests/unit/c/test-fss-basic_content_read.c b/level_1/fl_fss/tests/unit/c/test-fss-basic_content_read.c index 511fec3ef..89bbf6a2f 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-basic_content_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-basic_content_read.c @@ -133,7 +133,7 @@ void test__fl_fss_basic_content_read__works(void **void_state) { assert_return_code(result, 0); // The newline is copied by getline(), and so remove that newline before comparing. - line_content[result - 1] = 0; + line_content[result ? result - 1 : 0] = 0; state.status = F_none; range.start = 0; @@ -325,7 +325,7 @@ void test__fl_fss_basic_content_read__works_using_combining(void **void_state) { assert_return_code(result, 0); // The newline is copied by getline(), and so remove that newline before comparing. - line_content[result - 1] = 0; + line_content[result ? result - 1 : 0] = 0; state.status = F_none; range.start = 0; diff --git a/level_1/fl_fss/tests/unit/c/test-fss-basic_list_content_read.c b/level_1/fl_fss/tests/unit/c/test-fss-basic_list_content_read.c index 76cbf1f03..f9dc447ad 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-basic_list_content_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-basic_list_content_read.c @@ -203,12 +203,7 @@ void test__fl_fss_basic_list_content_read__works(void **void_state) { result = getline(&line_content[i], &max, file_contents[i]); // The newline is copied by getline(), and so remove that newline before comparing. - if (result > 0) { - line_content[i][result - 1] = 0; - } - else { - line_content[i][0] = 0; - } + line_content[i][result > 0 ? result - 1 : 0] = 0; } // or state.status = F_none; @@ -434,15 +429,10 @@ void test__fl_fss_basic_list_content_read__works_using_combining(void **void_sta printf("[ -------> ] --- [03] Failure with getline() for objects, with set %lu, result is negative.\n", set); } - assert_true(result >= 0); + assert_return_code(result, 0); // The newline is copied by getline(), and so remove that newline before comparing. - if (result) { - line_object[result - 1] = 0; - } - else { - line_object[0] = 0; - } + line_object[result ? result - 1 : 0] = 0; max = 255; diff --git a/level_1/fl_fss/tests/unit/c/test-fss-basic_list_object_read.c b/level_1/fl_fss/tests/unit/c/test-fss-basic_list_object_read.c index 8a195db3c..d23a14dca 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-basic_list_object_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-basic_list_object_read.c @@ -144,7 +144,7 @@ void test__fl_fss_basic_list_object_read__works(void **void_state) { assert_return_code(result, 0); // The newline is copied by getline(), and so remove that newline before comparing. - line_object[result - 1] = 0; + line_object[result ? result - 1 : 0] = 0; if (found.start <= found.stop) { { diff --git a/level_1/fl_fss/tests/unit/c/test-fss-basic_object_read.c b/level_1/fl_fss/tests/unit/c/test-fss-basic_object_read.c index 24ec27b60..e97030e37 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-basic_object_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-basic_object_read.c @@ -173,10 +173,11 @@ void test__fl_fss_basic_object_read__works(void **void_state) { max = 255; result = getline(&line_object, &max, file_objects); + assert_return_code(result, 0); // The newline is copied by getline(), and so remove that newline before comparing. - line_object[result - 1] = 0; + line_object[result ? result - 1 : 0] = 0; state.status = F_none; range.start = 0; @@ -299,7 +300,7 @@ void test__fl_fss_basic_object_read__works_using_combining(void **void_state) { assert_return_code(result, 0); // The newline is copied by getline(), and so remove that newline before comparing. - line_object[result - 1] = 0; + line_object[result ? result - 1 : 0] = 0; state.status = F_none; range.start = 0; diff --git a/level_1/fl_fss/tests/unit/c/test-fss-embedded_list_content_read.c b/level_1/fl_fss/tests/unit/c/test-fss-embedded_list_content_read.c index 906783f84..de6241d7d 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-embedded_list_content_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-embedded_list_content_read.c @@ -248,12 +248,7 @@ void test__fl_fss_embedded_list_content_read__works(void **void_state) { result = getline(&line_content[i], &max, file_contents[i]); // The newline is copied by getline(), and so remove that newline before comparing. - if (result > 0) { - line_content[i][result - 1] = 0; - } - else { - line_content[i][0] = 0; - } + line_content[i][result > 0 ? result - 1 : 0] = 0; } // or state.status = F_none; @@ -417,13 +412,10 @@ void test__fl_fss_embedded_list_content_read__works_using_combining(void **void_ result = getline(&line_content[i], &max, file_contents[i]); + assert_return_code(result, 0); + // The newline is copied by getline(), and so remove that newline before comparing. - if (result > 0) { - line_content[i][result - 1] = 0; - } - else { - line_content[i][0] = 0; - } + line_content[i][result ? result - 1 : 0] = 0; } // or state.status = F_none; diff --git a/level_1/fl_fss/tests/unit/c/test-fss-embedded_list_object_read.c b/level_1/fl_fss/tests/unit/c/test-fss-embedded_list_object_read.c index 0ed8f7507..10cef3d75 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-embedded_list_object_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-embedded_list_object_read.c @@ -144,7 +144,7 @@ void test__fl_fss_embedded_list_object_read__works(void **void_state) { assert_return_code(result, 0); // The newline is copied by getline(), and so remove that newline before comparing. - line_object[result - 1] = 0; + line_object[result ? result - 1 : 0] = 0; if (found.start <= found.stop) { { @@ -292,7 +292,7 @@ void test__fl_fss_embedded_list_object_read__works_using_combining(void **void_s assert_return_code(result, 0); // The newline is copied by getline(), and so remove that newline before comparing. - line_object[result - 1] = 0; + line_object[result ? result - 1 : 0] = 0; if (found.start <= found.stop) { { diff --git a/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.c b/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.c index 521858b07..693a3dcc6 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.c @@ -205,10 +205,9 @@ void test__fl_fss_extended_content_read__works(void **void_state) { max = 255; result = getline(&line_content[i], &max, file_contents[i]); - assert_return_code(result, 0); // The newline is copied by getline(), and so remove that newline before comparing. - line_content[i][result - 1] = 0; + line_content[i][result > 0 ? result - 1 : 0] = 0; } // or state.status = F_none; @@ -415,7 +414,7 @@ void test__fl_fss_extended_content_read__works_using_combining(void **void_state assert_return_code(result, 0); // The newline is copied by getline(), and so remove that newline before comparing. - line_content[i][result - 1] = 0; + line_content[i][result ? result - 1 : 0] = 0; } // for state.status = F_none; diff --git a/level_1/fl_fss/tests/unit/c/test-fss-extended_list_content_read.c b/level_1/fl_fss/tests/unit/c/test-fss-extended_list_content_read.c index 85118934b..8b26865d2 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-extended_list_content_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-extended_list_content_read.c @@ -334,12 +334,7 @@ void test__fl_fss_extended_list_content_read__works(void **void_state) { result = getline(&line_content[i], &max, file_contents[i]); // The newline is copied by getline(), and so remove that newline before comparing. - if (result > 0) { - line_content[i][result - 1] = 0; - } - else { - line_content[i][0] = 0; - } + line_content[i][result > 0 ? result - 1 : 0] = 0; } // or state.status = F_none; @@ -465,6 +460,9 @@ void test__fl_fss_extended_list_content_read__works_using_combining(void **void_ { // Note: These files are required to have the same number of lines and each line should probably be at max 255 characters. + FILE *file_counts = data__file_open__named("counts", "extended_list", "combining_read"); + FILE *file_matches = data__file_open__named("matches", "extended_list", "combining_read"); + FILE *file_objects = data__file_open__named("objects", "extended_list", "combining_read"); FILE *file_strings = data__file_open__named("strings", "extended_list", "combining_read"); FILE *file_contents[] = { @@ -473,183 +471,289 @@ void test__fl_fss_extended_list_content_read__works_using_combining(void **void_ data__file_open__named_at("contents", "extended_list", "combining_read", 2), data__file_open__named_at("contents", "extended_list", "combining_read", 3), data__file_open__named_at("contents", "extended_list", "combining_read", 4), - data__file_open__named_at("contents", "extended_list", "combining_read", 5), }; + assert_non_null(file_counts); + assert_non_null(file_matches); + assert_non_null(file_objects); assert_non_null(file_strings); assert_non_null(file_contents[0]); assert_non_null(file_contents[1]); assert_non_null(file_contents[2]); assert_non_null(file_contents[3]); assert_non_null(file_contents[4]); - assert_non_null(file_contents[5]); + const uint8_t sets_total = 5; + + int counts = 0; + int matches = 0; size_t max = 0; - char *line_string = 0; - char *line_content[] = { - 0, - 0, - 0, - 0, - 0, - 0, - }; ssize_t result = 0; - const uint8_t total_content = 6; - f_string_static_t buffer_string = f_string_static_t_initialize; + char *line_counts = 0; + char *line_matches = 0; + char *line_object = 0; - f_state_t state = f_state_t_initialize; f_range_t close = f_range_t_initialize; f_range_t range = f_range_t_initialize; f_range_t found_object = f_range_t_initialize; - f_ranges_t found = f_ranges_t_initialize; + f_ranges_t found_content = f_ranges_t_initialize; f_ranges_t comments = f_ranges_t_initialize; + + f_state_t state = f_state_t_initialize; + f_status_t status_object = F_okay; f_uint8s_t quotes = f_uint8s_t_initialize; f_number_unsigneds_t delimits = f_number_unsigneds_t_initialize; - f_string_dynamic_t result_string = f_string_dynamic_t_initialize; - f_string_dynamic_t delimit_string = f_string_dynamic_t_initialize; - f_status_t status_object = F_okay; - for (;;) { + f_string_dynamic_t set_delimit = f_string_dynamic_t_initialize; + f_string_dynamic_t set_result = f_string_dynamic_t_initialize; + f_string_dynamic_t set_strings = f_string_dynamic_t_initialize; + + f_string_dynamic_t set_contents[] = { + macro_f_string_dynamic_t_initialize_2(0, 0), + macro_f_string_dynamic_t_initialize_2(0, 0), + macro_f_string_dynamic_t_initialize_2(0, 0), + macro_f_string_dynamic_t_initialize_2(0, 0), + macro_f_string_dynamic_t_initialize_2(0, 0), + }; + + { + const f_status_t status = data__file_load_buffer(file_strings, &set_strings); + + if (F_status_is_error(status)) { + printf("[ -------> ] --- [00] Failure with data__file_load_buffer() for loading file strings, status=%u has error bit set.\n", status); + } + + assert_true(F_status_is_error_not(status)); + } + + for (uint8_t i = 0; i < sets_total; ++i) { + + const f_status_t status = data__file_load_buffer(file_contents[i], &set_contents[i]); + + if (F_status_is_error(status)) { + printf("[ -------> ] --- [01] Failure with data__file_load_buffer() for loading file contents at %u, status=%u has error bit set.\n", i, status); + } + + assert_true(F_status_is_error_not(state.status)); + } // for + + { + const f_status_t status = f_string_dynamic_append(set_strings, &set_delimit); + + if (status != F_okay) { + printf("[ -------> ] --- [02] Failure with f_string_dynamic_append() for preparing delimit string, status=%u, expected=%u.\n", status, F_okay); + } + + assert_int_equal(status, F_okay); + } + + range.start = 0; + range.stop = set_strings.used - 1; + + for (f_number_unsigned_t set = 0; set < sets_total; ++set) { max = 255; - result = getline(&line_string, &max, file_strings); - if (result == -1) break; + result = getline(&line_object, &max, file_objects); - buffer_string.string = line_string; - buffer_string.used = (f_number_unsigned_t) result; - buffer_string.size = buffer_string.used; + if (result < 0) { + printf("[ -------> ] --- [03] Failure with getline() for objects, with set %lu, result is negative.\n", set); + } - for (uint8_t i = 0; i < total_content; ++i) { + assert_return_code(result, 0); - max = 255; + // The newline is copied by getline(), and so remove that newline before comparing. + line_object[result ? result - 1 : 0] = 0; - result = getline(&line_content[i], &max, file_contents[i]); + max = 255; - // The newline is copied by getline(), and so remove that newline before comparing. - if (result > 0) { - line_content[i][result - 1] = 0; - } - } // or + result = getline(&line_matches, &max, file_matches); + + if (result < 0) { + printf("[ -------> ] --- [04] Failure with getline() for matches, with set %lu, result is negative.\n", set); + } + + assert_true(result >= 0); + + matches = atoi(line_matches); - state.status = F_none; - range.start = 0; - range.stop = buffer_string.used - 1; found_object.start = 1; found_object.stop = 0; + state.status = F_none; - fl_fss_extended_list_object_read(buffer_string, &range, &found_object, &delimits, &state); + fl_fss_extended_list_object_read(set_strings, &range, &found_object, &delimits, &state); - assert_true(state.status == F_fss_found_object || state.status == F_fss_found_object_not); + if (matches) { + + // When matches is 2, then this matches both object and content. + if (matches == 2) { + if (!(state.status == F_fss_found_object)) { + printf("[ -------> ] --- [05] Failure with fl_fss_extended_list_object_read(), with set %lu, matches=%d, status=%u, expected %u.\n", set, matches, state.status, F_fss_found_object); + } + + assert_true(state.status == F_fss_found_object); + } + + // When matches is 1, then this matches only object. + else { + if (!(state.status == F_fss_found_object_content_not)) { + printf("[ -------> ] --- [06] Failure with fl_fss_extended_list_object_read(), with set %lu, matches=%d, status=%u, expected %u.\n", set, matches, state.status, F_fss_found_object_content_not); + } + + assert_true(state.status == F_fss_found_object_content_not); + } + } + else { + if (!(state.status == F_fss_found_object_not)) { + printf("[ -------> ] --- [07] Failure with with fl_fss_extended_list_object_read(), set %lu, matches=%d, status=%u, expected %u.\n", set, matches, state.status, F_fss_found_object_not); + } + + assert_true(state.status == F_fss_found_object_not); + } status_object = state.status; state.status = F_none; if (status_object == F_fss_found_object) { - fl_fss_extended_list_content_read(buffer_string, &range, &found, &close, &delimits, &comments, &state); + + // The Object had to be read before getting to the Content, so test it as well. + { + const f_status_t status = data__extract_from_source(set_strings, found_object, &set_result); + + if (F_status_is_error(status)) { + printf("[ -------> ] --- [14] Failure with data__extract_from_source() for extract object, with set %lu, status=%u has error bit set.\n", set, status); + } + + assert_true(F_status_is_error_not(status)); + } + + if (strcmp(set_result.string, line_object)) { + printf("[ -------> ] --- [09] Failure with set %lu, object strings do not match.\n", set); + } + + assert_string_equal(set_result.string, line_object); + + max = 255; + + result = getline(&line_counts, &max, file_counts); + + if (result < 0) { + printf("[ -------> ] --- [10] Failure with getline() for counts, with set %lu, result is negative.\n", set); + } + + assert_true(result >= 0); + + counts = atoi(line_counts); + + fl_fss_extended_list_content_read(set_strings, &range, &found_content, &close, &delimits, &comments, &state); + + if (!(state.status == F_fss_found_content || state.status == F_data_not)) { + printf("[ -------> ] --- [11] Failure with fl_fss_extended_list_content_read(), with set %lu, status=%u, expected %u, or %u.\n", set, state.status, F_fss_found_content, F_data_not); + } assert_true(state.status == F_fss_found_content || state.status == F_data_not); if (state.status == F_fss_found_content) { - assert_true(found.used); - assert_true(found.used <= (f_number_unsigned_t) total_content); - - { - const f_status_t status = f_string_dynamic_append(buffer_string, &delimit_string); - assert_int_equal(status, F_okay); + if (!found_content.used) { + printf("[ -------> ] --- [12] Failure with fl_fss_extended_list_content_read(), with set %lu, expected found_content.used (%lu) <> 0.\n", set, found_content.used); } - state.status = F_none; + assert_true(found_content.used); - f_fss_apply_delimit(delimits, &delimit_string, &state); - assert_int_equal(state.status, F_okay); + if (found_content.used != (f_number_unsigned_t) counts) { + printf("[ -------> ] --- [13] Failure with fl_fss_extended_list_content_read(), with set %lu, expected found_content.used (%lu) == %lu, found = '%s', expected = '%s'.\n", set, found_content.used, (f_number_unsigned_t) counts, set_result.string ? set_result.string : "", set_contents[set].string ? set_contents[set].string : ""); + } - { - uint8_t i = 0; + assert_true(found_content.used == (f_number_unsigned_t) counts); - for (; i < found.used; ++i) { + state.status = F_none; - result_string.used = 0; + f_fss_apply_delimit(delimits, &set_delimit, &state); - { - const f_status_t status = f_string_dynamic_partial_append_nulless(delimit_string, found.array[i], &result_string); - assert_true(status == F_okay || status == F_data_not_eos); - } + if (state.status != F_okay) { + printf("[ -------> ] --- [14] Failure with f_fss_apply_delimit(), with set %lu, status=%u, expected=%u.\n", set, state.status, F_okay); + } - { - const f_status_t status = f_string_dynamic_terminate_after(&result_string); - assert_int_equal(status, F_okay); - } + assert_int_equal(state.status, F_okay); - assert_string_equal(result_string.string, line_content[i]); - } // for + { + const f_status_t status = data__extract_from_source(set_delimit, found_content.array[0], &set_result); - // All remaining positions in the file need to be a zero length string. - for (; i < total_content; ++i) { - assert_int_equal(line_content[i][0], 0); + if (F_status_is_error(status)) { + printf("[ -------> ] --- [15] Failure with data__extract_from_source() for extract set contents, with set %lu, status=%u has error bit set.\n", set, status); } + + assert_true(F_status_is_error_not(status)); + } + + if (strcmp(set_result.string, set_contents[set].string)) { + printf("[ -------> ] --- [16] Failure with set %lu, content strings do not match.\n", set); } + + assert_string_equal(set_result.string, set_contents[set].string); } else { - assert_true(!found.used); + if (found_content.used) { + printf("[ -------> ] --- [17] Failure with set %lu, should not have any content, but match %lu.\n", set, found_content.used); + } + + assert_true(!found_content.used); } } - if (line_string) free(line_string); - if (result_string.string) free(result_string.string); - if (delimit_string.string) free(delimit_string.string); - if (delimits.array) free(delimits.array); - if (found.array) free(found.array); if (comments.array) free(comments.array); + if (delimits.array) free(delimits.array); + if (found_content.array) free(found_content.array); if (quotes.array) free(quotes.array); - for (uint8_t i = 0; i < total_content; ++i) { - - if (line_content[i]) free(line_content[i]); - - line_content[i] = 0; - } // for + if (line_counts) free(line_counts); + if (line_matches) free(line_matches); + if (line_object) free(line_object); + if (set_result.string) free(set_result.string); - line_string = 0; - result_string.string = 0; - result_string.used = 0; - result_string.size = 0; - delimit_string.string = 0; - delimit_string.used = 0; - delimit_string.size = 0; - delimits.array = 0; - delimits.used = 0; - delimits.size = 0; - found.array = 0; - found.used = 0; - found.size = 0; comments.array = 0; comments.used = 0; comments.size = 0; + delimits.array = 0; + delimits.used = 0; + delimits.size = 0; + found_content.array = 0; + found_content.used = 0; + found_content.size = 0; + line_counts = 0; + line_matches = 0; + line_object = 0; quotes.array = 0; quotes.used = 0; quotes.size = 0; + set_result.string = 0; + set_result.used = 0; + set_result.size = 0; } // for - for (uint8_t i = 0; i < total_content; ++i) { + for (uint8_t i = 0; i < sets_total; ++i) { if (file_contents[i]) fclose(file_contents[i]); - if (line_content[i]) free(line_content[i]); - - line_content[i] = 0; + if (set_contents[i].string) free(set_contents[i].string); } // for + if (line_counts) free(line_counts); + if (line_matches) free(line_matches); + if (line_object) free(line_object); + if (set_delimit.string) free(set_delimit.string); + if (set_result.string) free(set_result.string); + if (set_strings.string) free(set_strings.string); + + if (file_counts) fclose(file_counts); + if (file_matches) fclose(file_matches); + if (file_objects) fclose(file_objects); if (file_strings) fclose(file_strings); - if (delimits.array) free(delimits.array); - if (found.array) free(found.array); if (comments.array) free(comments.array); + if (delimits.array) free(delimits.array); + if (found_content.array) free(found_content.array); if (quotes.array) free(quotes.array); - if (line_string) free(line_string); - if (result_string.string) free(result_string.string); - if (delimit_string.string) free(delimit_string.string); } } diff --git a/level_1/fl_fss/tests/unit/c/test-fss-extended_list_object_read.c b/level_1/fl_fss/tests/unit/c/test-fss-extended_list_object_read.c index 90ae13ecf..c18531f75 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-extended_list_object_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-extended_list_object_read.c @@ -144,7 +144,7 @@ void test__fl_fss_extended_list_object_read__works(void **void_state) { assert_return_code(result, 0); // The newline is copied by getline(), and so remove that newline before comparing. - line_object[result - 1] = 0; + line_object[result ? result - 1 : 0] = 0; if (found.start <= found.stop) { { @@ -292,7 +292,7 @@ void test__fl_fss_extended_list_object_read__works_using_combining(void **void_s assert_return_code(result, 0); // The newline is copied by getline(), and so remove that newline before comparing. - line_object[result - 1] = 0; + line_object[result ? result - 1 : 0] = 0; if (found.start <= found.stop) { { diff --git a/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.c b/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.c index c5f79d174..028382ae7 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.c @@ -189,10 +189,11 @@ void test__fl_fss_extended_object_read__works(void **void_state) { max = 255; result = getline(&line_object, &max, file_objects); + assert_return_code(result, 0); // The newline is copied by getline(), and so remove that newline before comparing. - line_object[result - 1] = 0; + line_object[result ? result - 1 : 0] = 0; state.status = F_none; range.start = 0; @@ -315,7 +316,7 @@ void test__fl_fss_extended_object_read__works_using_combining(void **void_state) assert_return_code(result, 0); // The newline is copied by getline(), and so remove that newline before comparing. - line_object[result - 1] = 0; + line_object[result ? result - 1 : 0] = 0; state.status = F_none; range.start = 0; diff --git a/level_1/fl_fss/tests/unit/c/test-fss.c b/level_1/fl_fss/tests/unit/c/test-fss.c index c2d31f482..f7429c7a8 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss.c +++ b/level_1/fl_fss/tests/unit/c/test-fss.c @@ -65,7 +65,7 @@ int main(void) { cmocka_unit_test(test__fl_fss_extended_list_object_write__returns_data_not), cmocka_unit_test(test__fl_fss_extended_list_content_read__works), - //cmocka_unit_test(test__fl_fss_extended_list_content_read__works_using_combining), + cmocka_unit_test(test__fl_fss_extended_list_content_read__works_using_combining), cmocka_unit_test(test__fl_fss_extended_list_object_read__works), // fl_fss_extended_list_object_read() combining check is handled by test__fl_fss_extended_list_content_read__works_using_combining(). -- 2.52.0