tests/test_string.c

Wed, 01 Jan 2025 15:26:50 +0100

author
Mike Becker <universe@uap-core.de>
date
Wed, 01 Jan 2025 15:26:50 +0100
changeset 1071
028cb6d22197
parent 1063
e453e717876e
permissions
-rw-r--r--

fix cx_strcmp() and cx_strcasecmp() - fixes #546

777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2023 Mike Becker, Olaf Wintermann All rights reserved.
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
e5b29e6f0615 migrate string tests - relates to #342
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
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 #include "cx/test.h"
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 #include "util_allocator.h"
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32 #include "cx/string.h"
1063
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
33 #include "cx/compare.h"
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34
1052
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
35 #include <limits.h>
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
36 #include <errno.h>
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
37
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 #define ASSERT_ZERO_TERMINATED(str) CX_TEST_ASSERTM((str).ptr[(str).length] == '\0', \
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 #str " is not zero terminated")
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 CX_TEST(test_string_construct) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 cxstring s1 = CX_STR("1234");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43 cxstring s2 = cx_strn("abcd", 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 cxmutstr s3 = cx_mutstr((char *) "1234");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45 cxmutstr s4 = cx_mutstrn((char *) "abcd", 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
47 CX_TEST_ASSERT(s1.length == 4);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 CX_TEST_ASSERT(strncmp(s1.ptr, "1234", 4) == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49 CX_TEST_ASSERT(s2.length == 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50 CX_TEST_ASSERT(strncmp(s2.ptr, "ab", 2) == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51 CX_TEST_ASSERT(s3.length == 4);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 CX_TEST_ASSERT(strncmp(s3.ptr, "1234", 4) == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 CX_TEST_ASSERT(s4.length == 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 CX_TEST_ASSERT(strncmp(s4.ptr, "ab", 2) == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 CX_TEST(test_strfree) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 CxTestingAllocator talloc;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 cx_testing_allocator_init(&talloc);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61 CxAllocator *alloc = &talloc.base;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 char *test = cxMalloc(alloc, 16);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 cxmutstr str = cx_mutstrn(test, 16);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 CX_TEST_ASSERT(str.ptr == test);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 CX_TEST_ASSERT(str.length == 16);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 cx_strfree_a(alloc, &str);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 CX_TEST_ASSERT(str.ptr == NULL);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69 CX_TEST_ASSERT(str.length == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72 cx_testing_allocator_destroy(&talloc);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
73 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
74
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75 CX_TEST(test_strdup) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
76 cxstring str = CX_STR("test");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
77 cxmutstr dup = cx_strdup(str);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 CX_TEST_ASSERT(dup.length == str.length);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80 CX_TEST_ASSERT(0 == strcmp(dup.ptr, str.ptr));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81 ASSERT_ZERO_TERMINATED(dup);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 cx_strfree(&dup);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 CX_TEST(test_strdup_shortened) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 cxstring str = CX_STR("test");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 str.length = 2;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 cxmutstr dup = cx_strdup(str);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 CX_TEST_ASSERT(dup.length == str.length);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92 CX_TEST_ASSERT(0 == strcmp(dup.ptr, "te"));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93 ASSERT_ZERO_TERMINATED(dup);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95 cx_strfree(&dup);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98 CX_TEST(test_strlen) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 cxstring s1 = CX_STR("1234");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 cxstring s2 = CX_STR(".:.:.");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101 cxstring s3 = CX_STR("X");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 size_t len0 = cx_strlen(0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
104 size_t len1 = cx_strlen(1, s1);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
105 size_t len2 = cx_strlen(2, s1, s2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
106 size_t len3 = cx_strlen(3, s1, s2, s3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 CX_TEST_ASSERT(len0 == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 CX_TEST_ASSERT(len1 == 4);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110 CX_TEST_ASSERT(len2 == 9);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
111 CX_TEST_ASSERT(len3 == 10);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
114
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115 CX_TEST(test_strsubs) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 cxstring str = CX_STR("A test string");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 cxstring sub = cx_strsubs(str, 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120 CX_TEST_ASSERT(0 == cx_strcmp(sub, str));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122 sub = cx_strsubs(str, 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123 CX_TEST_ASSERT(0 == cx_strcmp(sub, CX_STR("test string")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
124
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 sub = cx_strsubs(str, 7);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
126 CX_TEST_ASSERT(0 == cx_strcmp(sub, CX_STR("string")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
127
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
128 sub = cx_strsubs(str, 15);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129 CX_TEST_ASSERT(0 == cx_strcmp(sub, CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131 sub = cx_strsubsl(str, 2, 4);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132 CX_TEST_ASSERT(0 == cx_strcmp(sub, CX_STR("test")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
133
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 sub = cx_strsubsl(str, 7, 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135 CX_TEST_ASSERT(0 == cx_strcmp(sub, CX_STR("str")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137 sub = cx_strsubsl(str, 7, 20);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138 CX_TEST_ASSERT(0 == cx_strcmp(sub, CX_STR("string")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140 // just for coverage, call the _m variant
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141 cxmutstr m = cx_strsubs_m(cx_mutstrn(NULL, 0), 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(m), CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 CX_TEST(test_strchr) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147 cxstring str = CX_STR("I will find you - and I will kill you");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 cxstring notfound = cx_strchr(str, 'x');
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151 CX_TEST_ASSERT(notfound.length == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 cxstring result = cx_strchr(str, 'w');
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 CX_TEST_ASSERT(result.length == 35);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155 CX_TEST_ASSERT(0 == strcmp(result.ptr, "will find you - and I will kill you"));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
157 // just for coverage, call the _m variant
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
158 cxmutstr m = cx_strchr_m(cx_mutstrn(NULL, 0), 'a');
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
159 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(m), CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 CX_TEST(test_strrchr) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
164 cxstring str = CX_STR("I will find you - and I will kill you");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167 cxstring notfound = cx_strrchr(str, 'x');
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
168 CX_TEST_ASSERT(notfound.length == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
169
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
170 cxstring result = cx_strrchr(str, 'w');
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
171 CX_TEST_ASSERT(result.length == 13);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
172 CX_TEST_ASSERT(0 == strcmp(result.ptr, "will kill you"));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
173
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
174 // just for coverage, call the _m variant
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
175 cxmutstr m = cx_strrchr_m(cx_mutstrn(NULL, 0), 'a');
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
176 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(m), CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
177 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
178 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
179
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
180 CX_TEST(test_strstr) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
181 cxstring str = CX_STR("find the match in this string");
806
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
182
926
8fdd8d78c14b fix several survivors of east-const and some missing consts
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
183 const size_t longstrpatternlen = 64 + cx_strstr_sbo_size;
8fdd8d78c14b fix several survivors of east-const and some missing consts
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
184 const size_t longstrlen = 320 + longstrpatternlen + 14;
806
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
185
809
b7e2e1d7ed22 fix assertion failure depending on possibly uninitialized memory
Mike Becker <universe@uap-core.de>
parents: 806
diff changeset
186 // it is more expensive to use calloc here, because we will overwrite
b7e2e1d7ed22 fix assertion failure depending on possibly uninitialized memory
Mike Becker <universe@uap-core.de>
parents: 806
diff changeset
187 // the memory anyway in the test preparation - but it is more reliable
b7e2e1d7ed22 fix assertion failure depending on possibly uninitialized memory
Mike Becker <universe@uap-core.de>
parents: 806
diff changeset
188 // in case we are doing something horribly wrong
b7e2e1d7ed22 fix assertion failure depending on possibly uninitialized memory
Mike Becker <universe@uap-core.de>
parents: 806
diff changeset
189 char *longstrc = calloc(longstrlen+1, 1);
b7e2e1d7ed22 fix assertion failure depending on possibly uninitialized memory
Mike Becker <universe@uap-core.de>
parents: 806
diff changeset
190 char *longstrpatternc = calloc(longstrpatternlen+1, 1);
806
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
191
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
192 memcpy(longstrc,
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
193 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl"
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
194 "mnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx"
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
195 "yzabcdeababababnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghij"
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
196 "klmnopqrstuvwxyzaababababababababrstuvwxyzabcdefghijklmnopqrstuv"
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
197 "abababababababababababababababababababababababababababababababab",
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
198 320
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
199 );
806
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
200 memcpy(longstrpatternc,
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
201 "abababababababababababababababababababababababababababababababab",
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
202 64
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
203 );
806
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
204 char x = 'a', y='b', z;
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
205 for (size_t i = 0; i < cx_strstr_sbo_size ; i++) {
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
206 longstrpatternc[64+i] = x;
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
207 longstrc[320+i] = x;
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
208 z=x; x=y; y=z;
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
209 }
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
210 longstrpatternc[longstrpatternlen] = '\0';
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
211 memcpy(longstrc+longstrlen-14, "wxyz1234567890", 15);
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
212
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
213 cxmutstr longstr = cx_mutstrn(longstrc, longstrlen);
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
214 cxstring longstrpattern = cx_strn(longstrpatternc, longstrpatternlen);
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
215 cxmutstr longstrresult = cx_mutstrn(longstrc+256, longstrlen-256);
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
216
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
217 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
218 cxstring notfound = cx_strstr(str, CX_STR("no match"));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
219 CX_TEST_ASSERT(notfound.length == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
220
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
221 cxstring result = cx_strstr(str, CX_STR("match"));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
222 CX_TEST_ASSERT(result.length == 20);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
223 CX_TEST_ASSERT(0 == strcmp(result.ptr, "match in this string"));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
224
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
225 result = cx_strstr(str, CX_STR(""));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
226 CX_TEST_ASSERT(result.length == str.length);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
227 CX_TEST_ASSERT(0 == strcmp(result.ptr, str.ptr));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
228
806
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
229 cxmutstr resultm = cx_strstr_m(longstr, longstrpattern);
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
230 CX_TEST_ASSERT(resultm.length == longstrresult.length);
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
231 CX_TEST_ASSERT(0 == strcmp(resultm.ptr, longstrresult.ptr));
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
232 }
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
233
806
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
234 free(longstrc);
e06249e09f99 add constant for reading out strstr sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents: 777
diff changeset
235 free(longstrpatternc);
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
236 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
237
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
238 CX_TEST(test_strcmp) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
239 cxstring str = CX_STR("compare this");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
240 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
241 CX_TEST_ASSERT(0 == cx_strcmp(CX_STR(""), CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
242 CX_TEST_ASSERT(0 < cx_strcmp(str, CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
243 CX_TEST_ASSERT(0 == cx_strcmp(str, CX_STR("compare this")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
244 CX_TEST_ASSERT(0 != cx_strcmp(str, CX_STR("Compare This")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
245 CX_TEST_ASSERT(0 > cx_strcmp(str, CX_STR("compare tool")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
246 CX_TEST_ASSERT(0 < cx_strcmp(str, CX_STR("compare shit")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
247 CX_TEST_ASSERT(0 > cx_strcmp(str, CX_STR("compare this not")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
248 CX_TEST_ASSERT(0 < cx_strcmp(str, CX_STR("compare")));
1071
028cb6d22197 fix cx_strcmp() and cx_strcasecmp() - fixes #546
Mike Becker <universe@uap-core.de>
parents: 1063
diff changeset
249 CX_TEST_ASSERT(0 > cx_strcmp(str, CX_STR("lex")));
028cb6d22197 fix cx_strcmp() and cx_strcasecmp() - fixes #546
Mike Becker <universe@uap-core.de>
parents: 1063
diff changeset
250 CX_TEST_ASSERT(0 < cx_strcmp(str, CX_STR("another lex test")));
028cb6d22197 fix cx_strcmp() and cx_strcasecmp() - fixes #546
Mike Becker <universe@uap-core.de>
parents: 1063
diff changeset
251 CX_TEST_ASSERT(0 < cx_strcmp(str, CX_STR("Lex")));
028cb6d22197 fix cx_strcmp() and cx_strcasecmp() - fixes #546
Mike Becker <universe@uap-core.de>
parents: 1063
diff changeset
252 CX_TEST_ASSERT(0 < cx_strcmp(str, CX_STR("Another lex test")));
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
253
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
254 cxstring str2 = CX_STR("Compare This");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
255 CX_TEST_ASSERT(0 != cx_strcmp_p(&str, &str2));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
256 str2 = CX_STR("compare this");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
257 CX_TEST_ASSERT(0 == cx_strcmp_p(&str, &str2));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
258 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
259 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
260
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
261 CX_TEST(test_strcasecmp) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
262 cxstring str = CX_STR("compare this");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
263 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
264 CX_TEST_ASSERT(0 == cx_strcasecmp(CX_STR(""), CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
265 CX_TEST_ASSERT(0 < cx_strcasecmp(str, CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
266 CX_TEST_ASSERT(0 == cx_strcasecmp(str, CX_STR("compare this")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
267 CX_TEST_ASSERT(0 == cx_strcasecmp(str, CX_STR("Compare This")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
268 CX_TEST_ASSERT(0 > cx_strcasecmp(str, CX_STR("compare tool")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
269 CX_TEST_ASSERT(0 < cx_strcasecmp(str, CX_STR("compare shit")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
270 CX_TEST_ASSERT(0 > cx_strcasecmp(str, CX_STR("compare this not")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
271 CX_TEST_ASSERT(0 < cx_strcasecmp(str, CX_STR("compare")));
1071
028cb6d22197 fix cx_strcmp() and cx_strcasecmp() - fixes #546
Mike Becker <universe@uap-core.de>
parents: 1063
diff changeset
272 CX_TEST_ASSERT(0 > cx_strcasecmp(str, CX_STR("lex")));
028cb6d22197 fix cx_strcmp() and cx_strcasecmp() - fixes #546
Mike Becker <universe@uap-core.de>
parents: 1063
diff changeset
273 CX_TEST_ASSERT(0 < cx_strcasecmp(str, CX_STR("another lex test")));
028cb6d22197 fix cx_strcmp() and cx_strcasecmp() - fixes #546
Mike Becker <universe@uap-core.de>
parents: 1063
diff changeset
274 CX_TEST_ASSERT(0 > cx_strcasecmp(str, CX_STR("Lex")));
028cb6d22197 fix cx_strcmp() and cx_strcasecmp() - fixes #546
Mike Becker <universe@uap-core.de>
parents: 1063
diff changeset
275 CX_TEST_ASSERT(0 < cx_strcasecmp(str, CX_STR("Another lex test")));
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
276
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
277 cxstring str2 = CX_STR("Compare This");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
278 CX_TEST_ASSERT(0 == cx_strcasecmp_p(&str, &str2));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
279 str2 = CX_STR("Compare Tool");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
280 CX_TEST_ASSERT(0 > cx_strcasecmp_p(&str, &str2));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
281 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
282 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
283
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
284 CX_TEST(test_strcat) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
285 cxstring s1 = CX_STR("12");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
286 cxstring s2 = CX_STR("34");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
287 cxstring s3 = CX_STR("56");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
288 cxstring sn = {NULL, 0};
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
289
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
290 CxTestingAllocator talloc;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
291 cx_testing_allocator_init(&talloc);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
292 CxAllocator *alloc = &talloc.base;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
293
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
294 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
295 cxmutstr t1 = cx_strcat_a(alloc, 2, s1, s2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
296 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t1), CX_STR("1234")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
297 ASSERT_ZERO_TERMINATED(t1);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
298 cx_strfree_a(alloc, &t1);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
299
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
300 cxmutstr t2 = cx_strcat_a(alloc, 3, s1, s2, s3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
301 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t2), CX_STR("123456")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
302 ASSERT_ZERO_TERMINATED(t2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
303 cx_strfree_a(alloc, &t2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
304
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
305 cxmutstr t3 = cx_strcat_a(alloc, 6, s1, sn, s2, sn, s3, sn);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
306 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t3), CX_STR("123456")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
307 ASSERT_ZERO_TERMINATED(t3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
308 cx_strfree_a(alloc, &t3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
309
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
310 cxmutstr t4 = cx_strcat_a(alloc, 2, sn, sn);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
311 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t4), CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
312 ASSERT_ZERO_TERMINATED(t4);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
313 cx_strfree_a(alloc, &t4);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
314
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
315 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
316
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
317 // use the macro
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
318 cxmutstr t5 = cx_strcat(3, s3, s1, s2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
319 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t5), CX_STR("561234")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
320 ASSERT_ZERO_TERMINATED(t5);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
321 cx_strfree(&t5);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
322
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
323 // use an initial string
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
324 cxmutstr t6 = cx_strdup(CX_STR("Hello"));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
325 t6 = cx_strcat_m(t6, 2, CX_STR(", "), CX_STR("World!"));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
326 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t6), CX_STR("Hello, World!")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
327 ASSERT_ZERO_TERMINATED(t6);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
328 cx_strfree(&t6);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
329 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
330 cx_testing_allocator_destroy(&talloc);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
331 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
332
1003
455afb252878 add test case to cover new branches inside cx_strcat_ma()
Mike Becker <universe@uap-core.de>
parents: 926
diff changeset
333 CX_TEST(test_strcat_more_than_eight) {
455afb252878 add test case to cover new branches inside cx_strcat_ma()
Mike Becker <universe@uap-core.de>
parents: 926
diff changeset
334 cxstring s1 = CX_STR("12");
455afb252878 add test case to cover new branches inside cx_strcat_ma()
Mike Becker <universe@uap-core.de>
parents: 926
diff changeset
335 cxstring s2 = CX_STR("34");
455afb252878 add test case to cover new branches inside cx_strcat_ma()
Mike Becker <universe@uap-core.de>
parents: 926
diff changeset
336 cxstring s3 = CX_STR("56");
455afb252878 add test case to cover new branches inside cx_strcat_ma()
Mike Becker <universe@uap-core.de>
parents: 926
diff changeset
337 cxstring s4 = CX_STR("78");
455afb252878 add test case to cover new branches inside cx_strcat_ma()
Mike Becker <universe@uap-core.de>
parents: 926
diff changeset
338 cxstring s5 = CX_STR("9a");
455afb252878 add test case to cover new branches inside cx_strcat_ma()
Mike Becker <universe@uap-core.de>
parents: 926
diff changeset
339 cxstring s6 = CX_STR("bc");
455afb252878 add test case to cover new branches inside cx_strcat_ma()
Mike Becker <universe@uap-core.de>
parents: 926
diff changeset
340 cxstring s7 = CX_STR("de");
455afb252878 add test case to cover new branches inside cx_strcat_ma()
Mike Becker <universe@uap-core.de>
parents: 926
diff changeset
341 cxstring s8 = CX_STR("f0");
455afb252878 add test case to cover new branches inside cx_strcat_ma()
Mike Becker <universe@uap-core.de>
parents: 926
diff changeset
342 cxstring s9 = CX_STR("xy");
455afb252878 add test case to cover new branches inside cx_strcat_ma()
Mike Becker <universe@uap-core.de>
parents: 926
diff changeset
343
455afb252878 add test case to cover new branches inside cx_strcat_ma()
Mike Becker <universe@uap-core.de>
parents: 926
diff changeset
344 CX_TEST_DO {
455afb252878 add test case to cover new branches inside cx_strcat_ma()
Mike Becker <universe@uap-core.de>
parents: 926
diff changeset
345 cxmutstr r = cx_strcat(9, s1, s2, s3, s4, s5, s6, s7, s8, s9);
455afb252878 add test case to cover new branches inside cx_strcat_ma()
Mike Becker <universe@uap-core.de>
parents: 926
diff changeset
346 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(r), CX_STR("123456789abcdef0xy")));
455afb252878 add test case to cover new branches inside cx_strcat_ma()
Mike Becker <universe@uap-core.de>
parents: 926
diff changeset
347 ASSERT_ZERO_TERMINATED(r);
455afb252878 add test case to cover new branches inside cx_strcat_ma()
Mike Becker <universe@uap-core.de>
parents: 926
diff changeset
348 cx_strfree(&r);
455afb252878 add test case to cover new branches inside cx_strcat_ma()
Mike Becker <universe@uap-core.de>
parents: 926
diff changeset
349 }
455afb252878 add test case to cover new branches inside cx_strcat_ma()
Mike Becker <universe@uap-core.de>
parents: 926
diff changeset
350 }
455afb252878 add test case to cover new branches inside cx_strcat_ma()
Mike Becker <universe@uap-core.de>
parents: 926
diff changeset
351
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
352 CX_TEST(test_strsplit) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
353 cxstring test = CX_STR("this,is,a,csv,string");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
354 size_t capa = 8;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
355 cxstring list[8];
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
356 size_t n;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
357 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
358 // special case: empty string
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
359 n = cx_strsplit(test, CX_STR(""), capa, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
360 CX_TEST_ASSERT(n == 1);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
361 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
362
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
363 // no delimiter occurrence
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
364 n = cx_strsplit(test, CX_STR("z"), capa, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
365 CX_TEST_ASSERT(n == 1);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
366 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
367
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
368 // partially matching delimiter
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
369 n = cx_strsplit(test, CX_STR("is,not"), capa, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
370 CX_TEST_ASSERT(n == 1);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
371 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
372
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
373 // matching single-char delimiter
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
374 n = cx_strsplit(test, CX_STR(","), capa, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
375 CX_TEST_ASSERT(n == 5);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
376 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("this")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
377 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR("is")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
378 CX_TEST_ASSERT(0 == cx_strcmp(list[2], CX_STR("a")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
379 CX_TEST_ASSERT(0 == cx_strcmp(list[3], CX_STR("csv")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
380 CX_TEST_ASSERT(0 == cx_strcmp(list[4], CX_STR("string")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
381
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
382 // matching multi-char delimiter
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
383 n = cx_strsplit(test, CX_STR("is"), capa, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
384 CX_TEST_ASSERT(n == 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
385 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("th")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
386 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR(",")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
387 CX_TEST_ASSERT(0 == cx_strcmp(list[2], CX_STR(",a,csv,string")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
388
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
389 // bounded list using single-char delimiter
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
390 n = cx_strsplit(test, CX_STR(","), 3, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
391 CX_TEST_ASSERT(n == 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
392 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("this")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
393 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR("is")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
394 CX_TEST_ASSERT(0 == cx_strcmp(list[2], CX_STR("a,csv,string")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
395
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
396 // bounded list using multi-char delimiter
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
397 n = cx_strsplit(test, CX_STR("is"), 2, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
398 CX_TEST_ASSERT(n == 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
399 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("th")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
400 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR(",is,a,csv,string")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
401
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
402 // start with delimiter
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
403 n = cx_strsplit(test, CX_STR("this"), capa, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
404 CX_TEST_ASSERT(n == 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
405 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
406 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR(",is,a,csv,string")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
407
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
408 // end with delimiter
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
409 n = cx_strsplit(test, CX_STR("string"), capa, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
410 CX_TEST_ASSERT(n == 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
411 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("this,is,a,csv,")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
412 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
413
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
414
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
415 // end with delimiter exceed bound
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
416 n = cx_strsplit(CX_STR("a,b,c,"), CX_STR(","), 3, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
417 CX_TEST_ASSERT(n == 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
418 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("a")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
419 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR("b")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
420 CX_TEST_ASSERT(0 == cx_strcmp(list[2], CX_STR("c,")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
421
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
422 // exact match
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
423 n = cx_strsplit(test, CX_STR("this,is,a,csv,string"), capa, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
424 CX_TEST_ASSERT(n == 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
425 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
426 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
427
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
428 // string to be split is only substring
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
429 n = cx_strsplit(test, CX_STR("this,is,a,csv,string,with,extension"), capa, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
430 CX_TEST_ASSERT(n == 1);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
431 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
432
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
433 // subsequent encounter of delimiter (the string between is empty)
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
434 n = cx_strsplit(test, CX_STR("is,"), capa, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
435 CX_TEST_ASSERT(n == 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
436 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("th")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
437 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
438 CX_TEST_ASSERT(0 == cx_strcmp(list[2], CX_STR("a,csv,string")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
439
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
440 // call the _m variant just for coverage
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
441 cxmutstr mtest = cx_strdup(test);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
442 cxmutstr mlist[4];
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
443 n = cx_strsplit_m(mtest, CX_STR("is,"), 4, mlist);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
444 CX_TEST_ASSERT(n == 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
445 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[0]), CX_STR("th")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
446 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[1]), CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
447 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[2]), CX_STR("a,csv,string")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
448 cx_strfree(&mtest);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
449 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
450 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
451
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
452 CX_TEST(test_strsplit_a) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
453 CxTestingAllocator talloc;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
454 cx_testing_allocator_init(&talloc);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
455 CxAllocator *alloc = &talloc.base;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
456
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
457 cxstring test = CX_STR("this,is,a,csv,string");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
458 size_t capa = 8;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
459 cxstring *list;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
460 size_t n;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
461 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
462 // special case: empty string
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
463 n = cx_strsplit_a(alloc, test, CX_STR(""), capa, &list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
464 CX_TEST_ASSERT(n == 1);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
465 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
466 cxFree(alloc, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
467
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
468 // no delimiter occurrence
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
469 n = cx_strsplit_a(alloc, test, CX_STR("z"), capa, &list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
470 CX_TEST_ASSERT(n == 1);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
471 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
472 cxFree(alloc, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
473
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
474 // partially matching delimiter
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
475 n = cx_strsplit_a(alloc, test, CX_STR("is,not"), capa, &list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
476 CX_TEST_ASSERT(n == 1);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
477 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
478 cxFree(alloc, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
479
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
480 // matching single-char delimiter
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
481 n = cx_strsplit_a(alloc, test, CX_STR(","), capa, &list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
482 CX_TEST_ASSERT(n == 5);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
483 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("this")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
484 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR("is")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
485 CX_TEST_ASSERT(0 == cx_strcmp(list[2], CX_STR("a")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
486 CX_TEST_ASSERT(0 == cx_strcmp(list[3], CX_STR("csv")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
487 CX_TEST_ASSERT(0 == cx_strcmp(list[4], CX_STR("string")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
488 cxFree(alloc, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
489
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
490 // matching multi-char delimiter
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
491 n = cx_strsplit_a(alloc, test, CX_STR("is"), capa, &list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
492 CX_TEST_ASSERT(n == 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
493 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("th")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
494 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR(",")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
495 CX_TEST_ASSERT(0 == cx_strcmp(list[2], CX_STR(",a,csv,string")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
496 cxFree(alloc, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
497
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
498 // bounded list using single-char delimiter
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
499 n = cx_strsplit_a(alloc, test, CX_STR(","), 3, &list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
500 CX_TEST_ASSERT(n == 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
501 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("this")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
502 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR("is")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
503 CX_TEST_ASSERT(0 == cx_strcmp(list[2], CX_STR("a,csv,string")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
504 cxFree(alloc, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
505
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
506 // bounded list using multi-char delimiter
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
507 n = cx_strsplit_a(alloc, test, CX_STR("is"), 2, &list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
508 CX_TEST_ASSERT(n == 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
509 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("th")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
510 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR(",is,a,csv,string")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
511 cxFree(alloc, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
512
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
513 // start with delimiter
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
514 n = cx_strsplit_a(alloc, test, CX_STR("this"), capa, &list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
515 CX_TEST_ASSERT(n == 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
516 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
517 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR(",is,a,csv,string")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
518 cxFree(alloc, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
519
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
520 // end with delimiter
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
521 n = cx_strsplit_a(alloc, test, CX_STR("string"), capa, &list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
522 CX_TEST_ASSERT(n == 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
523 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("this,is,a,csv,")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
524 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
525 cxFree(alloc, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
526
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
527 // end with delimiter exceed bound
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
528 n = cx_strsplit_a(alloc, CX_STR("a,b,c,"), CX_STR(","), 3, &list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
529 CX_TEST_ASSERT(n == 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
530 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("a")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
531 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR("b")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
532 CX_TEST_ASSERT(0 == cx_strcmp(list[2], CX_STR("c,")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
533 cxFree(alloc, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
534
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
535 // exact match
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
536 n = cx_strsplit_a(alloc, test, CX_STR("this,is,a,csv,string"), capa, &list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
537 CX_TEST_ASSERT(n == 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
538 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
539 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
540 cxFree(alloc, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
541
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
542 // string to be split is only substring
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
543 n = cx_strsplit_a(alloc, test, CX_STR("this,is,a,csv,string,with,extension"), capa, &list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
544 CX_TEST_ASSERT(n == 1);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
545 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
546 cxFree(alloc, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
547
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
548 // subsequent encounter of delimiter (the string between is empty)
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
549 n = cx_strsplit_a(alloc, test, CX_STR("is,"), capa, &list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
550 CX_TEST_ASSERT(n == 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
551 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("th")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
552 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
553 CX_TEST_ASSERT(0 == cx_strcmp(list[2], CX_STR("a,csv,string")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
554 cxFree(alloc, list);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
555
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
556 // call the _m variant just for coverage
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
557 cxmutstr mtest = cx_strdup(test);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
558 cxmutstr *mlist;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
559 n = cx_strsplit_ma(alloc, mtest, CX_STR("is,"), 4, &mlist);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
560 CX_TEST_ASSERT(n == 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
561 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[0]), CX_STR("th")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
562 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[1]), CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
563 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[2]), CX_STR("a,csv,string")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
564 cxFree(alloc, mlist);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
565 cx_strfree(&mtest);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
566
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
567 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
568 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
569 cx_testing_allocator_destroy(&talloc);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
570 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
571
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
572 CX_TEST(test_strtrim) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
573 cxstring t1 = cx_strtrim(CX_STR(" ein test \t "));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
574 cxstring t2 = cx_strtrim(CX_STR("abc"));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
575 cxstring t3 = cx_strtrim(CX_STR(" 123"));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
576 cxstring t4 = cx_strtrim(CX_STR("xyz "));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
577 cxstring t5 = cx_strtrim(CX_STR(" "));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
578 cxstring empty = cx_strtrim(CX_STR(""));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
579
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
580 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
581 CX_TEST_ASSERT(0 == cx_strcmp(t1, CX_STR("ein test")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
582 CX_TEST_ASSERT(0 == cx_strcmp(t2, CX_STR("abc")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
583 CX_TEST_ASSERT(0 == cx_strcmp(t3, CX_STR("123")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
584 CX_TEST_ASSERT(0 == cx_strcmp(t4, CX_STR("xyz")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
585 CX_TEST_ASSERT(0 == cx_strcmp(t5, CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
586 CX_TEST_ASSERT(0 == cx_strcmp(empty, CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
587
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
588 // call the _m variant just for coverage
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
589 cxmutstr m1 = cx_strtrim_m(cx_mutstr((char *) " ein test \t "));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
590 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(m1), CX_STR("ein test")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
591 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
592 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
593
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
594 CX_TEST(test_strprefix) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
595 cxstring str = CX_STR("test my prefix and my suffix");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
596 cxstring empty = CX_STR("");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
597 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
598 CX_TEST_ASSERT(!cx_strprefix(empty, CX_STR("pref")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
599 CX_TEST_ASSERT(cx_strprefix(str, empty));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
600 CX_TEST_ASSERT(cx_strprefix(empty, empty));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
601 CX_TEST_ASSERT(cx_strprefix(str, CX_STR("test ")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
602 CX_TEST_ASSERT(!cx_strprefix(str, CX_STR("8-) fsck ")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
603 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
604 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
605
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
606 CX_TEST(test_strsuffix) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
607 cxstring str = CX_STR("test my prefix and my suffix");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
608 cxstring empty = CX_STR("");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
609 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
610 CX_TEST_ASSERT(!cx_strsuffix(empty, CX_STR("suf")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
611 CX_TEST_ASSERT(cx_strsuffix(str, empty));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
612 CX_TEST_ASSERT(cx_strsuffix(empty, empty));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
613 CX_TEST_ASSERT(cx_strsuffix(str, CX_STR("fix")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
614 CX_TEST_ASSERT(!cx_strsuffix(str, CX_STR("fox")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
615 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
616 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
617
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
618 CX_TEST(test_strcaseprefix) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
619 cxstring str = CX_STR("test my prefix and my suffix");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
620 cxstring empty = CX_STR("");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
621 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
622 CX_TEST_ASSERT(!cx_strcaseprefix(empty, CX_STR("pREf")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
623 CX_TEST_ASSERT(cx_strcaseprefix(str, empty));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
624 CX_TEST_ASSERT(cx_strcaseprefix(empty, empty));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
625 CX_TEST_ASSERT(cx_strcaseprefix(str, CX_STR("TEST ")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
626 CX_TEST_ASSERT(!cx_strcaseprefix(str, CX_STR("8-) fsck ")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
627 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
628 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
629
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
630 CX_TEST(test_strcasesuffix) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
631 cxstring str = CX_STR("test my prefix and my suffix");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
632 cxstring empty = CX_STR("");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
633 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
634 CX_TEST_ASSERT(!cx_strcasesuffix(empty, CX_STR("sUf")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
635 CX_TEST_ASSERT(cx_strcasesuffix(str, empty));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
636 CX_TEST_ASSERT(cx_strcasesuffix(empty, empty));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
637 CX_TEST_ASSERT(cx_strcasesuffix(str, CX_STR("FIX")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
638 CX_TEST_ASSERT(!cx_strcasesuffix(str, CX_STR("fox")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
639 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
640 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
641
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
642 CX_TEST(test_strreplace) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
643 CxTestingAllocator talloc;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
644 cx_testing_allocator_init(&talloc);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
645 CxAllocator *alloc = &talloc.base;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
646
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
647 cxstring str = CX_STR("test ababab string aba");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
648 cxstring longstr = CX_STR(
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
649 "xyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacd");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
650 cxstring notrail = CX_STR("test abab");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
651 cxstring empty = CX_STR("");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
652 cxstring astr = CX_STR("aaaaaaaaaa");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
653 cxstring csstr = CX_STR("test AB ab TEST xyz");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
654
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
655 cxmutstr repl = cx_strreplace(str, CX_STR("abab"), CX_STR("muchlonger"));
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 809
diff changeset
656 const char *expected = "test muchlongerab string aba";
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
657
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
658 cxmutstr repln = cx_strreplacen(str, CX_STR("ab"), CX_STR("c"), 2);
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 809
diff changeset
659 const char *expectedn = "test ccab string aba";
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
660
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
661 cxmutstr longrepl = cx_strreplace(longstr, CX_STR("a"), CX_STR("z"));
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 809
diff changeset
662 const char *longexpect = "xyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzcd";
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
663
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
664 cxmutstr replnotrail = cx_strreplace(notrail, CX_STR("ab"), CX_STR("z"));
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 809
diff changeset
665 const char *notrailexpect = "test zz";
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
666
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
667 cxmutstr repleq = cx_strreplace(str, str, CX_STR("hello"));
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 809
diff changeset
668 const char *eqexpect = "hello";
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
669
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
670 cxmutstr replempty1 = cx_strreplace(empty, CX_STR("ab"), CX_STR("c")); // expect: empty
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
671 cxmutstr replempty2 = cx_strreplace(str, CX_STR("abab"), empty);
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 809
diff changeset
672 const char *emptyexpect2 = "test ab string aba";
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
673
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
674 cxmutstr replpre = cx_strreplace(str, CX_STR("test "), CX_STR("TEST "));
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 809
diff changeset
675 const char *preexpected = "TEST ababab string aba";
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
676
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
677 cxmutstr replan1 = cx_strreplacen(astr, CX_STR("a"), CX_STR("x"), 1);
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 809
diff changeset
678 const char *an1expected = "xaaaaaaaaa";
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
679
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
680 cxmutstr replan4 = cx_strreplacen(astr, CX_STR("a"), CX_STR("x"), 4);
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 809
diff changeset
681 const char *an4expected = "xxxxaaaaaa";
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
682
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
683 cxmutstr replan9 = cx_strreplacen(astr, CX_STR("a"), CX_STR("x"), 9);
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 809
diff changeset
684 const char *an9expected = "xxxxxxxxxa";
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
685
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
686 cxmutstr replan10 = cx_strreplacen(astr, CX_STR("a"), CX_STR("x"), 10);
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 809
diff changeset
687 const char *an10expected = "xxxxxxxxxx";
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
688
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
689 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
690 cxmutstr repl1_a = cx_strreplace_a(alloc, csstr, CX_STR("AB"), CX_STR("*"));
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 809
diff changeset
691 const char *expeced1_a = "test * ab TEST xyz";
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
692
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
693 cxmutstr repl2_a = cx_strreplace_a(alloc, csstr, CX_STR("test"), CX_STR("TEST"));
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 809
diff changeset
694 const char *expected2_a = "TEST AB ab TEST xyz";
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
695
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
696 CX_TEST_ASSERT(repl.ptr != str.ptr);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
697 ASSERT_ZERO_TERMINATED(repl);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
698 CX_TEST_ASSERT(0 == strcmp(repl.ptr, expected));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
699 ASSERT_ZERO_TERMINATED(repln);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
700 CX_TEST_ASSERT(0 == strcmp(repln.ptr, expectedn));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
701 ASSERT_ZERO_TERMINATED(longrepl);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
702 CX_TEST_ASSERT(0 == strcmp(longrepl.ptr, longexpect));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
703 ASSERT_ZERO_TERMINATED(replnotrail);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
704 CX_TEST_ASSERT(0 == strcmp(replnotrail.ptr, notrailexpect));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
705 ASSERT_ZERO_TERMINATED(repleq);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
706 CX_TEST_ASSERT(0 == strcmp(repleq.ptr, eqexpect));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
707 ASSERT_ZERO_TERMINATED(replempty1);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
708 CX_TEST_ASSERT(0 == strcmp(replempty1.ptr, ""));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
709 ASSERT_ZERO_TERMINATED(replempty2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
710 CX_TEST_ASSERT(0 == strcmp(replempty2.ptr, emptyexpect2));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
711 ASSERT_ZERO_TERMINATED(replpre);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
712 CX_TEST_ASSERT(0 == strcmp(replpre.ptr, preexpected));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
713 ASSERT_ZERO_TERMINATED(replan1);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
714 CX_TEST_ASSERT(0 == strcmp(replan1.ptr, an1expected));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
715 ASSERT_ZERO_TERMINATED(replan4);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
716 CX_TEST_ASSERT(0 == strcmp(replan4.ptr, an4expected));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
717 ASSERT_ZERO_TERMINATED(replan9);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
718 CX_TEST_ASSERT(0 == strcmp(replan9.ptr, an9expected));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
719 ASSERT_ZERO_TERMINATED(replan10);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
720 CX_TEST_ASSERT(0 == strcmp(replan10.ptr, an10expected));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
721 ASSERT_ZERO_TERMINATED(repl1_a);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
722 CX_TEST_ASSERT(0 == strcmp(repl1_a.ptr, expeced1_a));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
723 ASSERT_ZERO_TERMINATED(repl2_a);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
724 CX_TEST_ASSERT(0 == strcmp(repl2_a.ptr, expected2_a));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
725
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
726 cx_strfree_a(alloc, &repl1_a);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
727 cx_strfree_a(alloc, &repl2_a);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
728 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
729 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
730
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
731 cx_strfree(&repl);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
732 cx_strfree(&repln);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
733 cx_strfree(&longrepl);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
734 cx_strfree(&replnotrail);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
735 cx_strfree(&repleq);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
736 cx_strfree(&replempty1);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
737 cx_strfree(&replempty2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
738 cx_strfree(&replpre);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
739 cx_strfree(&replan1);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
740 cx_strfree(&replan4);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
741 cx_strfree(&replan9);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
742 cx_strfree(&replan10);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
743 cx_testing_allocator_destroy(&talloc);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
744 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
745
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
746 CX_TEST(test_strupper) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
747 cxmutstr str = cx_strdup(CX_STR("thIs 1s @ Te$t"));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
748 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
749 cx_strupper(str);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
750 CX_TEST_ASSERT(0 == strcmp(str.ptr, "THIS 1S @ TE$T"));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
751 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
752 cx_strfree(&str);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
753 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
754
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
755 CX_TEST(test_strlower) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
756 cxmutstr str = cx_strdup(CX_STR("thIs 1s @ Te$t"));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
757 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
758 cx_strlower(str);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
759 CX_TEST_ASSERT(0 == strcmp(str.ptr, "this 1s @ te$t"));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
760 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
761 cx_strfree(&str);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
762 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
763
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
764 CX_TEST(test_strtok) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
765 cxstring str = CX_STR("a,comma,separated,string");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
766 cxstring delim = CX_STR(",");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
767 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
768 CxStrtokCtx ctx = cx_strtok(str, delim, 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
769 CX_TEST_ASSERT(ctx.str.ptr == str.ptr);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
770 CX_TEST_ASSERT(ctx.str.length == str.length);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
771 CX_TEST_ASSERT(ctx.delim.ptr == delim.ptr);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
772 CX_TEST_ASSERT(ctx.delim.length == delim.length);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
773 CX_TEST_ASSERT(ctx.limit == 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
774 CX_TEST_ASSERT(ctx.found == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
775 CX_TEST_ASSERT(ctx.pos == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
776 CX_TEST_ASSERT(ctx.next_pos == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
777 CX_TEST_ASSERT(ctx.delim_more == NULL);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
778 CX_TEST_ASSERT(ctx.delim_more_count == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
779 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
780 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
781
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
782 CX_TEST(test_strtok_m) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
783 cxmutstr str = cx_strdup(CX_STR("a,comma,separated,string"));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
784 cxstring delim = CX_STR(",");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
785 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
786 CxStrtokCtx ctx = cx_strtok_m(str, delim, 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
787 CX_TEST_ASSERT(ctx.str.ptr == str.ptr);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
788 CX_TEST_ASSERT(ctx.str.length == str.length);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
789 CX_TEST_ASSERT(ctx.delim.ptr == delim.ptr);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
790 CX_TEST_ASSERT(ctx.delim.length == delim.length);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
791 CX_TEST_ASSERT(ctx.limit == 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
792 CX_TEST_ASSERT(ctx.found == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
793 CX_TEST_ASSERT(ctx.pos == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
794 CX_TEST_ASSERT(ctx.next_pos == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
795 CX_TEST_ASSERT(ctx.delim_more == NULL);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
796 CX_TEST_ASSERT(ctx.delim_more_count == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
797 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
798 cx_strfree(&str);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
799 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
800
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
801 CX_TEST(test_strtok_delim) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
802 cxstring str = CX_STR("an,arbitrarily|separated;string");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
803 cxstring delim = CX_STR(",");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
804 cxstring delim_more[2] = {CX_STR("|"), CX_STR(";")};
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
805 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
806 CxStrtokCtx ctx = cx_strtok(str, delim, 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
807 cx_strtok_delim(&ctx, delim_more, 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
808 CX_TEST_ASSERT(ctx.str.ptr == str.ptr);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
809 CX_TEST_ASSERT(ctx.str.length == str.length);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
810 CX_TEST_ASSERT(ctx.delim.ptr == delim.ptr);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
811 CX_TEST_ASSERT(ctx.delim.length == delim.length);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
812 CX_TEST_ASSERT(ctx.limit == 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
813 CX_TEST_ASSERT(ctx.found == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
814 CX_TEST_ASSERT(ctx.pos == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
815 CX_TEST_ASSERT(ctx.next_pos == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
816 CX_TEST_ASSERT(ctx.delim_more == delim_more);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
817 CX_TEST_ASSERT(ctx.delim_more_count == 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
818 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
819 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
820
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
821 CX_TEST(test_strtok_next_easy) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
822 cxstring str = CX_STR("a,comma,separated,string");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
823 cxstring delim = CX_STR(",");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
824 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
825 CxStrtokCtx ctx = cx_strtok(str, delim, 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
826 bool ret;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
827 cxstring tok;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
828
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
829 ret = cx_strtok_next(&ctx, &tok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
830 CX_TEST_ASSERT(ret);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
831 CX_TEST_ASSERT(0 == cx_strcmp(tok, CX_STR("a")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
832 CX_TEST_ASSERT(ctx.pos == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
833 CX_TEST_ASSERT(ctx.next_pos == 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
834 CX_TEST_ASSERT(ctx.delim_pos == 1);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
835 CX_TEST_ASSERT(ctx.found == 1);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
836
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
837 ret = cx_strtok_next(&ctx, &tok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
838 CX_TEST_ASSERT(ret);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
839 CX_TEST_ASSERT(0 == cx_strcmp(tok, CX_STR("comma")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
840 CX_TEST_ASSERT(ctx.pos == 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
841 CX_TEST_ASSERT(ctx.next_pos == 8);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
842 CX_TEST_ASSERT(ctx.delim_pos == 7);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
843 CX_TEST_ASSERT(ctx.found == 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
844
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
845 ret = cx_strtok_next(&ctx, &tok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
846 CX_TEST_ASSERT(ret);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
847 CX_TEST_ASSERT(0 == cx_strcmp(tok, CX_STR("separated")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
848 CX_TEST_ASSERT(ctx.pos == 8);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
849 CX_TEST_ASSERT(ctx.next_pos == 18);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
850 CX_TEST_ASSERT(ctx.delim_pos == 17);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
851 CX_TEST_ASSERT(ctx.found == 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
852
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
853 ret = cx_strtok_next(&ctx, &tok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
854 CX_TEST_ASSERT(!ret);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
855 CX_TEST_ASSERT(ctx.pos == 8);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
856 CX_TEST_ASSERT(ctx.next_pos == 18);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
857 CX_TEST_ASSERT(ctx.delim_pos == 17);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
858 CX_TEST_ASSERT(ctx.found == 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
859 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
860 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
861
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
862 CX_TEST(test_strtok_next_unlimited) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
863 cxstring str = CX_STR("some;-;otherwise;-;separated;-;string;-;");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
864 cxstring delim = CX_STR(";-;");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
865 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
866 CxStrtokCtx ctx = cx_strtok(str, delim, SIZE_MAX);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
867 bool ret;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
868 cxstring tok;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
869
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
870 ret = cx_strtok_next(&ctx, &tok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
871 CX_TEST_ASSERT(ret);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
872 CX_TEST_ASSERT(0 == cx_strcmp(tok, CX_STR("some")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
873 CX_TEST_ASSERT(ctx.pos == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
874 CX_TEST_ASSERT(ctx.next_pos == 7);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
875 CX_TEST_ASSERT(ctx.delim_pos == 4);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
876 CX_TEST_ASSERT(ctx.found == 1);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
877
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
878 ret = cx_strtok_next(&ctx, &tok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
879 CX_TEST_ASSERT(ret);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
880 CX_TEST_ASSERT(0 == cx_strcmp(tok, CX_STR("otherwise")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
881 CX_TEST_ASSERT(ctx.pos == 7);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
882 CX_TEST_ASSERT(ctx.next_pos == 19);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
883 CX_TEST_ASSERT(ctx.delim_pos == 16);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
884 CX_TEST_ASSERT(ctx.found == 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
885
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
886 ret = cx_strtok_next(&ctx, &tok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
887 CX_TEST_ASSERT(ret);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
888 CX_TEST_ASSERT(0 == cx_strcmp(tok, CX_STR("separated")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
889 CX_TEST_ASSERT(ctx.pos == 19);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
890 CX_TEST_ASSERT(ctx.next_pos == 31);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
891 CX_TEST_ASSERT(ctx.delim_pos == 28);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
892 CX_TEST_ASSERT(ctx.found == 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
893
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
894 ret = cx_strtok_next(&ctx, &tok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
895 CX_TEST_ASSERT(ret);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
896 CX_TEST_ASSERT(0 == cx_strcmp(tok, CX_STR("string")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
897 CX_TEST_ASSERT(ctx.pos == 31);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
898 CX_TEST_ASSERT(ctx.next_pos == 40);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
899 CX_TEST_ASSERT(ctx.delim_pos == 37);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
900 CX_TEST_ASSERT(ctx.found == 4);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
901
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
902 ret = cx_strtok_next(&ctx, &tok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
903 CX_TEST_ASSERT(ret);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
904 CX_TEST_ASSERT(0 == cx_strcmp(tok, CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
905 CX_TEST_ASSERT(ctx.pos == 40);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
906 CX_TEST_ASSERT(ctx.next_pos == 40);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
907 CX_TEST_ASSERT(ctx.delim_pos == 40);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
908 CX_TEST_ASSERT(ctx.found == 5);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
909
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
910 ret = cx_strtok_next(&ctx, &tok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
911 CX_TEST_ASSERT(!ret);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
912 CX_TEST_ASSERT(ctx.pos == 40);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
913 CX_TEST_ASSERT(ctx.delim_pos == 40);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
914 CX_TEST_ASSERT(ctx.found == 5);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
915 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
916 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
917
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
918 CX_TEST(test_strtok_next_advanced) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
919 cxmutstr str = cx_strdup(CX_STR("an,arbitrarily;||separated;string"));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
920 cxstring delim = CX_STR(",");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
921 cxstring delim_more[2] = {CX_STR("||"), CX_STR(";")};
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
922 CX_TEST_DO {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
923 CxStrtokCtx ctx = cx_strtok_m(str, delim, 10);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
924 cx_strtok_delim(&ctx, delim_more, 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
925 bool ret;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
926 cxmutstr tok;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
927
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
928 ret = cx_strtok_next_m(&ctx, &tok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
929 CX_TEST_ASSERT(ret);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
930 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), CX_STR("an")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
931 CX_TEST_ASSERT(ctx.pos == 0);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
932 CX_TEST_ASSERT(ctx.next_pos == 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
933 CX_TEST_ASSERT(ctx.delim_pos == 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
934 CX_TEST_ASSERT(ctx.found == 1);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
935 cx_strupper(tok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
936
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
937 ret = cx_strtok_next_m(&ctx, &tok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
938 CX_TEST_ASSERT(ret);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
939 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), CX_STR("arbitrarily")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
940 CX_TEST_ASSERT(ctx.pos == 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
941 CX_TEST_ASSERT(ctx.next_pos == 15);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
942 CX_TEST_ASSERT(ctx.delim_pos == 14);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
943 CX_TEST_ASSERT(ctx.found == 2);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
944 cx_strupper(tok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
945
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
946 ret = cx_strtok_next_m(&ctx, &tok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
947 CX_TEST_ASSERT(ret);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
948 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), CX_STR("")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
949 CX_TEST_ASSERT(ctx.pos == 15);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
950 CX_TEST_ASSERT(ctx.next_pos == 17);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
951 CX_TEST_ASSERT(ctx.delim_pos == 15);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
952 CX_TEST_ASSERT(ctx.found == 3);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
953 cx_strupper(tok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
954
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
955 ret = cx_strtok_next_m(&ctx, &tok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
956 CX_TEST_ASSERT(ret);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
957 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), CX_STR("separated")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
958 CX_TEST_ASSERT(ctx.pos == 17);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
959 CX_TEST_ASSERT(ctx.next_pos == 27);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
960 CX_TEST_ASSERT(ctx.delim_pos == 26);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
961 CX_TEST_ASSERT(ctx.found == 4);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
962 cx_strupper(tok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
963
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
964 ret = cx_strtok_next_m(&ctx, &tok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
965 CX_TEST_ASSERT(ret);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
966 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), CX_STR("string")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
967 CX_TEST_ASSERT(ctx.pos == 27);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
968 CX_TEST_ASSERT(ctx.next_pos == 33);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
969 CX_TEST_ASSERT(ctx.delim_pos == 33);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
970 CX_TEST_ASSERT(ctx.found == 5);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
971 cx_strupper(tok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
972
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
973 ret = cx_strtok_next_m(&ctx, &tok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
974 CX_TEST_ASSERT(!ret);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
975 CX_TEST_ASSERT(ctx.pos == 27);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
976 CX_TEST_ASSERT(ctx.next_pos == 33);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
977 CX_TEST_ASSERT(ctx.delim_pos == 33);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
978 CX_TEST_ASSERT(ctx.found == 5);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
979
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
980 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(str), CX_STR("AN,ARBITRARILY;||SEPARATED;STRING")));
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
981 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
982 cx_strfree(&str);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
983 }
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
984
1052
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
985 #define test_strtoint_impl(suffix, num, base, var, min, max) \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
986 do { \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
987 errno = 0; \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
988 int r = cx_strto##var(cx_str( #num), &var, base); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
989 if ((min) <= (num##suffix) && (num##suffix) <= (max)) { \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
990 CX_TEST_ASSERTM(0 == r, "failed for "#num); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
991 CX_TEST_ASSERT(0 == errno); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
992 CX_TEST_ASSERT((num##suffix) == (0##suffix)+(var)); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
993 } else { \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
994 CX_TEST_ASSERTM(0 != r, "out-of-range not detected for "#num " in variant "#var); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
995 CX_TEST_ASSERT(ERANGE == errno); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
996 } \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
997 } while (0)
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
998
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
999 #define test_strtoint_rollout_signed_impl(num, base) \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1000 test_strtoint_impl(LL, num, base, s, SHRT_MIN, SHRT_MAX); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1001 test_strtoint_impl(LL, num, base, i, INT_MIN, INT_MAX); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1002 test_strtoint_impl(LL, num, base, l, LONG_MIN, LONG_MAX); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1003 test_strtoint_impl(LL, num, base, ll, LLONG_MIN, LLONG_MAX); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1004 test_strtoint_impl(LL, num, base, i8, INT8_MIN, INT8_MAX); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1005 test_strtoint_impl(LL, num, base, i16, INT16_MIN, INT16_MAX); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1006 test_strtoint_impl(LL, num, base, i32, INT32_MIN, INT32_MAX); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1007 test_strtoint_impl(LL, num, base, i64, INT64_MIN, INT64_MAX); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1008 test_strtoint_impl(LL, num, base, z, -SSIZE_MAX-1, SSIZE_MAX)
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1009
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1010 #define test_strtoint_rollout_signed(num, base) \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1011 test_strtoint_rollout_signed_impl(num, base); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1012 test_strtoint_rollout_signed_impl(-num, base)
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1013
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1014 #define test_strtoint_rollout(num, base) \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1015 test_strtoint_impl(ULL, num, base, us, 0, USHRT_MAX); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1016 test_strtoint_impl(ULL, num, base, u, 0, UINT_MAX); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1017 test_strtoint_impl(ULL, num, base, ul, 0, ULONG_MAX); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1018 test_strtoint_impl(ULL, num, base, ull, 0, ULLONG_MAX); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1019 test_strtoint_impl(ULL, num, base, u8, 0, UINT8_MAX); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1020 test_strtoint_impl(ULL, num, base, u16, 0, UINT16_MAX); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1021 test_strtoint_impl(ULL, num, base, u32, 0, UINT32_MAX); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1022 test_strtoint_impl(ULL, num, base, u64, 0, UINT64_MAX); \
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1023 test_strtoint_impl(ULL, num, base, uz, 0, SIZE_MAX)
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1024
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1025 CX_TEST(test_string_to_signed_integer) {
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1026 short s;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1027 int i;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1028 long l;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1029 long long ll;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1030 int8_t i8;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1031 int16_t i16;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1032 int32_t i32;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1033 int64_t i64;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1034 ssize_t z;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1035 CX_TEST_DO {
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1036 // do some brute force tests with all ranges
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1037 test_strtoint_rollout_signed(47, 10);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1038 test_strtoint_rollout_signed(210, 10);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1039 test_strtoint_rollout_signed(5678, 10);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1040 test_strtoint_rollout_signed(40678, 10);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1041 test_strtoint_rollout_signed(1350266537, 10);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1042 test_strtoint_rollout_signed(3350266537, 10);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1043 test_strtoint_rollout_signed(473350266537, 10);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1044 test_strtoint_rollout_signed(057, 8);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1045 test_strtoint_rollout_signed(0322, 8);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1046 test_strtoint_rollout_signed(013056, 8);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1047 test_strtoint_rollout_signed(0117346, 8);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1048 test_strtoint_rollout_signed(012036667251, 8);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1049 test_strtoint_rollout_signed(030754201251, 8);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1050 test_strtoint_rollout_signed(06706567757251, 8);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1051 test_strtoint_rollout_signed(0767716340165362204025, 8);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1052 test_strtoint_rollout_signed(0x65, 16);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1053 test_strtoint_rollout_signed(0xf5, 16);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1054 test_strtoint_rollout_signed(0xABC5, 16);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1055 test_strtoint_rollout_signed(0xFBC5, 16);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1056 test_strtoint_rollout_signed(0x6df9CE03, 16);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1057 test_strtoint_rollout_signed(0xFdf9CE03, 16);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1058 test_strtoint_rollout_signed(0x6df9CE03AbC90815, 16);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1059 // TODO: roll out base 2 tests, but that needs C23
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1060
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1061 // do some special case tests
1061
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1062 // --------------------------
1052
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1063
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1064 // can fit only in unsigned long long
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1065 errno = 0;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1066 CX_TEST_ASSERT(0 != cx_strtoll(cx_str("0x8df9CE03AbC90815"), &ll, 16));
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1067 CX_TEST_ASSERT(errno == ERANGE);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1068
1061
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1069 // edge case: only the sign bit is set
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1070 errno = 0;
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1071 CX_TEST_ASSERT(0 != cx_strtoi16(cx_str("0x8000"), &i16, 16));
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1072 CX_TEST_ASSERT(errno == ERANGE);
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1073 errno = 0;
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1074 CX_TEST_ASSERT(0 == cx_strtoi16(cx_str("-0x8000"), &i16, 16));
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1075 CX_TEST_ASSERT(errno == 0);
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1076 CX_TEST_ASSERT(i16 == INT16_MIN);
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1077 errno = 0;
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1078 CX_TEST_ASSERT(0 != cx_strtoi64(cx_str("X8000000000000000"), &i64, 16));
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1079 CX_TEST_ASSERT(errno == ERANGE);
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1080 errno = 0;
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1081 CX_TEST_ASSERT(0 == cx_strtoi64(cx_str("-X8000000000000000"), &i64, 16));
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1082 CX_TEST_ASSERT(errno == 0);
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1083 CX_TEST_ASSERT(i64 == INT64_MIN);
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1084
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1085 // group separators
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1086 CX_TEST_ASSERT(0 == cx_strtoi32(cx_str(" -123,456"), &i32, 10));
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1087 CX_TEST_ASSERT(i32 == -123456);
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1088 errno = 0;
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1089 CX_TEST_ASSERT(0 != cx_strtoi16_lc(cx_str(" -Xab,cd"), &i16, 16, "'"));
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1090 CX_TEST_ASSERT(errno == EINVAL);
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1091 errno = 0;
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1092 CX_TEST_ASSERT(0 != cx_strtoi16_lc(cx_str(" -X'ab'cd"), &i16, 16, "'"));
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1093 CX_TEST_ASSERT(errno == ERANGE);
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1094 errno = 0;
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1095 CX_TEST_ASSERT(0 == cx_strtoi16_lc(cx_str(" -X'67'89"), &i16, 16, "'"));
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1096 CX_TEST_ASSERT(errno == 0);
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1097 CX_TEST_ASSERT(i16 == -0x6789);
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1098
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1099 // binary and (unusual notation of) signed binary
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1100 errno = 0;
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1101 CX_TEST_ASSERT(0 != cx_strtoi8_lc(cx_str(" -1010 1011"), &i8, 2, " "));
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1102 CX_TEST_ASSERT(errno == ERANGE);
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1103 errno = 0;
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1104 CX_TEST_ASSERT(0 != cx_strtoi8_lc(cx_str(" 1010 1011"), &i8, 2, " "));
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1105 CX_TEST_ASSERT(errno == ERANGE);
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1106 errno = 0;
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1107 CX_TEST_ASSERT(0 == cx_strtoi8_lc(cx_str(" -0101 0101"), &i8, 2, " "));
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1108 CX_TEST_ASSERT(errno == 0);
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1109 CX_TEST_ASSERT(i8 == -0x55);
1052
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1110 }
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1111 }
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1112
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1113 CX_TEST(test_string_to_unsigned_integer) {
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1114 unsigned short us;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1115 unsigned int u;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1116 unsigned long ul;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1117 unsigned long long ull;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1118 uint8_t u8;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1119 uint16_t u16;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1120 uint32_t u32;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1121 uint64_t u64;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1122 size_t uz;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1123 CX_TEST_DO {
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1124 // do some brute force tests with all ranges
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1125 test_strtoint_rollout(47, 10);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1126 test_strtoint_rollout(210, 10);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1127 test_strtoint_rollout(5678, 10);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1128 test_strtoint_rollout(40678, 10);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1129 test_strtoint_rollout(1350266537, 10);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1130 test_strtoint_rollout(3350266537, 10);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1131 test_strtoint_rollout(473350266537, 10);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1132 test_strtoint_rollout(057, 8);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1133 test_strtoint_rollout(0322, 8);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1134 test_strtoint_rollout(013056, 8);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1135 test_strtoint_rollout(0117346, 8);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1136 test_strtoint_rollout(012036667251, 8);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1137 test_strtoint_rollout(030754201251, 8);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1138 test_strtoint_rollout(06706567757251, 8);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1139 test_strtoint_rollout(01767716340165362204025, 8);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1140 test_strtoint_rollout(0x65, 16);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1141 test_strtoint_rollout(0xf5, 16);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1142 test_strtoint_rollout(0xABC5, 16);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1143 test_strtoint_rollout(0xFBC5, 16);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1144 test_strtoint_rollout(0x6df9CE03, 16);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1145 test_strtoint_rollout(0xFdf9CE03, 16);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1146 test_strtoint_rollout(0x6df9CE03AbC90815, 16);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1147 test_strtoint_rollout(0xfdf9CE03AbC90815, 16);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1148 // TODO: roll out base 2 tests, but that needs C23
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1149
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1150 // do some special case tests
1061
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1151 // --------------------------
1052
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1152
1061
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1153 // group separators
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1154 CX_TEST_ASSERT(0 == cx_strtou32(cx_str(" 123,456"), &u32, 10));
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1155 CX_TEST_ASSERT(u32 == 123456);
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1156 errno = 0;
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1157 CX_TEST_ASSERT(0 != cx_strtou16_lc(cx_str(" ab,cd"), &u16, 16, "'"));
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1158 CX_TEST_ASSERT(errno == EINVAL);
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1159 errno = 0;
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1160 CX_TEST_ASSERT(0 == cx_strtou16_lc(cx_str(" ab'cd"), &u16, 16, "'"));
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1161 CX_TEST_ASSERT(errno == 0);
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1162 CX_TEST_ASSERT(u16 == 0xabcd);
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1163
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1164 // binary
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1165 errno = 0;
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1166 CX_TEST_ASSERT(0 != cx_strtou8_lc(cx_str("1 1010 1011"), &u8, 2, " "));
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1167 CX_TEST_ASSERT(errno == ERANGE);
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1168 errno = 0;
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1169 CX_TEST_ASSERT(0 == cx_strtou8_lc(cx_str(" 1010 1011"), &u8, 2, " "));
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1170 CX_TEST_ASSERT(errno == 0);
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1171 CX_TEST_ASSERT(u8 == 0xAB);
1052
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1172 }
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1173 }
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1174
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1175 CX_TEST(test_string_to_float) {
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1176 float f;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1177 CX_TEST_DO {
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1178 CX_TEST_ASSERT(0 == cx_strtof(cx_str("11.3"), &f));
1063
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1179 CX_TEST_ASSERT(0 == cx_vcmp_float(11.3f, f));
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1180
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1181 CX_TEST_ASSERT(0 == cx_strtof(cx_str("-4.711e+1"), &f));
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1182 CX_TEST_ASSERT(0 == cx_vcmp_float(-47.11f, f));
1061
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1183
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1184 CX_TEST_ASSERT(0 == cx_strtof(cx_str("1.67262192595e-27"), &f));
1063
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1185 CX_TEST_ASSERT(0 == cx_vcmp_float(1.67262192595e-27f, f));
1061
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1186
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1187 CX_TEST_ASSERT(0 == cx_strtof_lc(cx_str("138,339.4"), &f, '.', ","));
1063
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1188 CX_TEST_ASSERT(0 == cx_vcmp_float(138339.4f, f));
1061
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1189
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1190 CX_TEST_ASSERT(0 == cx_strtof_lc(cx_str("138,339.4"), &f, ',', "."));
1063
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1191 CX_TEST_ASSERT(0 == cx_vcmp_float(138.3394f, f));
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1192
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1193 errno = 0;
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1194 CX_TEST_ASSERT(0 != cx_strtof(cx_str("15e"), &f));
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1195 CX_TEST_ASSERT(errno == EINVAL);
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1196 errno = 0;
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1197 CX_TEST_ASSERT(0 != cx_strtof(cx_str("15e+"), &f));
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1198 CX_TEST_ASSERT(errno == EINVAL);
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1199 errno = 0;
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1200 CX_TEST_ASSERT(0 != cx_strtof(cx_str("15e-"), &f));
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1201 CX_TEST_ASSERT(errno == EINVAL);
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1202 CX_TEST_ASSERT(0 == cx_strtof(cx_str("15e-0"), &f));
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1203 CX_TEST_ASSERT(0 == cx_vcmp_float(15.f, f));
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1204
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1205 CX_TEST_ASSERT(0 == cx_strtof(cx_str("3e38"), &f));
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1206 CX_TEST_ASSERT(0 == cx_vcmp_float(3e38f, f));
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1207 errno = 0;
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1208 CX_TEST_ASSERT(0 != cx_strtof(cx_str("3e39"), &f));
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1209 CX_TEST_ASSERT(errno == ERANGE);
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1210 CX_TEST_ASSERT(0 == cx_strtof(cx_str("-3e38"), &f));
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1211 CX_TEST_ASSERT(0 == cx_vcmp_float(-3e38f, f));
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1212 errno = 0;
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1213 CX_TEST_ASSERT(0 != cx_strtof(cx_str("-3e39"), &f));
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1214 CX_TEST_ASSERT(errno == ERANGE);
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1215 CX_TEST_ASSERT(0 == cx_strtof(cx_str("1.18e-38"), &f));
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1216 CX_TEST_ASSERT(0 == cx_vcmp_float(1.18e-38f, f));
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1217 errno = 0;
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1218 CX_TEST_ASSERT(0 != cx_strtof(cx_str("1.17e-38"), &f));
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1219 CX_TEST_ASSERT(errno == ERANGE);
1052
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1220 }
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1221 }
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1222
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1223 CX_TEST(test_string_to_double) {
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1224 double d;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1225 CX_TEST_DO {
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1226 CX_TEST_ASSERT(0 == cx_strtod(cx_str("11.3"), &d));
1063
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1227 CX_TEST_ASSERT(0 == cx_vcmp_double(11.3, d));
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1228
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1229 CX_TEST_ASSERT(0 == cx_strtod(cx_str("-13.37"), &d));
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1230 CX_TEST_ASSERT(0 == cx_vcmp_double(-13.37, d));
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1231
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1232 CX_TEST_ASSERT(0 == cx_strtod(cx_str("-4.711e+1"), &d));
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1233 CX_TEST_ASSERT(0 == cx_vcmp_double(-47.11, d));
1061
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1234
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1235 CX_TEST_ASSERT(0 == cx_strtod(cx_str("1.67262192595e-27"), &d));
1063
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1236 CX_TEST_ASSERT(0 == cx_vcmp_double(1.67262192595e-27, d));
1061
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1237
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1238 CX_TEST_ASSERT(0 == cx_strtod_lc(cx_str("138,339.4"), &d, '.', ","));
1063
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1239 CX_TEST_ASSERT(0 == cx_vcmp_double(138339.4, d));
1061
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1240
c7d23892eab5 implement string to integer conversions
Mike Becker <universe@uap-core.de>
parents: 1052
diff changeset
1241 CX_TEST_ASSERT(0 == cx_strtod_lc(cx_str("138,339.4"), &d, ',', "."));
1063
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1242 CX_TEST_ASSERT(0 == cx_vcmp_double(138.3394, d));
1052
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1243
1063
e453e717876e implement floating point string to number conversions
Mike Becker <universe@uap-core.de>
parents: 1061
diff changeset
1244 // TODO: test and improve support for big numbers, precision, and out-of-range detection
1052
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1245 }
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1246 }
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1247
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1248 CxTestSuite *cx_test_suite_string(void) {
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1249 CxTestSuite *suite = cx_test_suite_new("string");
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1250
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1251 cx_test_register(suite, test_string_construct);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1252 cx_test_register(suite, test_strfree);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1253 cx_test_register(suite, test_strdup);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1254 cx_test_register(suite, test_strdup_shortened);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1255 cx_test_register(suite, test_strlen);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1256 cx_test_register(suite, test_strsubs);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1257 cx_test_register(suite, test_strchr);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1258 cx_test_register(suite, test_strrchr);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1259 cx_test_register(suite, test_strstr);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1260 cx_test_register(suite, test_strcmp);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1261 cx_test_register(suite, test_strcasecmp);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1262 cx_test_register(suite, test_strcat);
1003
455afb252878 add test case to cover new branches inside cx_strcat_ma()
Mike Becker <universe@uap-core.de>
parents: 926
diff changeset
1263 cx_test_register(suite, test_strcat_more_than_eight);
777
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1264 cx_test_register(suite, test_strsplit);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1265 cx_test_register(suite, test_strsplit_a);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1266 cx_test_register(suite, test_strtrim);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1267 cx_test_register(suite, test_strprefix);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1268 cx_test_register(suite, test_strsuffix);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1269 cx_test_register(suite, test_strcaseprefix);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1270 cx_test_register(suite, test_strcasesuffix);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1271 cx_test_register(suite, test_strreplace);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1272 cx_test_register(suite, test_strupper);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1273 cx_test_register(suite, test_strlower);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1274 cx_test_register(suite, test_strtok);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1275 cx_test_register(suite, test_strtok_m);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1276 cx_test_register(suite, test_strtok_delim);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1277 cx_test_register(suite, test_strtok_next_easy);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1278 cx_test_register(suite, test_strtok_next_unlimited);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1279 cx_test_register(suite, test_strtok_next_advanced);
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1280
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1281 return suite;
e5b29e6f0615 migrate string tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1282 }
1052
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1283
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1284 CxTestSuite *cx_test_suite_string_to_number(void) {
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1285 CxTestSuite *suite = cx_test_suite_new("string to number");
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1286
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1287 cx_test_register(suite, test_string_to_signed_integer);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1288 cx_test_register(suite, test_string_to_unsigned_integer);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1289 cx_test_register(suite, test_string_to_float);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1290 cx_test_register(suite, test_string_to_double);
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1291
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1292 return suite;
e997862a57d8 add temporary implementations for string to number and first test cases
Mike Becker <universe@uap-core.de>
parents: 1003
diff changeset
1293 }

mercurial