tests/test_string.c

changeset 1679
4a08dabe5e8f
parent 1678
6cf10bb137c5
equal deleted inserted replaced
1678:6cf10bb137c5 1679:4a08dabe5e8f
833 } 833 }
834 cx_testing_allocator_destroy(&talloc); 834 cx_testing_allocator_destroy(&talloc);
835 } 835 }
836 836
837 CX_TEST(test_strtrim) { 837 CX_TEST(test_strtrim) {
838 cxstring t1 = cx_strtrim(cx_str(" ein test \t ")); 838 const char *t = " ein test \t ";
839 cxstring t1 = cx_strtrim(t);
839 cxstring t2 = cx_strtrim(cx_str("abc")); 840 cxstring t2 = cx_strtrim(cx_str("abc"));
840 cxstring t3 = cx_strtrim(cx_str(" 123")); 841 cxmutstr t3 = cx_strtrim(cx_mutstr((char*)" 123"));
841 cxstring t4 = cx_strtrim(cx_str("xyz ")); 842 cxmutstr t4 = cx_strtrim((char*)"xyz ");
842 cxstring t5 = cx_strtrim(cx_str(" ")); 843 cxstring t5 = cx_strtrim(cx_str(" "));
843 cxstring empty = cx_strtrim(cx_str("")); 844 cxstring empty = cx_strtrim(cx_str(""));
844 845
845 CX_TEST_DO { 846 CX_TEST_DO {
846 CX_TEST_ASSERT(0 == cx_strcmp(t1, cx_str("ein test"))); 847 CX_TEST_ASSERT(0 == cx_strcmp(t1, "ein test"));
847 CX_TEST_ASSERT(0 == cx_strcmp(t2, cx_str("abc"))); 848 CX_TEST_ASSERT(0 == cx_strcmp(t2, "abc"));
848 CX_TEST_ASSERT(0 == cx_strcmp(t3, cx_str("123"))); 849 CX_TEST_ASSERT(0 == cx_strcmp(t3, "123"));
849 CX_TEST_ASSERT(0 == cx_strcmp(t4, cx_str("xyz"))); 850 CX_TEST_ASSERT(0 == cx_strcmp(t4, "xyz"));
850 CX_TEST_ASSERT(0 == cx_strcmp(t5, cx_str(""))); 851 CX_TEST_ASSERT(0 == cx_strcmp(t5, ""));
851 CX_TEST_ASSERT(0 == cx_strcmp(empty, cx_str(""))); 852 CX_TEST_ASSERT(0 == cx_strcmp(empty, ""));
852
853 // call the _m variant just for coverage
854 cxmutstr m1 = cx_strtrim_m(cx_mutstr((char *) " ein test \t "));
855 CX_TEST_ASSERT(0 == cx_strcmp(m1, "ein test"));
856 } 853 }
857 } 854 }
858 855
859 CX_TEST(test_strprefix) { 856 CX_TEST(test_strprefix) {
860 cxstring str = cx_str("test my prefix and my suffix"); 857 cxstring str = cx_str("test my prefix and my suffix");

mercurial