| #include "../../unity/unity.h" |
| #include <string.h> |
| #include <stdlib.h> |
|
|
| |
| void setUp(void) { |
| |
| } |
| void tearDown(void) { |
| |
| } |
|
|
| |
|
|
| |
| void test_remove_suffix_basic_removal(void) { |
| char name[32]; |
| strcpy(name, "foo.txt"); |
| remove_suffix(name, ".txt"); |
| TEST_ASSERT_EQUAL_STRING("foo", name); |
| } |
|
|
| |
| void test_remove_suffix_no_match(void) { |
| char name[32]; |
| strcpy(name, "foo.txt"); |
| remove_suffix(name, ".log"); |
| TEST_ASSERT_EQUAL_STRING("foo.txt", name); |
| } |
|
|
| |
| void test_remove_suffix_exact_match_no_removal(void) { |
| char name[16]; |
| strcpy(name, "abc"); |
| remove_suffix(name, "abc"); |
| TEST_ASSERT_EQUAL_STRING("abc", name); |
| } |
|
|
| |
| void test_remove_suffix_suffix_longer_than_name(void) { |
| char name[16]; |
| strcpy(name, "abc"); |
| remove_suffix(name, "zabcd"); |
| TEST_ASSERT_EQUAL_STRING("abc", name); |
| } |
|
|
| |
| void test_remove_suffix_empty_suffix_no_change(void) { |
| char name[16]; |
| strcpy(name, "abc"); |
| remove_suffix(name, ""); |
| TEST_ASSERT_EQUAL_STRING("abc", name); |
| } |
|
|
| |
| void test_remove_suffix_empty_name(void) { |
| char name[4]; |
| strcpy(name, ""); |
| remove_suffix(name, "abc"); |
| TEST_ASSERT_EQUAL_STRING("", name); |
| } |
|
|
| |
| void test_remove_suffix_case_sensitivity(void) { |
| char name[32]; |
| strcpy(name, "File.TXT"); |
| remove_suffix(name, ".txt"); |
| TEST_ASSERT_EQUAL_STRING("File.TXT", name); |
| } |
|
|
| |
| void test_remove_suffix_remove_only_trailing_occurrence(void) { |
| char name[32]; |
| strcpy(name, "foobarbar"); |
| remove_suffix(name, "bar"); |
| TEST_ASSERT_EQUAL_STRING("foobar", name); |
| } |
|
|
| |
| void test_remove_suffix_longer_suffix_removal(void) { |
| char name[32]; |
| strcpy(name, "foobarbar"); |
| remove_suffix(name, "barbar"); |
| TEST_ASSERT_EQUAL_STRING("foo", name); |
| } |
|
|
| |
| void test_remove_suffix_partial_match_then_mismatch_should_not_modify(void) { |
| char name[32]; |
| strcpy(name, "abcdXY"); |
| remove_suffix(name, "cXY"); |
| TEST_ASSERT_EQUAL_STRING("abcdXY", name); |
| } |
|
|
| |
| void test_remove_suffix_leave_single_char(void) { |
| char name[32]; |
| strcpy(name, "abcdef"); |
| remove_suffix(name, "bcdef"); |
| TEST_ASSERT_EQUAL_STRING("a", name); |
| } |
|
|
| |
| void test_remove_suffix_suffix_longer_but_tail_matches_name(void) { |
| char name[8]; |
| strcpy(name, "ab"); |
| remove_suffix(name, "cab"); |
| TEST_ASSERT_EQUAL_STRING("ab", name); |
| } |
|
|
| |
| void test_remove_suffix_utf8_bytes(void) { |
| char name[64]; |
| strcpy(name, "grün.txt"); |
| remove_suffix(name, ".txt"); |
| TEST_ASSERT_EQUAL_STRING("grün", name); |
|
|
| |
| strcpy(name, "naïve.TXT"); |
| remove_suffix(name, ".txt"); |
| TEST_ASSERT_EQUAL_STRING("naïve.TXT", name); |
| } |
|
|
| |
| void test_remove_suffix_exact_length_protection(void) { |
| char name[16]; |
| strcpy(name, "aa"); |
| remove_suffix(name, "aa"); |
| TEST_ASSERT_EQUAL_STRING("aa", name); |
| } |
|
|
| int main(void) { |
| UNITY_BEGIN(); |
| RUN_TEST(test_remove_suffix_basic_removal); |
| RUN_TEST(test_remove_suffix_no_match); |
| RUN_TEST(test_remove_suffix_exact_match_no_removal); |
| RUN_TEST(test_remove_suffix_suffix_longer_than_name); |
| RUN_TEST(test_remove_suffix_empty_suffix_no_change); |
| RUN_TEST(test_remove_suffix_empty_name); |
| RUN_TEST(test_remove_suffix_case_sensitivity); |
| RUN_TEST(test_remove_suffix_remove_only_trailing_occurrence); |
| RUN_TEST(test_remove_suffix_longer_suffix_removal); |
| RUN_TEST(test_remove_suffix_partial_match_then_mismatch_should_not_modify); |
| RUN_TEST(test_remove_suffix_leave_single_char); |
| RUN_TEST(test_remove_suffix_suffix_longer_but_tail_matches_name); |
| RUN_TEST(test_remove_suffix_utf8_bytes); |
| RUN_TEST(test_remove_suffix_exact_length_protection); |
| return UNITY_END(); |
| } |