| #include "sqliteInt.h" |
| #include "unity.h" |
| #include <stdlib.h> |
| #include <string.h> |
|
|
| |
| extern int test_getWhitespace(const u8 *z); |
|
|
| void setUp(void) { |
| |
| } |
|
|
| void tearDown(void) { |
| |
| } |
|
|
| |
| #define U8STR(z) ((const u8*)(z)) |
|
|
| void test_getWhitespace_empty_string(void) { |
| const char *z = ""; |
| int n = test_getWhitespace(U8STR(z)); |
| TEST_ASSERT_EQUAL_INT(0, n); |
| } |
|
|
| void test_getWhitespace_no_leading_whitespace(void) { |
| const char *z = "SELECT"; |
| int n = test_getWhitespace(U8STR(z)); |
| TEST_ASSERT_EQUAL_INT(0, n); |
| } |
|
|
| void test_getWhitespace_simple_spaces_tabs_newlines(void) { |
| const char *z = " \t\nabc"; |
| |
| int n = test_getWhitespace(U8STR(z)); |
| TEST_ASSERT_EQUAL_INT(3, n); |
| } |
|
|
| void test_getWhitespace_c_style_comment_only_then_token(void) { |
| const char *z = "/*hello*/world"; |
| " is 9 bytes long */ |
| int expected = 9; |
| int n = test_getWhitespace(U8STR(z)); |
| TEST_ASSERT_EQUAL_INT(expected, n); |
| } |
| |
| void test_getWhitespace_c_style_comment_then_whitespace_then_token(void) { |
| const char *z = " \tY"; |
| /* "" = 5, ' ' = 1, '\t' = 1, total = 7 */ |
| int expected = 7; |
| int n = test_getWhitespace(U8STR(z)); |
| TEST_ASSERT_EQUAL_INT(expected, n); |
| } |
| |
| void test_getWhitespace_multiple_comments_and_whitespace(void) { |
| const char *z = " \t X"; |
| /* ' ' = 1, "" = 5, '\t' = 1, "" = 7, ' ' = 2 => total 16 */ |
| int expected = 16; |
| int n = test_getWhitespace(U8STR(z)); |
| TEST_ASSERT_EQUAL_INT(expected, n); |
| } |
| |
| void test_getWhitespace_sql_line_comment_to_eof(void) { |
| const char *z = "-- hello"; |
| /* Entire string is a line comment to EOF. */ |
| int expected = (int)strlen(z); |
| int n = test_getWhitespace(U8STR(z)); |
| TEST_ASSERT_EQUAL_INT(expected, n); |
| } |
| |
| void test_getWhitespace_mixed_leading_ws_and_sql_line_comment_to_eof(void) { |
| const char *z = " \t--abc"; |
| /* Leading space+tab (2) then line comment "--abc" (5) => total 7; entire string */ |
| int expected = (int)strlen(z); |
| int n = test_getWhitespace(U8STR(z)); |
| TEST_ASSERT_EQUAL_INT(expected, n); |
| } |
| |
| void test_getWhitespace_stops_before_non_ws_or_comment_after_comment(void) { |
| const char *z = "X"; |
| /* Should count only the comment (5), then stop before 'X' */ |
| int expected = 5; |
| int n = test_getWhitespace(U8STR(z)); |
| TEST_ASSERT_EQUAL_INT(expected, n); |
| } |
| |
| void test_getWhitespace_all_ws_and_comments_entire_string(void) { |
| const char *z = " \t--d"; |
| /* space(1) + tab(1) + ""(5) + "--d"(3) = 10; entire string */ |
| int expected = (int)strlen(z); |
| int n = test_getWhitespace(U8STR(z)); |
| TEST_ASSERT_EQUAL_INT(expected, n); |
| } |
| |
| int main(void) { |
| UNITY_BEGIN(); |
| |
| RUN_TEST(test_getWhitespace_empty_string); |
| RUN_TEST(test_getWhitespace_no_leading_whitespace); |
| RUN_TEST(test_getWhitespace_simple_spaces_tabs_newlines); |
| RUN_TEST(test_getWhitespace_c_style_comment_only_then_token); |
| RUN_TEST(test_getWhitespace_c_style_comment_then_whitespace_then_token); |
| RUN_TEST(test_getWhitespace_multiple_comments_and_whitespace); |
| RUN_TEST(test_getWhitespace_sql_line_comment_to_eof); |
| RUN_TEST(test_getWhitespace_mixed_leading_ws_and_sql_line_comment_to_eof); |
| RUN_TEST(test_getWhitespace_stops_before_non_ws_or_comment_after_comment); |
| RUN_TEST(test_getWhitespace_all_ws_and_comments_entire_string); |
| |
| return UNITY_END(); |
| } |