|
|
#include "../../unity/unity.h" |
|
|
#include <string.h> |
|
|
#include <stdbool.h> |
|
|
|
|
|
|
|
|
void setUp(void) { |
|
|
|
|
|
} |
|
|
void tearDown(void) { |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
static WORD make_word_from_cstr(const char *s) { |
|
|
WORD w; |
|
|
memset(&w, 0, sizeof(w)); |
|
|
w.text = s; |
|
|
w.length = (int)strlen(s); |
|
|
return w; |
|
|
} |
|
|
|
|
|
|
|
|
static void test_check_punctuation_plain_word(void) { |
|
|
WORD w = make_word_from_cstr("hello"); |
|
|
check_punctuation(&w); |
|
|
TEST_ASSERT_FALSE(w.paren); |
|
|
TEST_ASSERT_FALSE(w.punct); |
|
|
TEST_ASSERT_FALSE(w.period); |
|
|
} |
|
|
|
|
|
|
|
|
static void test_check_punctuation_start_quote_end_quote(void) { |
|
|
WORD w = make_word_from_cstr("\"hello\""); |
|
|
check_punctuation(&w); |
|
|
TEST_ASSERT_TRUE(w.paren); |
|
|
TEST_ASSERT_TRUE(w.punct); |
|
|
TEST_ASSERT_FALSE(w.period); |
|
|
} |
|
|
|
|
|
|
|
|
static void test_check_punctuation_end_period(void) { |
|
|
WORD w = make_word_from_cstr("end."); |
|
|
check_punctuation(&w); |
|
|
TEST_ASSERT_FALSE(w.paren); |
|
|
TEST_ASSERT_TRUE(w.punct); |
|
|
TEST_ASSERT_TRUE(w.period); |
|
|
} |
|
|
|
|
|
|
|
|
static void test_check_punctuation_end_period_then_close_paren(void) { |
|
|
WORD w = make_word_from_cstr("done.)"); |
|
|
check_punctuation(&w); |
|
|
TEST_ASSERT_FALSE(w.paren); |
|
|
TEST_ASSERT_TRUE(w.punct); |
|
|
TEST_ASSERT_TRUE(w.period); |
|
|
} |
|
|
|
|
|
|
|
|
static void test_check_punctuation_exclaim_then_close_quote(void) { |
|
|
WORD w = make_word_from_cstr("Wow!'"); |
|
|
check_punctuation(&w); |
|
|
TEST_ASSERT_FALSE(w.paren); |
|
|
TEST_ASSERT_TRUE(w.punct); |
|
|
TEST_ASSERT_TRUE(w.period); |
|
|
} |
|
|
|
|
|
|
|
|
static void test_check_punctuation_trailing_closer_no_period(void) { |
|
|
WORD w = make_word_from_cstr("word)"); |
|
|
check_punctuation(&w); |
|
|
TEST_ASSERT_FALSE(w.paren); |
|
|
TEST_ASSERT_TRUE(w.punct); |
|
|
TEST_ASSERT_FALSE(w.period); |
|
|
} |
|
|
|
|
|
|
|
|
static void test_check_punctuation_single_open_paren(void) { |
|
|
WORD w = make_word_from_cstr("("); |
|
|
check_punctuation(&w); |
|
|
TEST_ASSERT_TRUE(w.paren); |
|
|
TEST_ASSERT_TRUE(w.punct); |
|
|
TEST_ASSERT_FALSE(w.period); |
|
|
} |
|
|
|
|
|
|
|
|
static void test_check_punctuation_single_period(void) { |
|
|
WORD w = make_word_from_cstr("."); |
|
|
check_punctuation(&w); |
|
|
TEST_ASSERT_FALSE(w.paren); |
|
|
TEST_ASSERT_TRUE(w.punct); |
|
|
TEST_ASSERT_TRUE(w.period); |
|
|
} |
|
|
|
|
|
|
|
|
static void test_check_punctuation_nonperiod_punctuation_comma(void) { |
|
|
WORD w = make_word_from_cstr("a,"); |
|
|
check_punctuation(&w); |
|
|
TEST_ASSERT_FALSE(w.paren); |
|
|
TEST_ASSERT_TRUE(w.punct); |
|
|
TEST_ASSERT_FALSE(w.period); |
|
|
} |
|
|
|
|
|
|
|
|
static void test_check_punctuation_opener_and_punct_inside_closers(void) { |
|
|
WORD w = make_word_from_cstr("('Hi!')"); |
|
|
check_punctuation(&w); |
|
|
TEST_ASSERT_TRUE(w.paren); |
|
|
TEST_ASSERT_TRUE(w.punct); |
|
|
TEST_ASSERT_TRUE(w.period); |
|
|
} |
|
|
|
|
|
int main(void) { |
|
|
UNITY_BEGIN(); |
|
|
RUN_TEST(test_check_punctuation_plain_word); |
|
|
RUN_TEST(test_check_punctuation_start_quote_end_quote); |
|
|
RUN_TEST(test_check_punctuation_end_period); |
|
|
RUN_TEST(test_check_punctuation_end_period_then_close_paren); |
|
|
RUN_TEST(test_check_punctuation_exclaim_then_close_quote); |
|
|
RUN_TEST(test_check_punctuation_trailing_closer_no_period); |
|
|
RUN_TEST(test_check_punctuation_single_open_paren); |
|
|
RUN_TEST(test_check_punctuation_single_period); |
|
|
RUN_TEST(test_check_punctuation_nonperiod_punctuation_comma); |
|
|
RUN_TEST(test_check_punctuation_opener_and_punct_inside_closers); |
|
|
return UNITY_END(); |
|
|
} |