From: Kevin Day Date: Tue, 20 Aug 2024 03:00:46 +0000 (-0500) Subject: Update: FSS Read unit tests to handle trailing space when dealing with --line. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=d7e458ece486134c9002c453935a1ae861efbe0f;p=fll Update: FSS Read unit tests to handle trailing space when dealing with --line. The tests now handle the `--line` parameter such that a trailing space is not printed. The code is now updated to handle this behavior. --- diff --git a/level_3/fss_read/c/main/print/data.c b/level_3/fss_read/c/main/print/data.c index c9e2c84..9476cfc 100644 --- a/level_3/fss_read/c/main/print/data.c +++ b/level_3/fss_read/c/main/print/data.c @@ -35,12 +35,12 @@ extern "C" { if (main->setting.select < main->setting.contents.array[at].used && main->setting.contents.array[at].array[main->setting.select].start <= main->setting.contents.array[at].array[main->setting.select].stop) { if (main->callback.print_content && main->callback.print_object_end_content) { if (print_state & 0x1) { - if (main->callback.print_object_end_content(&main->program.output, main->setting.contents.array[at].array[main->setting.select], main->setting.quotes_content.array[at].used ? main->setting.quotes_content.array[at].array[main->setting.select] : 0, delimits_content) != F_output_not) { + if (F_status_set_fine(main->callback.print_object_end_content(&main->program.output, main->setting.contents.array[at].array[main->setting.select], main->setting.quotes_content.array[at].used ? main->setting.quotes_content.array[at].array[main->setting.select] : 0, delimits_content)) != F_output_not) { print_state |= 0x6; } } else { - if (main->callback.print_content(&main->program.output, main->setting.contents.array[at].array[main->setting.select], main->setting.quotes_content.array[at].used ? main->setting.quotes_content.array[at].array[main->setting.select] : 0, delimits_content) != F_output_not) { + if (F_status_set_fine(main->callback.print_content(&main->program.output, main->setting.contents.array[at].array[main->setting.select], main->setting.quotes_content.array[at].used ? main->setting.quotes_content.array[at].array[main->setting.select] : 0, delimits_content)) != F_output_not) { print_state |= 0x2; } } @@ -63,13 +63,12 @@ extern "C" { print_state &= ~0x8; if (print_state & 0x1) { - if (main->callback.print_object_end_content(&main->program.output, main->setting.contents.array[at].array[i], main->setting.quotes_content.array[at].used ? main->setting.quotes_content.array[at].array[i] : 0, delimits_content) != F_output_not) { + if (F_status_set_fine(main->callback.print_object_end_content(&main->program.output, main->setting.contents.array[at].array[i], main->setting.quotes_content.array[at].used ? main->setting.quotes_content.array[at].array[i] : 0, delimits_content)) != F_output_not) { print_state |= 0x6; } } - else {if (main->callback.print_content(&main->program.output, main->setting.contents.array[at].array[i], main->setting.quotes_content.array[at].used ? main->setting.quotes_content.array[at].array[i] : 0, delimits_content) != F_output_not) { - print_state |= 0x2; - } + else if (F_status_set_fine(main->callback.print_content(&main->program.output, main->setting.contents.array[at].array[i], main->setting.quotes_content.array[at].used ? main->setting.quotes_content.array[at].array[i] : 0, delimits_content)) != F_output_not) { + print_state |= 0x2; } ++i; diff --git a/level_3/fss_read/c/main/process_normal.c b/level_3/fss_read/c/main/process_normal.c index 157aa9e..22bfd55 100644 --- a/level_3/fss_read/c/main/process_normal.c +++ b/level_3/fss_read/c/main/process_normal.c @@ -192,17 +192,22 @@ extern "C" { fss_read_main_t * const main = (fss_read_main_t *) void_main; + // 0x1 = object printed, 0x2 = content printed, 0x4 = object end printed, 0x8 = content is empty, 0x10 = select is out of range. + uint8_t print_state = 0x0; + if (main->setting.flag & fss_read_main_flag_object_d) { if (*line == main->setting.line) { if (main->callback.print_object) { - main->callback.print_object(&main->program.output, at, delimits_object); - } - - if (main->callback.print_object_end) { - main->callback.print_object_end(&main->program.output); + if (F_status_set_fine(main->callback.print_object(&main->program.output, at, delimits_object)) != F_output_not) { + print_state = 0x1; + } } if (!(main->setting.flag & fss_read_main_flag_content_d)) { + if (main->callback.print_object_end) { + main->callback.print_object_end(&main->program.output); + } + if (!(main->setting.flag & fss_read_main_flag_object_as_line_d)) { if (main->callback.print_set_end) { main->callback.print_set_end(&main->program.output); @@ -213,6 +218,12 @@ extern "C" { return; } + + if (main->setting.flag & fss_read_main_flag_object_as_line_d && main->callback.print_object_end) { + if (F_status_set_fine(main->callback.print_object_end(&main->program.output)) != F_output_not) { + print_state = 0x4; + } + } } if ((main->setting.flag & fss_read_main_flag_object_as_line_d) || !(main->setting.flag & fss_read_main_flag_content_d)) { @@ -279,16 +290,32 @@ extern "C" { if (main->setting.flag & fss_read_main_flag_line_single_d) { if (*line == main->setting.line) { - if (main->setting.contents.array[at].used) { - for (;;) { + if (main->setting.contents.array[at].used && main->callback.print_content && main->callback.print_object_end_content) { + for (f_status_t printed = F_okay; ; ) { + + if (main->setting.contents.array[at].array[i].start <= main->setting.contents.array[at].array[i].stop) { + if ((print_state & 0x1) && !(print_state & 0x4)) { + printed = main->callback.print_object_end_content(&main->program.output, main->setting.contents.array[at].array[i], main->setting.quotes_content.array[at].array[i], delimits_content); + + if (F_status_set_fine(printed) != F_output_not) { + print_state |= 0x6; + } + } + else { + printed = main->callback.print_content(&main->program.output, main->setting.contents.array[at].array[i], main->setting.quotes_content.array[at].array[i], delimits_content); - if (main->callback.print_content) { - main->callback.print_content(&main->program.output, main->setting.contents.array[at].array[i], main->setting.quotes_content.array[at].array[i], delimits_content); + if (F_status_set_fine(printed) != F_output_not) { + print_state |= 0x2; + } + } + } + else { + printed = F_output_not; } if (++i >= main->setting.contents.array[at].used) break; - if (main->callback.print_content_next) { + if (F_status_set_fine(printed) != F_output_not && main->callback.print_content_next) { main->callback.print_content_next(&main->program.output); } } // for @@ -305,7 +332,7 @@ extern "C" { ++(*line); } - else { + else if (main->callback.print_content && main->callback.print_object_end_content) { f_number_unsigned_t j = 0; f_number_unsigned_t k = 0; @@ -336,7 +363,10 @@ extern "C" { if (*line == main->setting.line) { main->setting.range.stop = j; - if (main->callback.print_content) { + if ((print_state & 0x1) && !(print_state & 0x4)) { + main->callback.print_object_end_content(&main->program.output, main->setting.range, main->setting.quotes_content.array[at].array[i], delimits_content); + } + else { main->callback.print_content(&main->program.output, main->setting.range, main->setting.quotes_content.array[at].array[i], delimits_content); } diff --git a/level_3/fss_read/tests/runtime/fss_0000/expect/test-0001-unicode-object_and_content-line-6-original.expect b/level_3/fss_read/tests/runtime/fss_0000/expect/test-0001-unicode-object_and_content-line-6-original.expect index 0b5d6ed..45b983b 100644 --- a/level_3/fss_read/tests/runtime/fss_0000/expect/test-0001-unicode-object_and_content-line-6-original.expect +++ b/level_3/fss_read/tests/runtime/fss_0000/expect/test-0001-unicode-object_and_content-line-6-original.expect @@ -1 +1 @@ -hi +hi diff --git a/level_3/fss_read/tests/runtime/fss_0000/expect/test-0001-unicode-object_and_content-line-6.expect b/level_3/fss_read/tests/runtime/fss_0000/expect/test-0001-unicode-object_and_content-line-6.expect index 0b5d6ed..45b983b 100644 --- a/level_3/fss_read/tests/runtime/fss_0000/expect/test-0001-unicode-object_and_content-line-6.expect +++ b/level_3/fss_read/tests/runtime/fss_0000/expect/test-0001-unicode-object_and_content-line-6.expect @@ -1 +1 @@ -hi +hi diff --git a/level_3/fss_read/tests/runtime/fss_0001/expect/test-0001-unicode-object_and_content-line-6-original.expect b/level_3/fss_read/tests/runtime/fss_0001/expect/test-0001-unicode-object_and_content-line-6-original.expect index 0b5d6ed..45b983b 100644 --- a/level_3/fss_read/tests/runtime/fss_0001/expect/test-0001-unicode-object_and_content-line-6-original.expect +++ b/level_3/fss_read/tests/runtime/fss_0001/expect/test-0001-unicode-object_and_content-line-6-original.expect @@ -1 +1 @@ -hi +hi diff --git a/level_3/fss_read/tests/runtime/fss_0001/expect/test-0001-unicode-object_and_content-line-6.expect b/level_3/fss_read/tests/runtime/fss_0001/expect/test-0001-unicode-object_and_content-line-6.expect index 0b5d6ed..45b983b 100644 --- a/level_3/fss_read/tests/runtime/fss_0001/expect/test-0001-unicode-object_and_content-line-6.expect +++ b/level_3/fss_read/tests/runtime/fss_0001/expect/test-0001-unicode-object_and_content-line-6.expect @@ -1 +1 @@ -hi +hi