| #include "../../unity/unity.h" |
| #include <string.h> |
| #include <stddef.h> |
|
|
| |
| void setUp(void) { |
| |
| } |
| void tearDown(void) { |
| |
| } |
|
|
| |
| |
| static void configure_default_delims(void) |
| { |
| |
| static char h[] = "\\:h"; |
| static char b[] = "\\:b"; |
| static char f[] = "\\:f"; |
|
|
| |
| |
| section_del = DEFAULT_SECTION_DELIMITERS; |
|
|
| header_del = h; |
| header_del_len = strlen(h); |
|
|
| body_del = b; |
| body_del_len = strlen(b); |
|
|
| footer_del = f; |
| footer_del_len = strlen(f); |
| } |
|
|
| |
| |
| |
| static void set_line_buf_str(const char *s) |
| { |
| line_buf.buffer = (char *) s; |
| line_buf.length = strlen(s); |
| } |
|
|
| |
|
|
| static void test_check_section_returns_Text_when_line_too_short(void) |
| { |
| configure_default_delims(); |
| |
| const char *line = "A\n"; |
| set_line_buf_str(line); |
|
|
| enum section sec = check_section(); |
| TEST_ASSERT_EQUAL_INT(Text, sec); |
| } |
|
|
| static void test_check_section_returns_Text_when_prefix_mismatch(void) |
| { |
| configure_default_delims(); |
| |
| const char *line = "xyh\n"; |
| set_line_buf_str(line); |
|
|
| enum section sec = check_section(); |
| TEST_ASSERT_EQUAL_INT(Text, sec); |
| } |
|
|
| static void test_check_section_detects_Header(void) |
| { |
| configure_default_delims(); |
| |
| const char *line = "\\:h\n"; |
| set_line_buf_str(line); |
|
|
| enum section sec = check_section(); |
| TEST_ASSERT_EQUAL_INT(Header, sec); |
| } |
|
|
| static void test_check_section_detects_Body(void) |
| { |
| configure_default_delims(); |
| |
| const char *line = "\\:b\n"; |
| set_line_buf_str(line); |
|
|
| enum section sec = check_section(); |
| TEST_ASSERT_EQUAL_INT(Body, sec); |
| } |
|
|
| static void test_check_section_detects_Footer(void) |
| { |
| configure_default_delims(); |
| |
| const char *line = "\\:f\n"; |
| set_line_buf_str(line); |
|
|
| enum section sec = check_section(); |
| TEST_ASSERT_EQUAL_INT(Footer, sec); |
| } |
|
|
| static void test_check_section_only_prefix_without_type_is_Text(void) |
| { |
| configure_default_delims(); |
| |
| |
| const char *line = "\\:\n"; |
| set_line_buf_str(line); |
|
|
| enum section sec = check_section(); |
| TEST_ASSERT_EQUAL_INT(Text, sec); |
| } |
|
|
| static void test_check_section_disabled_by_empty_delimiter_returns_Text(void) |
| { |
| configure_default_delims(); |
| |
| footer_del_len = 0; |
|
|
| |
| const char *line = "\\:h\n"; |
| set_line_buf_str(line); |
|
|
| enum section sec = check_section(); |
| TEST_ASSERT_EQUAL_INT(Text, sec); |
| } |
|
|
| |
| int main(void) |
| { |
| UNITY_BEGIN(); |
|
|
| RUN_TEST(test_check_section_returns_Text_when_line_too_short); |
| RUN_TEST(test_check_section_returns_Text_when_prefix_mismatch); |
| RUN_TEST(test_check_section_detects_Header); |
| RUN_TEST(test_check_section_detects_Body); |
| RUN_TEST(test_check_section_detects_Footer); |
| RUN_TEST(test_check_section_only_prefix_without_type_is_Text); |
| RUN_TEST(test_check_section_disabled_by_empty_delimiter_returns_Text); |
|
|
| return UNITY_END(); |
| } |