test/test_string.cpp

Tue, 20 Sep 2022 10:37:29 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 20 Sep 2022 10:37:29 +0200
changeset 588
6a3cd8f0a2cf
parent 587
3dd55e246d2d
child 589
c290f8fd979e
permissions
-rw-r--r--

do not use c++ object initialization

583
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 #include "cx/string.h"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 #include "util_allocator.h"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32 #include <gtest/gtest.h>
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 TEST(String, construct) {
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 cxstring s1 = cx_str("1234");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 cxstring s2 = cx_strn("abcd", 2);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 cxmutstr s3 = cx_mutstr((char *) "1234");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 cxmutstr s4 = cx_mutstrn((char *) "abcd", 2);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 EXPECT_EQ(s1.length, 4);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 EXPECT_EQ(s2.length, 2);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 EXPECT_EQ(s3.length, 4);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43 EXPECT_EQ(s4.length, 2);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 }
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46 TEST(String, strfree) {
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
47 CxTestingAllocator alloc;
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 auto test = (char *) cxMalloc(&alloc, 16);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49 cxmutstr str = cx_mutstrn(test, 16);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50 ASSERT_EQ(str.ptr, test);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51 EXPECT_EQ(str.length, 16);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 cx_strfree_a(&alloc, &str);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 EXPECT_EQ(str.ptr, nullptr);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 EXPECT_EQ(str.length, 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 EXPECT_TRUE(alloc.verify());
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56 }
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 TEST(String, strlen) {
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 cxstring s1 = CX_STR("1234");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 cxstring s2 = CX_STR(".:.:.");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61 cxstring s3 = CX_STR("X");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 size_t len0 = cx_strlen(0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 size_t len1 = cx_strlen(1, s1);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 size_t len2 = cx_strlen(2, s1, s2);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 size_t len3 = cx_strlen(3, s1, s2, s3);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 EXPECT_EQ(len0, 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69 EXPECT_EQ(len1, 4);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70 EXPECT_EQ(len2, 9);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71 EXPECT_EQ(len3, 10);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72 }
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
73
585
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
74 TEST(String, strsubs) {
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
75 cxstring str = CX_STR("A test string");
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
76
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
77 cxstring sub = cx_strsubs(str, 0);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
78 EXPECT_EQ(cx_strcmp(sub, str), 0);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
79
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
80 sub = cx_strsubs(str, 2);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
81 EXPECT_EQ(cx_strcmp(sub, cx_str("test string")), 0);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
82
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
83 sub = cx_strsubs(str, 7);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
84 EXPECT_EQ(cx_strcmp(sub, cx_str("string")), 0);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
85
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
86 sub = cx_strsubs(str, 15);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
87 EXPECT_EQ(cx_strcmp(sub, cx_str("")), 0);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
88
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
89 sub = cx_strsubsl(str, 2, 4);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
90 EXPECT_EQ(cx_strcmp(sub, cx_str("test")), 0);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
91
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
92 sub = cx_strsubsl(str, 7, 3);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
93 EXPECT_EQ(cx_strcmp(sub, cx_str("str")), 0);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
94
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
95 sub = cx_strsubsl(str, 7, 20);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
96 EXPECT_EQ(cx_strcmp(sub, cx_str("string")), 0);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
97
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
98 // just for coverage, call the _m variant
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
99 auto m = cx_strsubs_m(cx_mutstrn(nullptr, 0), 0);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
100 EXPECT_EQ(cx_strcmp(cx_strcast(m), cx_str("")), 0);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
101 }
583
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 TEST(String, strchr) {
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
104 cxstring str = CX_STR("I will find you - and I will kill you");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
105
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
106 cxstring notfound = cx_strchr(str, 'x');
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 EXPECT_EQ(notfound.length, 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 cxstring result = cx_strchr(str, 'w');
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110 EXPECT_EQ(result.length, 35);
587
3dd55e246d2d use EXPECT_STREQ instead of strcmp
Mike Becker <universe@uap-core.de>
parents: 586
diff changeset
111 EXPECT_STREQ(result.ptr, "will find you - and I will kill you");
585
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
112
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
113 // just for coverage, call the _m variant
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
114 auto m = cx_strchr_m(cx_mutstrn(nullptr, 0), 'a');
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
115 EXPECT_EQ(cx_strcmp(cx_strcast(m), cx_str("")), 0);
583
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 }
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118 TEST(String, strrchr) {
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 cxstring str = CX_STR("I will find you - and I will kill you");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 cxstring notfound = cx_strrchr(str, 'x');
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122 EXPECT_EQ(notfound.length, 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
124 cxstring result = cx_strrchr(str, 'w');
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 EXPECT_EQ(result.length, 13);
587
3dd55e246d2d use EXPECT_STREQ instead of strcmp
Mike Becker <universe@uap-core.de>
parents: 586
diff changeset
126 EXPECT_STREQ(result.ptr, "will kill you");
585
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
127
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
128 // just for coverage, call the _m variant
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
129 auto m = cx_strrchr_m(cx_mutstrn(nullptr, 0), 'a');
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
130 EXPECT_EQ(cx_strcmp(cx_strcast(m), cx_str("")), 0);
583
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131 }
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
133 TEST(String, strstr) {
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 cxstring str = CX_STR("find the match in this string");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135 cxstring longstr = CX_STR(
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137 "mnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138 "yzabcdeababababnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghij"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 "klmnopqrstuvwxyzaababababababababrstuvwxyzabcdefghijklmnopqrstuv"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140 "abababababababababababababababababababababababababababababababab"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141 "abababababababababababababababababababababababababababababababab"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 "abababababababababababababababababababababababababababababababab"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143 "abababababababababababababababababababababababababababababababab"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 "abababababababababababababababababababababababababababababababab"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 "abababababababababababababababababababababababababababababababab"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 "wxyz1234567890");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147 cxstring longstrpattern = CX_STR(
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148 "abababababababababababababababababababababababababababababababab"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 "abababababababababababababababababababababababababababababababab"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 "abababababababababababababababababababababababababababababababab"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151 "abababababababababababababababababababababababababababababababab"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 "abababababababababababababababababababababababababababababababab"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 );
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 cxstring longstrresult = CX_STR(
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155 "abababababababababababababababababababababababababababababababab"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156 "abababababababababababababababababababababababababababababababab"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
157 "abababababababababababababababababababababababababababababababab"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
158 "abababababababababababababababababababababababababababababababab"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
159 "abababababababababababababababababababababababababababababababab"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160 "abababababababababababababababababababababababababababababababab"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161 "wxyz1234567890"
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 );
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
164 cxstring notfound = cx_strstr(str, cx_str("no match"));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165 EXPECT_EQ(notfound.length, 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167 cxstring result = cx_strstr(str, cx_str("match"));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
168 EXPECT_EQ(result.length, 20);
587
3dd55e246d2d use EXPECT_STREQ instead of strcmp
Mike Becker <universe@uap-core.de>
parents: 586
diff changeset
169 EXPECT_STREQ(result.ptr, "match in this string");
583
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
170
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
171 result = cx_strstr(str, cx_str(""));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
172 EXPECT_EQ(result.length, str.length);
587
3dd55e246d2d use EXPECT_STREQ instead of strcmp
Mike Becker <universe@uap-core.de>
parents: 586
diff changeset
173 EXPECT_STREQ(result.ptr, str.ptr);
583
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
174
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
175 result = cx_strstr(longstr, longstrpattern);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
176 EXPECT_EQ(result.length, longstrresult.length);
587
3dd55e246d2d use EXPECT_STREQ instead of strcmp
Mike Becker <universe@uap-core.de>
parents: 586
diff changeset
177 EXPECT_STREQ(result.ptr, longstrresult.ptr);
585
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
178
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
179 // just for coverage, call the _m variant
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
180 auto mstr = cx_strdup(longstr);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
181 auto m = cx_strstr_m(mstr, longstrpattern);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
182 EXPECT_EQ(m.length, longstrresult.length);
587
3dd55e246d2d use EXPECT_STREQ instead of strcmp
Mike Becker <universe@uap-core.de>
parents: 586
diff changeset
183 EXPECT_STREQ(m.ptr, longstrresult.ptr);
585
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
184 cx_strfree(&mstr);
583
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
185 }
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
186
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
187 TEST(String, strcmp) {
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
188 cxstring str = CX_STR("compare this");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
189
588
6a3cd8f0a2cf do not use c++ object initialization
Mike Becker <universe@uap-core.de>
parents: 587
diff changeset
190 EXPECT_EQ(cx_strcmp(cx_str(""), cx_str("")), 0);
6a3cd8f0a2cf do not use c++ object initialization
Mike Becker <universe@uap-core.de>
parents: 587
diff changeset
191 EXPECT_GT(cx_strcmp(str, cx_str("")), 0);
6a3cd8f0a2cf do not use c++ object initialization
Mike Becker <universe@uap-core.de>
parents: 587
diff changeset
192 EXPECT_EQ(cx_strcmp(str, cx_str("compare this")), 0);
6a3cd8f0a2cf do not use c++ object initialization
Mike Becker <universe@uap-core.de>
parents: 587
diff changeset
193 EXPECT_NE(cx_strcmp(str, cx_str("Compare This")), 0);
6a3cd8f0a2cf do not use c++ object initialization
Mike Becker <universe@uap-core.de>
parents: 587
diff changeset
194 EXPECT_LT(cx_strcmp(str, cx_str("compare tool")), 0);
6a3cd8f0a2cf do not use c++ object initialization
Mike Becker <universe@uap-core.de>
parents: 587
diff changeset
195 EXPECT_GT(cx_strcmp(str, cx_str("compare shit")), 0);
6a3cd8f0a2cf do not use c++ object initialization
Mike Becker <universe@uap-core.de>
parents: 587
diff changeset
196 EXPECT_LT(cx_strcmp(str, cx_str("compare this not")), 0);
6a3cd8f0a2cf do not use c++ object initialization
Mike Becker <universe@uap-core.de>
parents: 587
diff changeset
197 EXPECT_GT(cx_strcmp(str, cx_str("compare")), 0);
583
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
198 }
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
199
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
200 TEST(String, strcasecmp) {
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
201 cxstring str = CX_STR("compare this");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
202
588
6a3cd8f0a2cf do not use c++ object initialization
Mike Becker <universe@uap-core.de>
parents: 587
diff changeset
203 EXPECT_EQ(cx_strcasecmp(cx_str(""), cx_str("")), 0);
6a3cd8f0a2cf do not use c++ object initialization
Mike Becker <universe@uap-core.de>
parents: 587
diff changeset
204 EXPECT_GT(cx_strcasecmp(str, cx_str("")), 0);
6a3cd8f0a2cf do not use c++ object initialization
Mike Becker <universe@uap-core.de>
parents: 587
diff changeset
205 EXPECT_EQ(cx_strcasecmp(str, cx_str("compare this")), 0);
6a3cd8f0a2cf do not use c++ object initialization
Mike Becker <universe@uap-core.de>
parents: 587
diff changeset
206 EXPECT_EQ(cx_strcasecmp(str, cx_str("Compare This")), 0);
6a3cd8f0a2cf do not use c++ object initialization
Mike Becker <universe@uap-core.de>
parents: 587
diff changeset
207 EXPECT_LT(cx_strcasecmp(str, cx_str("compare tool")), 0);
6a3cd8f0a2cf do not use c++ object initialization
Mike Becker <universe@uap-core.de>
parents: 587
diff changeset
208 EXPECT_GT(cx_strcasecmp(str, cx_str("compare shit")), 0);
6a3cd8f0a2cf do not use c++ object initialization
Mike Becker <universe@uap-core.de>
parents: 587
diff changeset
209 EXPECT_LT(cx_strcasecmp(str, cx_str("compare this not")), 0);
6a3cd8f0a2cf do not use c++ object initialization
Mike Becker <universe@uap-core.de>
parents: 587
diff changeset
210 EXPECT_GT(cx_strcasecmp(str, cx_str("compare")), 0);
583
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
211 }
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
212
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
213
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
214 TEST(String, strcat) {
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
215 cxstring s1 = CX_STR("12");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
216 cxstring s2 = CX_STR("34");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
217 cxstring s3 = CX_STR("56");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
218 cxstring sn = {nullptr, 0};
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
219
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
220 CxTestingAllocator alloc;
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
221
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
222 cxmutstr t1 = cx_strcat_a(&alloc, 2, s1, s2);
588
6a3cd8f0a2cf do not use c++ object initialization
Mike Becker <universe@uap-core.de>
parents: 587
diff changeset
223 EXPECT_EQ(cx_strcmp(cx_strcast(t1), cx_str("1234")), 0);
583
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
224 cx_strfree_a(&alloc, &t1);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
225
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
226 cxmutstr t2 = cx_strcat_a(&alloc, 3, s1, s2, s3);
588
6a3cd8f0a2cf do not use c++ object initialization
Mike Becker <universe@uap-core.de>
parents: 587
diff changeset
227 EXPECT_EQ(cx_strcmp(cx_strcast(t2), cx_str("123456")), 0);
583
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
228 cx_strfree_a(&alloc, &t2);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
229
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
230 cxmutstr t3 = cx_strcat_a(&alloc, 6, s1, sn, s2, sn, s3, sn);
588
6a3cd8f0a2cf do not use c++ object initialization
Mike Becker <universe@uap-core.de>
parents: 587
diff changeset
231 EXPECT_EQ(cx_strcmp(cx_strcast(t3), cx_str("123456")), 0);
583
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
232 cx_strfree_a(&alloc, &t3);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
233
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
234 cxmutstr t4 = cx_strcat_a(&alloc, 2, sn, sn);
588
6a3cd8f0a2cf do not use c++ object initialization
Mike Becker <universe@uap-core.de>
parents: 587
diff changeset
235 EXPECT_EQ(cx_strcmp(cx_strcast(t4), cx_str("")), 0);
583
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
236 cx_strfree_a(&alloc, &t4);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
237
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
238 EXPECT_TRUE(alloc.verify());
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
239 }
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
240
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
241 TEST(String, strsplit) {
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
242
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
243 cxstring test = cx_str("this,is,a,csv,string");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
244 size_t capa = 8;
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
245 cxstring list[8];
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
246 size_t n;
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
247
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
248 /* special case: empty string */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
249 n = cx_strsplit(test, cx_str(""), capa, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
250 ASSERT_EQ(n, 1);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
251 EXPECT_EQ(cx_strcmp(list[0], test), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
252
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
253 /* no delimiter occurrence */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
254 n = cx_strsplit(test, cx_str("z"), capa, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
255 ASSERT_EQ(n, 1);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
256 EXPECT_EQ(cx_strcmp(list[0], test), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
257
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
258 /* partially matching delimiter */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
259 n = cx_strsplit(test, cx_str("is,not"), capa, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
260 ASSERT_EQ(n, 1);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
261 EXPECT_EQ(cx_strcmp(list[0], test), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
262
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
263 /* matching single-char delimiter */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
264 n = cx_strsplit(test, cx_str(","), capa, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
265 ASSERT_EQ(n, 5);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
266 EXPECT_EQ(cx_strcmp(list[0], cx_str("this")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
267 EXPECT_EQ(cx_strcmp(list[1], cx_str("is")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
268 EXPECT_EQ(cx_strcmp(list[2], cx_str("a")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
269 EXPECT_EQ(cx_strcmp(list[3], cx_str("csv")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
270 EXPECT_EQ(cx_strcmp(list[4], cx_str("string")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
271
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
272 /* matching multi-char delimiter */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
273 n = cx_strsplit(test, cx_str("is"), capa, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
274 ASSERT_EQ(n, 3);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
275 EXPECT_EQ(cx_strcmp(list[0], cx_str("th")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
276 EXPECT_EQ(cx_strcmp(list[1], cx_str(",")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
277 EXPECT_EQ(cx_strcmp(list[2], cx_str(",a,csv,string")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
278
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
279 /* bounded list using single-char delimiter */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
280 n = cx_strsplit(test, cx_str(","), 3, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
281 ASSERT_EQ(n, 3);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
282 EXPECT_EQ(cx_strcmp(list[0], cx_str("this")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
283 EXPECT_EQ(cx_strcmp(list[1], cx_str("is")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
284 EXPECT_EQ(cx_strcmp(list[2], cx_str("a,csv,string")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
285
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
286 /* bounded list using multi-char delimiter */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
287 n = cx_strsplit(test, cx_str("is"), 2, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
288 ASSERT_EQ(n, 2);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
289 EXPECT_EQ(cx_strcmp(list[0], cx_str("th")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
290 EXPECT_EQ(cx_strcmp(list[1], cx_str(",is,a,csv,string")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
291
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
292 /* start with delimiter */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
293 n = cx_strsplit(test, cx_str("this"), capa, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
294 ASSERT_EQ(n, 2);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
295 EXPECT_EQ(cx_strcmp(list[0], cx_str("")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
296 EXPECT_EQ(cx_strcmp(list[1], cx_str(",is,a,csv,string")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
297
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
298 /* end with delimiter */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
299 n = cx_strsplit(test, cx_str("string"), capa, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
300 ASSERT_EQ(n, 2);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
301 EXPECT_EQ(cx_strcmp(list[0], cx_str("this,is,a,csv,")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
302 EXPECT_EQ(cx_strcmp(list[1], cx_str("")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
303
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
304
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
305 /* end with delimiter exceed bound */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
306 n = cx_strsplit(cx_str("a,b,c,"), cx_str(","), 3, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
307 ASSERT_EQ(n, 3);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
308 EXPECT_EQ(cx_strcmp(list[0], cx_str("a")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
309 EXPECT_EQ(cx_strcmp(list[1], cx_str("b")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
310 EXPECT_EQ(cx_strcmp(list[2], cx_str("c,")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
311
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
312 /* exact match */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
313 n = cx_strsplit(test, cx_str("this,is,a,csv,string"), capa, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
314 ASSERT_EQ(n, 2);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
315 EXPECT_EQ(cx_strcmp(list[0], cx_str("")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
316 EXPECT_EQ(cx_strcmp(list[1], cx_str("")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
317
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
318 /* string to be split is only substring */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
319 n = cx_strsplit(test, cx_str("this,is,a,csv,string,with,extension"), capa, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
320 ASSERT_EQ(n, 1);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
321 EXPECT_EQ(cx_strcmp(list[0], test), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
322
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
323 /* subsequent encounter of delimiter (the string between is empty) */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
324 n = cx_strsplit(test, cx_str("is,"), capa, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
325 ASSERT_EQ(n, 3);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
326 EXPECT_EQ(cx_strcmp(list[0], cx_str("th")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
327 EXPECT_EQ(cx_strcmp(list[1], cx_str("")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
328 EXPECT_EQ(cx_strcmp(list[2], cx_str("a,csv,string")), 0);
585
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
329
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
330 /* call the _m variant just for coverage */
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
331 auto mtest = cx_strdup(test);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
332 cxmutstr mlist[4];
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
333 n = cx_strsplit_m(mtest, cx_str("is,"), 4, mlist);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
334 ASSERT_EQ(n, 3);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
335 EXPECT_EQ(cx_strcmp(cx_strcast(mlist[0]), cx_str("th")), 0);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
336 EXPECT_EQ(cx_strcmp(cx_strcast(mlist[1]), cx_str("")), 0);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
337 EXPECT_EQ(cx_strcmp(cx_strcast(mlist[2]), cx_str("a,csv,string")), 0);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
338 cx_strfree(&mtest);
583
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
339 }
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
340
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
341 TEST(String, strsplit_a) {
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
342 CxTestingAllocator alloc;
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
343
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
344 cxstring test = cx_str("this,is,a,csv,string");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
345 size_t capa = 8;
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
346 cxstring *list;
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
347 size_t n;
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
348
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
349 /* special case: empty string */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
350 n = cx_strsplit_a(&alloc, test, cx_str(""), capa, &list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
351 ASSERT_EQ(n, 1);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
352 EXPECT_EQ(cx_strcmp(list[0], test), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
353 cxFree(&alloc, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
354
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
355 /* no delimiter occurrence */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
356 n = cx_strsplit_a(&alloc, test, cx_str("z"), capa, &list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
357 ASSERT_EQ(n, 1);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
358 EXPECT_EQ(cx_strcmp(list[0], test), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
359 cxFree(&alloc, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
360
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
361 /* partially matching delimiter */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
362 n = cx_strsplit_a(&alloc, test, cx_str("is,not"), capa, &list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
363 ASSERT_EQ(n, 1);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
364 EXPECT_EQ(cx_strcmp(list[0], test), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
365 cxFree(&alloc, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
366
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
367 /* matching single-char delimiter */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
368 n = cx_strsplit_a(&alloc, test, cx_str(","), capa, &list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
369 ASSERT_EQ(n, 5);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
370 EXPECT_EQ(cx_strcmp(list[0], cx_str("this")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
371 EXPECT_EQ(cx_strcmp(list[1], cx_str("is")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
372 EXPECT_EQ(cx_strcmp(list[2], cx_str("a")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
373 EXPECT_EQ(cx_strcmp(list[3], cx_str("csv")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
374 EXPECT_EQ(cx_strcmp(list[4], cx_str("string")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
375 cxFree(&alloc, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
376
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
377 /* matching multi-char delimiter */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
378 n = cx_strsplit_a(&alloc, test, cx_str("is"), capa, &list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
379 ASSERT_EQ(n, 3);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
380 EXPECT_EQ(cx_strcmp(list[0], cx_str("th")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
381 EXPECT_EQ(cx_strcmp(list[1], cx_str(",")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
382 EXPECT_EQ(cx_strcmp(list[2], cx_str(",a,csv,string")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
383 cxFree(&alloc, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
384
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
385 /* bounded list using single-char delimiter */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
386 n = cx_strsplit_a(&alloc, test, cx_str(","), 3, &list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
387 ASSERT_EQ(n, 3);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
388 EXPECT_EQ(cx_strcmp(list[0], cx_str("this")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
389 EXPECT_EQ(cx_strcmp(list[1], cx_str("is")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
390 EXPECT_EQ(cx_strcmp(list[2], cx_str("a,csv,string")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
391 cxFree(&alloc, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
392
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
393 /* bounded list using multi-char delimiter */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
394 n = cx_strsplit_a(&alloc, test, cx_str("is"), 2, &list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
395 ASSERT_EQ(n, 2);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
396 EXPECT_EQ(cx_strcmp(list[0], cx_str("th")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
397 EXPECT_EQ(cx_strcmp(list[1], cx_str(",is,a,csv,string")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
398 cxFree(&alloc, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
399
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
400 /* start with delimiter */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
401 n = cx_strsplit_a(&alloc, test, cx_str("this"), capa, &list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
402 ASSERT_EQ(n, 2);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
403 EXPECT_EQ(cx_strcmp(list[0], cx_str("")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
404 EXPECT_EQ(cx_strcmp(list[1], cx_str(",is,a,csv,string")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
405 cxFree(&alloc, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
406
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
407 /* end with delimiter */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
408 n = cx_strsplit_a(&alloc, test, cx_str("string"), capa, &list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
409 ASSERT_EQ(n, 2);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
410 EXPECT_EQ(cx_strcmp(list[0], cx_str("this,is,a,csv,")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
411 EXPECT_EQ(cx_strcmp(list[1], cx_str("")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
412 cxFree(&alloc, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
413
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
414 /* end with delimiter exceed bound */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
415 n = cx_strsplit_a(&alloc, cx_str("a,b,c,"), cx_str(","), 3, &list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
416 ASSERT_EQ(n, 3);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
417 EXPECT_EQ(cx_strcmp(list[0], cx_str("a")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
418 EXPECT_EQ(cx_strcmp(list[1], cx_str("b")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
419 EXPECT_EQ(cx_strcmp(list[2], cx_str("c,")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
420 cxFree(&alloc, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
421
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
422 /* exact match */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
423 n = cx_strsplit_a(&alloc, test, cx_str("this,is,a,csv,string"), capa, &list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
424 ASSERT_EQ(n, 2);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
425 EXPECT_EQ(cx_strcmp(list[0], cx_str("")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
426 EXPECT_EQ(cx_strcmp(list[1], cx_str("")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
427 cxFree(&alloc, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
428
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
429 /* string to be split is only substring */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
430 n = cx_strsplit_a(&alloc, test, cx_str("this,is,a,csv,string,with,extension"), capa, &list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
431 ASSERT_EQ(n, 1);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
432 EXPECT_EQ(cx_strcmp(list[0], test), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
433 cxFree(&alloc, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
434
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
435 /* subsequent encounter of delimiter (the string between is empty) */
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
436 n = cx_strsplit_a(&alloc, test, cx_str("is,"), capa, &list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
437 ASSERT_EQ(n, 3);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
438 EXPECT_EQ(cx_strcmp(list[0], cx_str("th")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
439 EXPECT_EQ(cx_strcmp(list[1], cx_str("")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
440 EXPECT_EQ(cx_strcmp(list[2], cx_str("a,csv,string")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
441 cxFree(&alloc, list);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
442
585
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
443 /* call the _m variant just for coverage */
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
444 auto mtest = cx_strdup(test);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
445 cxmutstr *mlist;
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
446 n = cx_strsplit_ma(&alloc, mtest, cx_str("is,"), 4, &mlist);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
447 ASSERT_EQ(n, 3);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
448 EXPECT_EQ(cx_strcmp(cx_strcast(mlist[0]), cx_str("th")), 0);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
449 EXPECT_EQ(cx_strcmp(cx_strcast(mlist[1]), cx_str("")), 0);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
450 EXPECT_EQ(cx_strcmp(cx_strcast(mlist[2]), cx_str("a,csv,string")), 0);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
451 cxFree(&alloc, mlist);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
452 cx_strfree(&mtest);
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
453
583
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
454 EXPECT_TRUE(alloc.verify());
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
455 }
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
456
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
457 TEST(String, strtrim) {
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
458 cxstring t1 = cx_strtrim(cx_str(" ein test \t "));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
459 cxstring t2 = cx_strtrim(cx_str("abc"));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
460 cxstring t3 = cx_strtrim(cx_str(" 123"));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
461 cxstring t4 = cx_strtrim(cx_str("xyz "));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
462 cxstring t5 = cx_strtrim(cx_str(" "));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
463 cxstring empty = cx_strtrim(cx_str(""));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
464
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
465 EXPECT_EQ(cx_strcmp(t1, cx_str("ein test")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
466 EXPECT_EQ(cx_strcmp(t2, cx_str("abc")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
467 EXPECT_EQ(cx_strcmp(t3, cx_str("123")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
468 EXPECT_EQ(cx_strcmp(t4, cx_str("xyz")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
469 EXPECT_EQ(cx_strcmp(t5, cx_str("")), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
470 EXPECT_EQ(cx_strcmp(empty, cx_str("")), 0);
585
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
471
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
472 /* call the _m variant just for coverage */
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
473 cxmutstr m1 = cx_strtrim_m(cx_mutstr((char *) " ein test \t "));
038f5e99e00f add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents: 583
diff changeset
474 EXPECT_EQ(cx_strcmp(cx_strcast(m1), cx_str("ein test")), 0);
583
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
475 }
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
476
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
477 TEST(String, strprefix) {
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
478 cxstring str = CX_STR("test my prefix and my suffix");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
479 cxstring empty = CX_STR("");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
480 EXPECT_FALSE(cx_strprefix(empty, cx_str("pref")));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
481 EXPECT_TRUE(cx_strprefix(str, empty));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
482 EXPECT_TRUE(cx_strprefix(empty, empty));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
483 EXPECT_TRUE(cx_strprefix(str, cx_str("test ")));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
484 EXPECT_FALSE(cx_strprefix(str, cx_str("8-) fsck ")));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
485 }
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
486
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
487 TEST(String, strsuffix) {
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
488 cxstring str = CX_STR("test my prefix and my suffix");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
489 cxstring empty = CX_STR("");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
490 EXPECT_FALSE(cx_strsuffix(empty, cx_str("suf")));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
491 EXPECT_TRUE(cx_strsuffix(str, empty));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
492 EXPECT_TRUE(cx_strsuffix(empty, empty));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
493 EXPECT_TRUE(cx_strsuffix(str, cx_str("fix")));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
494 EXPECT_FALSE(cx_strsuffix(str, cx_str("fox")));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
495 }
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
496
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
497 TEST(String, strcaseprefix) {
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
498 cxstring str = CX_STR("test my prefix and my suffix");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
499 cxstring empty = CX_STR("");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
500 EXPECT_FALSE(cx_strcaseprefix(empty, cx_str("pREf")));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
501 EXPECT_TRUE(cx_strcaseprefix(str, empty));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
502 EXPECT_TRUE(cx_strcaseprefix(empty, empty));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
503 EXPECT_TRUE(cx_strcaseprefix(str, cx_str("TEST ")));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
504 EXPECT_FALSE(cx_strcaseprefix(str, cx_str("8-) fsck ")));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
505 }
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
506
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
507 TEST(String, strcasesuffix) {
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
508 cxstring str = CX_STR("test my prefix and my suffix");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
509 cxstring empty = CX_STR("");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
510 EXPECT_FALSE(cx_strcasesuffix(empty, cx_str("sUf")));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
511 EXPECT_TRUE(cx_strcasesuffix(str, empty));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
512 EXPECT_TRUE(cx_strcasesuffix(empty, empty));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
513 EXPECT_TRUE(cx_strcasesuffix(str, cx_str("FIX")));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
514 EXPECT_FALSE(cx_strcasesuffix(str, cx_str("fox")));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
515 }
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
516
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
517 TEST(String, strreplace) {
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
518 cxstring str = CX_STR("test ababab string aba");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
519 cxstring longstr = CX_STR(
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
520 "xyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacd");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
521 cxstring notrail = CX_STR("test abab");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
522 cxstring empty = CX_STR("");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
523 cxstring astr = CX_STR("aaaaaaaaaa");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
524 cxstring csstr = CX_STR("test AB ab TEST xyz");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
525
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
526 cxmutstr repl = cx_strreplace(str, cx_str("abab"), cx_str("muchlonger"));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
527 cxstring expected = CX_STR("test muchlongerab string aba");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
528
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
529 cxmutstr repln = cx_strreplacen(str, cx_str("ab"), cx_str("c"), 2);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
530 cxstring expectedn = CX_STR("test ccab string aba");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
531
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
532 cxmutstr longrepl = cx_strreplace(longstr, cx_str("a"), cx_str("z"));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
533 cxstring longexpect = CX_STR(
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
534 "xyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzcd");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
535
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
536 cxmutstr replnotrail = cx_strreplace(notrail, cx_str("ab"), cx_str("z"));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
537 cxstring notrailexpect = CX_STR("test zz");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
538
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
539 cxmutstr repleq = cx_strreplace(str, str, cx_str("hello"));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
540 cxstring eqexpect = CX_STR("hello");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
541
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
542 cxmutstr replempty1 = cx_strreplace(empty, cx_str("ab"), cx_str("c")); // expect: empty
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
543 cxmutstr replempty2 = cx_strreplace(str, cx_str("abab"), empty);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
544 cxstring emptyexpect2 = CX_STR("test ab string aba");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
545
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
546 cxmutstr replpre = cx_strreplace(str, cx_str("test "), cx_str("TEST "));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
547 cxstring preexpected = CX_STR("TEST ababab string aba");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
548
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
549 cxmutstr replan1 = cx_strreplacen(astr, cx_str("a"), cx_str("x"), 1);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
550 cxstring an1expected = CX_STR("xaaaaaaaaa");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
551
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
552 cxmutstr replan4 = cx_strreplacen(astr, cx_str("a"), cx_str("x"), 4);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
553 cxstring an4expected = CX_STR("xxxxaaaaaa");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
554
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
555 cxmutstr replan9 = cx_strreplacen(astr, cx_str("a"), cx_str("x"), 9);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
556 cxstring an9expected = CX_STR("xxxxxxxxxa");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
557
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
558 cxmutstr replan10 = cx_strreplacen(astr, cx_str("a"), cx_str("x"), 10);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
559 cxstring an10expected = CX_STR("xxxxxxxxxx");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
560
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
561 cxmutstr replcs1 = cx_strreplace(csstr, cx_str("AB"), cx_str("*"));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
562 cxstring cs1expected = CX_STR("test * ab TEST xyz");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
563
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
564 cxmutstr replcs2 = cx_strreplace(csstr, cx_str("test"), cx_str("TEST"));
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
565 cxstring cs2expected = CX_STR("TEST AB ab TEST xyz");
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
566
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
567
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
568 EXPECT_NE(repl.ptr, str.ptr);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
569 EXPECT_EQ(cx_strcmp(cx_strcast(repl), expected), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
570 EXPECT_NE(repln.ptr, str.ptr);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
571 EXPECT_EQ(cx_strcmp(cx_strcast(repln), expectedn), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
572 EXPECT_EQ(cx_strcmp(cx_strcast(longrepl), longexpect), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
573 EXPECT_EQ(cx_strcmp(cx_strcast(replnotrail), notrailexpect), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
574 EXPECT_EQ(cx_strcmp(cx_strcast(repleq), eqexpect), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
575 EXPECT_EQ(cx_strcmp(cx_strcast(replempty1), empty), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
576 EXPECT_EQ(cx_strcmp(cx_strcast(replempty2), emptyexpect2), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
577 EXPECT_EQ(cx_strcmp(cx_strcast(replpre), preexpected), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
578 EXPECT_EQ(cx_strcmp(cx_strcast(replan1), an1expected), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
579 EXPECT_EQ(cx_strcmp(cx_strcast(replan4), an4expected), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
580 EXPECT_EQ(cx_strcmp(cx_strcast(replan9), an9expected), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
581 EXPECT_EQ(cx_strcmp(cx_strcast(replan10), an10expected), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
582 EXPECT_EQ(cx_strcmp(cx_strcast(replcs1), cs1expected), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
583 EXPECT_EQ(cx_strcmp(cx_strcast(replcs2), cs2expected), 0);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
584
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
585 cx_strfree(&repl);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
586 cx_strfree(&repln);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
587 cx_strfree(&longrepl);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
588 cx_strfree(&replnotrail);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
589 cx_strfree(&repleq);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
590 cx_strfree(&replempty1);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
591 cx_strfree(&replempty2);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
592 cx_strfree(&replpre);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
593 cx_strfree(&replan1);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
594 cx_strfree(&replan4);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
595 cx_strfree(&replan9);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
596 cx_strfree(&replan10);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
597 cx_strfree(&replcs1);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
598 cx_strfree(&replcs2);
0f3c9662f9b5 add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff changeset
599 }
586
aa51aaa907b9 add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents: 585
diff changeset
600
aa51aaa907b9 add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents: 585
diff changeset
601 TEST(String, strupper) {
aa51aaa907b9 add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents: 585
diff changeset
602 cxmutstr str = cx_strdup(cx_str("thIs 1s @ Te$t"));
aa51aaa907b9 add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents: 585
diff changeset
603 cx_strupper(str);
aa51aaa907b9 add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents: 585
diff changeset
604 EXPECT_STREQ(str.ptr, "THIS 1S @ TE$T");
aa51aaa907b9 add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents: 585
diff changeset
605 cx_strfree(&str);
aa51aaa907b9 add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents: 585
diff changeset
606 }
aa51aaa907b9 add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents: 585
diff changeset
607
aa51aaa907b9 add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents: 585
diff changeset
608 TEST(String, strlower) {
aa51aaa907b9 add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents: 585
diff changeset
609 cxmutstr str = cx_strdup(cx_str("thIs 1s @ Te$t"));
aa51aaa907b9 add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents: 585
diff changeset
610 cx_strlower(str);
aa51aaa907b9 add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents: 585
diff changeset
611 EXPECT_STREQ(str.ptr, "this 1s @ te$t");
aa51aaa907b9 add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents: 585
diff changeset
612 cx_strfree(&str);
aa51aaa907b9 add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents: 585
diff changeset
613 }

mercurial