aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2025-07-12 12:28:57 -0400
committerEugene Triguba <eugenetriguba@gmail.com>2025-07-12 12:28:57 -0400
commit62c324f89216da1c311c8225f6c9087e441734de (patch)
tree89b60475d217bb1bbc9de91d43b243055124b2e5 /tests
parentRemove unnecesary if statement and fix memset (diff)
downloadcli-62c324f89216da1c311c8225f6c9087e441734de.zip
Simplify justify function and add additional read_word test
Diffstat (limited to 'tests')
-rw-r--r--tests/test_word.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/test_word.c b/tests/test_word.c
index aa58a34..54dbf45 100644
--- a/tests/test_word.c
+++ b/tests/test_word.c
@@ -125,6 +125,24 @@ void test_read_word_empty_input(void **state) {
}
/**
+ * GIVEN an input string that is only whitespace characters
+ * WHEN we read a word from the file
+ * THEN we expect to get EOF on read
+ */
+void test_read_word_input_with_only_spaces(void **state) {
+ const char *input = " \t\t\n\n";
+ const char *expected = "";
+ FILE *fp = create_tmp_file(input);
+ char word[100];
+
+ int result = read_word(fp, word, sizeof(word));
+
+ assert_int_equal(result, READ_WORD_ERR_EOF);
+ assert_string_equal(word, expected);
+ fclose(fp);
+}
+
+/**
* GIVEN a NULL input
* WHEN we read a word from the file
* THEN we expect to get a read error
@@ -198,6 +216,7 @@ int main(void) {
cmocka_unit_test(test_read_word_trailing_spaces),
cmocka_unit_test(test_read_word_multiple_spaces),
cmocka_unit_test(test_read_word_empty_input),
+ cmocka_unit_test(test_read_word_input_with_only_spaces),
cmocka_unit_test(test_read_word_null_fp),
cmocka_unit_test(test_read_word_null_word),
cmocka_unit_test(test_read_word_zero_length),