Wed, 20 Dec 2023 16:46:14 +0100
bring back UCX test - fixes #341
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1 | /* |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
3 | * |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
5 | * |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
8 | * |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
11 | * |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
15 | * |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
27 | */ |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
28 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
29 | #include "cx/string.h" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
30 | #include "util_allocator.h" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
31 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
32 | #include <gtest/gtest.h> |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
33 | |
589
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
34 | #define EXPECT_ZERO_TERMINATED(str) EXPECT_EQ((str).ptr[(str).length], '\0') |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
35 | |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
36 | TEST(String, construct) { |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
37 | cxstring s1 = CX_STR("1234"); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
38 | cxstring s2 = cx_strn("abcd", 2); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
39 | cxmutstr s3 = cx_mutstr((char *) "1234"); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
40 | cxmutstr s4 = cx_mutstrn((char *) "abcd", 2); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
41 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
42 | EXPECT_EQ(s1.length, 4); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
43 | EXPECT_EQ(s2.length, 2); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
44 | EXPECT_EQ(s3.length, 4); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
45 | EXPECT_EQ(s4.length, 2); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
46 | } |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
47 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
48 | TEST(String, strfree) { |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
49 | CxTestingAllocator alloc; |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
50 | auto test = (char *) cxMalloc(&alloc, 16); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
51 | cxmutstr str = cx_mutstrn(test, 16); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
52 | ASSERT_EQ(str.ptr, test); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
53 | EXPECT_EQ(str.length, 16); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
54 | cx_strfree_a(&alloc, &str); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
55 | EXPECT_EQ(str.ptr, nullptr); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
56 | EXPECT_EQ(str.length, 0); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
57 | EXPECT_TRUE(alloc.verify()); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
58 | } |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
59 | |
589
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
60 | TEST(String, strdup) { |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
61 | cxstring str = CX_STR("test"); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
62 | cxmutstr dup = cx_strdup(str); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
63 | ASSERT_EQ(dup.length, str.length); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
64 | EXPECT_STREQ(dup.ptr, str.ptr); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
65 | EXPECT_ZERO_TERMINATED(dup); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
66 | cx_strfree(&dup); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
67 | |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
68 | str.length = 2; |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
69 | dup = cx_strdup(str); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
70 | ASSERT_EQ(dup.length, str.length); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
71 | EXPECT_STREQ(dup.ptr, "te"); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
72 | EXPECT_ZERO_TERMINATED(dup); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
73 | cx_strfree(&dup); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
74 | } |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
75 | |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
76 | TEST(String, strlen) { |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
77 | cxstring s1 = CX_STR("1234"); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
78 | cxstring s2 = CX_STR(".:.:."); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
79 | cxstring s3 = CX_STR("X"); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
80 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
81 | size_t len0 = cx_strlen(0); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
82 | size_t len1 = cx_strlen(1, s1); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
83 | size_t len2 = cx_strlen(2, s1, s2); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
84 | size_t len3 = cx_strlen(3, s1, s2, s3); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
85 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
86 | EXPECT_EQ(len0, 0); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
87 | EXPECT_EQ(len1, 4); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
88 | EXPECT_EQ(len2, 9); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
89 | EXPECT_EQ(len3, 10); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
90 | } |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
91 | |
585
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
92 | TEST(String, strsubs) { |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
93 | cxstring str = CX_STR("A test string"); |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
94 | |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
95 | cxstring sub = cx_strsubs(str, 0); |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
96 | EXPECT_EQ(cx_strcmp(sub, str), 0); |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
97 | |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
98 | sub = cx_strsubs(str, 2); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
99 | EXPECT_EQ(cx_strcmp(sub, CX_STR("test string")), 0); |
585
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
100 | |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
101 | sub = cx_strsubs(str, 7); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
102 | EXPECT_EQ(cx_strcmp(sub, CX_STR("string")), 0); |
585
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
103 | |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
104 | sub = cx_strsubs(str, 15); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
105 | EXPECT_EQ(cx_strcmp(sub, CX_STR("")), 0); |
585
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
106 | |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
107 | sub = cx_strsubsl(str, 2, 4); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
108 | EXPECT_EQ(cx_strcmp(sub, CX_STR("test")), 0); |
585
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
109 | |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
110 | sub = cx_strsubsl(str, 7, 3); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
111 | EXPECT_EQ(cx_strcmp(sub, CX_STR("str")), 0); |
585
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
112 | |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
113 | sub = cx_strsubsl(str, 7, 20); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
114 | EXPECT_EQ(cx_strcmp(sub, CX_STR("string")), 0); |
585
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
115 | |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
116 | // just for coverage, call the _m variant |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
117 | auto m = cx_strsubs_m(cx_mutstrn(nullptr, 0), 0); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
118 | EXPECT_EQ(cx_strcmp(cx_strcast(m), CX_STR("")), 0); |
585
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
119 | } |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
120 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
121 | TEST(String, strchr) { |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
122 | cxstring str = CX_STR("I will find you - and I will kill you"); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
123 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
124 | cxstring notfound = cx_strchr(str, 'x'); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
125 | EXPECT_EQ(notfound.length, 0); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
126 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
127 | cxstring result = cx_strchr(str, 'w'); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
128 | EXPECT_EQ(result.length, 35); |
587
3dd55e246d2d
use EXPECT_STREQ instead of strcmp
Mike Becker <universe@uap-core.de>
parents:
586
diff
changeset
|
129 | EXPECT_STREQ(result.ptr, "will find you - and I will kill you"); |
585
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
130 | |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
131 | // just for coverage, call the _m variant |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
132 | auto m = cx_strchr_m(cx_mutstrn(nullptr, 0), 'a'); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
133 | EXPECT_EQ(cx_strcmp(cx_strcast(m), CX_STR("")), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
134 | } |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
135 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
136 | TEST(String, strrchr) { |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
137 | cxstring str = CX_STR("I will find you - and I will kill you"); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
138 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
139 | cxstring notfound = cx_strrchr(str, 'x'); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
140 | EXPECT_EQ(notfound.length, 0); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
141 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
142 | cxstring result = cx_strrchr(str, 'w'); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
143 | EXPECT_EQ(result.length, 13); |
587
3dd55e246d2d
use EXPECT_STREQ instead of strcmp
Mike Becker <universe@uap-core.de>
parents:
586
diff
changeset
|
144 | EXPECT_STREQ(result.ptr, "will kill you"); |
585
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
145 | |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
146 | // just for coverage, call the _m variant |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
147 | auto m = cx_strrchr_m(cx_mutstrn(nullptr, 0), 'a'); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
148 | EXPECT_EQ(cx_strcmp(cx_strcast(m), CX_STR("")), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
149 | } |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
150 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
151 | TEST(String, strstr) { |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
152 | cxstring str = CX_STR("find the match in this string"); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
153 | cxstring longstr = CX_STR( |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
154 | "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
155 | "mnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
156 | "yzabcdeababababnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghij" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
157 | "klmnopqrstuvwxyzaababababababababrstuvwxyzabcdefghijklmnopqrstuv" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
158 | "abababababababababababababababababababababababababababababababab" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
159 | "abababababababababababababababababababababababababababababababab" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
160 | "abababababababababababababababababababababababababababababababab" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
161 | "abababababababababababababababababababababababababababababababab" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
162 | "abababababababababababababababababababababababababababababababab" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
163 | "abababababababababababababababababababababababababababababababab" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
164 | "wxyz1234567890"); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
165 | cxstring longstrpattern = CX_STR( |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
166 | "abababababababababababababababababababababababababababababababab" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
167 | "abababababababababababababababababababababababababababababababab" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
168 | "abababababababababababababababababababababababababababababababab" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
169 | "abababababababababababababababababababababababababababababababab" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
170 | "abababababababababababababababababababababababababababababababab" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
171 | ); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
172 | cxstring longstrresult = CX_STR( |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
173 | "abababababababababababababababababababababababababababababababab" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
174 | "abababababababababababababababababababababababababababababababab" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
175 | "abababababababababababababababababababababababababababababababab" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
176 | "abababababababababababababababababababababababababababababababab" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
177 | "abababababababababababababababababababababababababababababababab" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
178 | "abababababababababababababababababababababababababababababababab" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
179 | "wxyz1234567890" |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
180 | ); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
181 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
182 | cxstring notfound = cx_strstr(str, CX_STR("no match")); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
183 | EXPECT_EQ(notfound.length, 0); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
184 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
185 | cxstring result = cx_strstr(str, CX_STR("match")); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
186 | EXPECT_EQ(result.length, 20); |
587
3dd55e246d2d
use EXPECT_STREQ instead of strcmp
Mike Becker <universe@uap-core.de>
parents:
586
diff
changeset
|
187 | EXPECT_STREQ(result.ptr, "match in this string"); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
188 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
189 | result = cx_strstr(str, CX_STR("")); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
190 | EXPECT_EQ(result.length, str.length); |
587
3dd55e246d2d
use EXPECT_STREQ instead of strcmp
Mike Becker <universe@uap-core.de>
parents:
586
diff
changeset
|
191 | EXPECT_STREQ(result.ptr, str.ptr); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
192 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
193 | result = cx_strstr(longstr, longstrpattern); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
194 | EXPECT_EQ(result.length, longstrresult.length); |
587
3dd55e246d2d
use EXPECT_STREQ instead of strcmp
Mike Becker <universe@uap-core.de>
parents:
586
diff
changeset
|
195 | EXPECT_STREQ(result.ptr, longstrresult.ptr); |
585
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
196 | |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
197 | // just for coverage, call the _m variant |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
198 | auto mstr = cx_strdup(longstr); |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
199 | auto m = cx_strstr_m(mstr, longstrpattern); |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
200 | EXPECT_EQ(m.length, longstrresult.length); |
587
3dd55e246d2d
use EXPECT_STREQ instead of strcmp
Mike Becker <universe@uap-core.de>
parents:
586
diff
changeset
|
201 | EXPECT_STREQ(m.ptr, longstrresult.ptr); |
585
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
202 | cx_strfree(&mstr); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
203 | } |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
204 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
205 | TEST(String, strcmp) { |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
206 | cxstring str = CX_STR("compare this"); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
207 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
208 | EXPECT_EQ(cx_strcmp(CX_STR(""), CX_STR("")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
209 | EXPECT_GT(cx_strcmp(str, CX_STR("")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
210 | EXPECT_EQ(cx_strcmp(str, CX_STR("compare this")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
211 | EXPECT_NE(cx_strcmp(str, CX_STR("Compare This")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
212 | EXPECT_LT(cx_strcmp(str, CX_STR("compare tool")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
213 | EXPECT_GT(cx_strcmp(str, CX_STR("compare shit")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
214 | EXPECT_LT(cx_strcmp(str, CX_STR("compare this not")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
215 | EXPECT_GT(cx_strcmp(str, CX_STR("compare")), 0); |
671
d7a67375a7ac
test coverage for cx_strcmp pointer variants
Mike Becker <universe@uap-core.de>
parents:
653
diff
changeset
|
216 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
217 | cxstring str2 = CX_STR("Compare This"); |
671
d7a67375a7ac
test coverage for cx_strcmp pointer variants
Mike Becker <universe@uap-core.de>
parents:
653
diff
changeset
|
218 | EXPECT_NE(cx_strcmp_p(&str, &str2), 0); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
219 | str2 = CX_STR("compare this"); |
671
d7a67375a7ac
test coverage for cx_strcmp pointer variants
Mike Becker <universe@uap-core.de>
parents:
653
diff
changeset
|
220 | EXPECT_EQ(cx_strcmp_p(&str, &str2), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
221 | } |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
222 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
223 | TEST(String, strcasecmp) { |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
224 | cxstring str = CX_STR("compare this"); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
225 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
226 | EXPECT_EQ(cx_strcasecmp(CX_STR(""), CX_STR("")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
227 | EXPECT_GT(cx_strcasecmp(str, CX_STR("")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
228 | EXPECT_EQ(cx_strcasecmp(str, CX_STR("compare this")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
229 | EXPECT_EQ(cx_strcasecmp(str, CX_STR("Compare This")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
230 | EXPECT_LT(cx_strcasecmp(str, CX_STR("compare tool")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
231 | EXPECT_GT(cx_strcasecmp(str, CX_STR("compare shit")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
232 | EXPECT_LT(cx_strcasecmp(str, CX_STR("compare this not")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
233 | EXPECT_GT(cx_strcasecmp(str, CX_STR("compare")), 0); |
671
d7a67375a7ac
test coverage for cx_strcmp pointer variants
Mike Becker <universe@uap-core.de>
parents:
653
diff
changeset
|
234 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
235 | cxstring str2 = CX_STR("Compare This"); |
671
d7a67375a7ac
test coverage for cx_strcmp pointer variants
Mike Becker <universe@uap-core.de>
parents:
653
diff
changeset
|
236 | EXPECT_EQ(cx_strcasecmp_p(&str, &str2), 0); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
237 | str2 = CX_STR("Compare Tool"); |
671
d7a67375a7ac
test coverage for cx_strcmp pointer variants
Mike Becker <universe@uap-core.de>
parents:
653
diff
changeset
|
238 | EXPECT_LT(cx_strcasecmp_p(&str, &str2), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
239 | } |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
240 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
241 | TEST(String, strcat) { |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
242 | cxstring s1 = CX_STR("12"); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
243 | cxstring s2 = CX_STR("34"); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
244 | cxstring s3 = CX_STR("56"); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
245 | cxstring sn = {nullptr, 0}; |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
246 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
247 | CxTestingAllocator alloc; |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
248 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
249 | cxmutstr t1 = cx_strcat_a(&alloc, 2, s1, s2); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
250 | EXPECT_EQ(cx_strcmp(cx_strcast(t1), CX_STR("1234")), 0); |
589
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
251 | EXPECT_ZERO_TERMINATED(t1); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
252 | cx_strfree_a(&alloc, &t1); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
253 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
254 | cxmutstr t2 = cx_strcat_a(&alloc, 3, s1, s2, s3); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
255 | EXPECT_EQ(cx_strcmp(cx_strcast(t2), CX_STR("123456")), 0); |
589
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
256 | EXPECT_ZERO_TERMINATED(t2); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
257 | cx_strfree_a(&alloc, &t2); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
258 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
259 | cxmutstr t3 = cx_strcat_a(&alloc, 6, s1, sn, s2, sn, s3, sn); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
260 | EXPECT_EQ(cx_strcmp(cx_strcast(t3), CX_STR("123456")), 0); |
589
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
261 | EXPECT_ZERO_TERMINATED(t3); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
262 | cx_strfree_a(&alloc, &t3); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
263 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
264 | cxmutstr t4 = cx_strcat_a(&alloc, 2, sn, sn); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
265 | EXPECT_EQ(cx_strcmp(cx_strcast(t4), CX_STR("")), 0); |
589
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
266 | EXPECT_ZERO_TERMINATED(t4); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
267 | cx_strfree_a(&alloc, &t4); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
268 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
269 | EXPECT_TRUE(alloc.verify()); |
597
8b48126671cf
#217 cover cx_strcat macro
Mike Becker <universe@uap-core.de>
parents:
589
diff
changeset
|
270 | |
8b48126671cf
#217 cover cx_strcat macro
Mike Becker <universe@uap-core.de>
parents:
589
diff
changeset
|
271 | // use the macro |
8b48126671cf
#217 cover cx_strcat macro
Mike Becker <universe@uap-core.de>
parents:
589
diff
changeset
|
272 | cxmutstr t5 = cx_strcat(3, s3, s1, s2); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
273 | EXPECT_EQ(cx_strcmp(cx_strcast(t5), CX_STR("561234")), 0); |
597
8b48126671cf
#217 cover cx_strcat macro
Mike Becker <universe@uap-core.de>
parents:
589
diff
changeset
|
274 | EXPECT_ZERO_TERMINATED(t5); |
8b48126671cf
#217 cover cx_strcat macro
Mike Becker <universe@uap-core.de>
parents:
589
diff
changeset
|
275 | cx_strfree(&t5); |
697
ebdce4bf262b
add cx_strcat_m() and cx_strcat_ma() for in-place concatenation
Mike Becker <universe@uap-core.de>
parents:
684
diff
changeset
|
276 | |
ebdce4bf262b
add cx_strcat_m() and cx_strcat_ma() for in-place concatenation
Mike Becker <universe@uap-core.de>
parents:
684
diff
changeset
|
277 | // use an initial string |
ebdce4bf262b
add cx_strcat_m() and cx_strcat_ma() for in-place concatenation
Mike Becker <universe@uap-core.de>
parents:
684
diff
changeset
|
278 | cxmutstr t6 = cx_strdup(CX_STR("Hello")); |
ebdce4bf262b
add cx_strcat_m() and cx_strcat_ma() for in-place concatenation
Mike Becker <universe@uap-core.de>
parents:
684
diff
changeset
|
279 | t6 = cx_strcat_m(t6, 2, CX_STR(", "), CX_STR("World!")); |
ebdce4bf262b
add cx_strcat_m() and cx_strcat_ma() for in-place concatenation
Mike Becker <universe@uap-core.de>
parents:
684
diff
changeset
|
280 | EXPECT_EQ(cx_strcmp(cx_strcast(t6), CX_STR("Hello, World!")), 0); |
ebdce4bf262b
add cx_strcat_m() and cx_strcat_ma() for in-place concatenation
Mike Becker <universe@uap-core.de>
parents:
684
diff
changeset
|
281 | EXPECT_ZERO_TERMINATED(t6); |
ebdce4bf262b
add cx_strcat_m() and cx_strcat_ma() for in-place concatenation
Mike Becker <universe@uap-core.de>
parents:
684
diff
changeset
|
282 | cx_strfree(&t6); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
283 | } |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
284 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
285 | TEST(String, strsplit) { |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
286 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
287 | cxstring test = CX_STR("this,is,a,csv,string"); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
288 | size_t capa = 8; |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
289 | cxstring list[8]; |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
290 | size_t n; |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
291 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
292 | // special case: empty string |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
293 | n = cx_strsplit(test, CX_STR(""), capa, list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
294 | ASSERT_EQ(n, 1); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
295 | EXPECT_EQ(cx_strcmp(list[0], test), 0); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
296 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
297 | // no delimiter occurrence |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
298 | n = cx_strsplit(test, CX_STR("z"), capa, list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
299 | ASSERT_EQ(n, 1); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
300 | EXPECT_EQ(cx_strcmp(list[0], test), 0); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
301 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
302 | // partially matching delimiter |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
303 | n = cx_strsplit(test, CX_STR("is,not"), capa, list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
304 | ASSERT_EQ(n, 1); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
305 | EXPECT_EQ(cx_strcmp(list[0], test), 0); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
306 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
307 | // matching single-char delimiter |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
308 | n = cx_strsplit(test, CX_STR(","), capa, list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
309 | ASSERT_EQ(n, 5); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
310 | EXPECT_EQ(cx_strcmp(list[0], CX_STR("this")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
311 | EXPECT_EQ(cx_strcmp(list[1], CX_STR("is")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
312 | EXPECT_EQ(cx_strcmp(list[2], CX_STR("a")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
313 | EXPECT_EQ(cx_strcmp(list[3], CX_STR("csv")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
314 | EXPECT_EQ(cx_strcmp(list[4], CX_STR("string")), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
315 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
316 | // matching multi-char delimiter |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
317 | n = cx_strsplit(test, CX_STR("is"), capa, list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
318 | ASSERT_EQ(n, 3); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
319 | EXPECT_EQ(cx_strcmp(list[0], CX_STR("th")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
320 | EXPECT_EQ(cx_strcmp(list[1], CX_STR(",")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
321 | EXPECT_EQ(cx_strcmp(list[2], CX_STR(",a,csv,string")), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
322 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
323 | // bounded list using single-char delimiter |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
324 | n = cx_strsplit(test, CX_STR(","), 3, list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
325 | ASSERT_EQ(n, 3); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
326 | EXPECT_EQ(cx_strcmp(list[0], CX_STR("this")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
327 | EXPECT_EQ(cx_strcmp(list[1], CX_STR("is")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
328 | EXPECT_EQ(cx_strcmp(list[2], CX_STR("a,csv,string")), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
329 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
330 | // bounded list using multi-char delimiter |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
331 | n = cx_strsplit(test, CX_STR("is"), 2, list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
332 | ASSERT_EQ(n, 2); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
333 | EXPECT_EQ(cx_strcmp(list[0], CX_STR("th")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
334 | EXPECT_EQ(cx_strcmp(list[1], CX_STR(",is,a,csv,string")), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
335 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
336 | // start with delimiter |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
337 | n = cx_strsplit(test, CX_STR("this"), capa, list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
338 | ASSERT_EQ(n, 2); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
339 | EXPECT_EQ(cx_strcmp(list[0], CX_STR("")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
340 | EXPECT_EQ(cx_strcmp(list[1], CX_STR(",is,a,csv,string")), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
341 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
342 | // end with delimiter |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
343 | n = cx_strsplit(test, CX_STR("string"), capa, list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
344 | ASSERT_EQ(n, 2); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
345 | EXPECT_EQ(cx_strcmp(list[0], CX_STR("this,is,a,csv,")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
346 | EXPECT_EQ(cx_strcmp(list[1], CX_STR("")), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
347 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
348 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
349 | // end with delimiter exceed bound |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
350 | n = cx_strsplit(CX_STR("a,b,c,"), CX_STR(","), 3, list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
351 | ASSERT_EQ(n, 3); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
352 | EXPECT_EQ(cx_strcmp(list[0], CX_STR("a")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
353 | EXPECT_EQ(cx_strcmp(list[1], CX_STR("b")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
354 | EXPECT_EQ(cx_strcmp(list[2], CX_STR("c,")), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
355 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
356 | // exact match |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
357 | n = cx_strsplit(test, CX_STR("this,is,a,csv,string"), capa, list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
358 | ASSERT_EQ(n, 2); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
359 | EXPECT_EQ(cx_strcmp(list[0], CX_STR("")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
360 | EXPECT_EQ(cx_strcmp(list[1], CX_STR("")), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
361 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
362 | // string to be split is only substring |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
363 | n = cx_strsplit(test, CX_STR("this,is,a,csv,string,with,extension"), capa, list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
364 | ASSERT_EQ(n, 1); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
365 | EXPECT_EQ(cx_strcmp(list[0], test), 0); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
366 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
367 | // subsequent encounter of delimiter (the string between is empty) |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
368 | n = cx_strsplit(test, CX_STR("is,"), capa, list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
369 | ASSERT_EQ(n, 3); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
370 | EXPECT_EQ(cx_strcmp(list[0], CX_STR("th")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
371 | EXPECT_EQ(cx_strcmp(list[1], CX_STR("")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
372 | EXPECT_EQ(cx_strcmp(list[2], CX_STR("a,csv,string")), 0); |
585
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
373 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
374 | // call the _m variant just for coverage |
585
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
375 | auto mtest = cx_strdup(test); |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
376 | cxmutstr mlist[4]; |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
377 | n = cx_strsplit_m(mtest, CX_STR("is,"), 4, mlist); |
585
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
378 | ASSERT_EQ(n, 3); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
379 | EXPECT_EQ(cx_strcmp(cx_strcast(mlist[0]), CX_STR("th")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
380 | EXPECT_EQ(cx_strcmp(cx_strcast(mlist[1]), CX_STR("")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
381 | EXPECT_EQ(cx_strcmp(cx_strcast(mlist[2]), CX_STR("a,csv,string")), 0); |
585
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
382 | cx_strfree(&mtest); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
383 | } |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
384 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
385 | TEST(String, strsplit_a) { |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
386 | CxTestingAllocator alloc; |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
387 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
388 | cxstring test = CX_STR("this,is,a,csv,string"); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
389 | size_t capa = 8; |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
390 | cxstring *list; |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
391 | size_t n; |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
392 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
393 | // special case: empty string |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
394 | n = cx_strsplit_a(&alloc, test, CX_STR(""), capa, &list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
395 | ASSERT_EQ(n, 1); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
396 | EXPECT_EQ(cx_strcmp(list[0], test), 0); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
397 | cxFree(&alloc, list); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
398 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
399 | // no delimiter occurrence |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
400 | n = cx_strsplit_a(&alloc, test, CX_STR("z"), capa, &list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
401 | ASSERT_EQ(n, 1); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
402 | EXPECT_EQ(cx_strcmp(list[0], test), 0); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
403 | cxFree(&alloc, list); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
404 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
405 | // partially matching delimiter |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
406 | n = cx_strsplit_a(&alloc, test, CX_STR("is,not"), capa, &list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
407 | ASSERT_EQ(n, 1); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
408 | EXPECT_EQ(cx_strcmp(list[0], test), 0); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
409 | cxFree(&alloc, list); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
410 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
411 | // matching single-char delimiter |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
412 | n = cx_strsplit_a(&alloc, test, CX_STR(","), capa, &list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
413 | ASSERT_EQ(n, 5); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
414 | EXPECT_EQ(cx_strcmp(list[0], CX_STR("this")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
415 | EXPECT_EQ(cx_strcmp(list[1], CX_STR("is")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
416 | EXPECT_EQ(cx_strcmp(list[2], CX_STR("a")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
417 | EXPECT_EQ(cx_strcmp(list[3], CX_STR("csv")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
418 | EXPECT_EQ(cx_strcmp(list[4], CX_STR("string")), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
419 | cxFree(&alloc, list); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
420 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
421 | // matching multi-char delimiter |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
422 | n = cx_strsplit_a(&alloc, test, CX_STR("is"), capa, &list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
423 | ASSERT_EQ(n, 3); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
424 | EXPECT_EQ(cx_strcmp(list[0], CX_STR("th")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
425 | EXPECT_EQ(cx_strcmp(list[1], CX_STR(",")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
426 | EXPECT_EQ(cx_strcmp(list[2], CX_STR(",a,csv,string")), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
427 | cxFree(&alloc, list); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
428 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
429 | // bounded list using single-char delimiter |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
430 | n = cx_strsplit_a(&alloc, test, CX_STR(","), 3, &list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
431 | ASSERT_EQ(n, 3); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
432 | EXPECT_EQ(cx_strcmp(list[0], CX_STR("this")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
433 | EXPECT_EQ(cx_strcmp(list[1], CX_STR("is")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
434 | EXPECT_EQ(cx_strcmp(list[2], CX_STR("a,csv,string")), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
435 | cxFree(&alloc, list); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
436 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
437 | // bounded list using multi-char delimiter |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
438 | n = cx_strsplit_a(&alloc, test, CX_STR("is"), 2, &list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
439 | ASSERT_EQ(n, 2); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
440 | EXPECT_EQ(cx_strcmp(list[0], CX_STR("th")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
441 | EXPECT_EQ(cx_strcmp(list[1], CX_STR(",is,a,csv,string")), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
442 | cxFree(&alloc, list); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
443 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
444 | // start with delimiter |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
445 | n = cx_strsplit_a(&alloc, test, CX_STR("this"), capa, &list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
446 | ASSERT_EQ(n, 2); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
447 | EXPECT_EQ(cx_strcmp(list[0], CX_STR("")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
448 | EXPECT_EQ(cx_strcmp(list[1], CX_STR(",is,a,csv,string")), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
449 | cxFree(&alloc, list); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
450 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
451 | // end with delimiter |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
452 | n = cx_strsplit_a(&alloc, test, CX_STR("string"), capa, &list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
453 | ASSERT_EQ(n, 2); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
454 | EXPECT_EQ(cx_strcmp(list[0], CX_STR("this,is,a,csv,")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
455 | EXPECT_EQ(cx_strcmp(list[1], CX_STR("")), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
456 | cxFree(&alloc, list); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
457 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
458 | // end with delimiter exceed bound |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
459 | n = cx_strsplit_a(&alloc, CX_STR("a,b,c,"), CX_STR(","), 3, &list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
460 | ASSERT_EQ(n, 3); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
461 | EXPECT_EQ(cx_strcmp(list[0], CX_STR("a")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
462 | EXPECT_EQ(cx_strcmp(list[1], CX_STR("b")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
463 | EXPECT_EQ(cx_strcmp(list[2], CX_STR("c,")), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
464 | cxFree(&alloc, list); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
465 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
466 | // exact match |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
467 | n = cx_strsplit_a(&alloc, test, CX_STR("this,is,a,csv,string"), capa, &list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
468 | ASSERT_EQ(n, 2); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
469 | EXPECT_EQ(cx_strcmp(list[0], CX_STR("")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
470 | EXPECT_EQ(cx_strcmp(list[1], CX_STR("")), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
471 | cxFree(&alloc, list); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
472 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
473 | // string to be split is only substring |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
474 | n = cx_strsplit_a(&alloc, test, CX_STR("this,is,a,csv,string,with,extension"), capa, &list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
475 | ASSERT_EQ(n, 1); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
476 | EXPECT_EQ(cx_strcmp(list[0], test), 0); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
477 | cxFree(&alloc, list); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
478 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
479 | // subsequent encounter of delimiter (the string between is empty) |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
480 | n = cx_strsplit_a(&alloc, test, CX_STR("is,"), capa, &list); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
481 | ASSERT_EQ(n, 3); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
482 | EXPECT_EQ(cx_strcmp(list[0], CX_STR("th")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
483 | EXPECT_EQ(cx_strcmp(list[1], CX_STR("")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
484 | EXPECT_EQ(cx_strcmp(list[2], CX_STR("a,csv,string")), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
485 | cxFree(&alloc, list); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
486 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
487 | // call the _m variant just for coverage |
585
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
488 | auto mtest = cx_strdup(test); |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
489 | cxmutstr *mlist; |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
490 | n = cx_strsplit_ma(&alloc, mtest, CX_STR("is,"), 4, &mlist); |
585
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
491 | ASSERT_EQ(n, 3); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
492 | EXPECT_EQ(cx_strcmp(cx_strcast(mlist[0]), CX_STR("th")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
493 | EXPECT_EQ(cx_strcmp(cx_strcast(mlist[1]), CX_STR("")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
494 | EXPECT_EQ(cx_strcmp(cx_strcast(mlist[2]), CX_STR("a,csv,string")), 0); |
585
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
495 | cxFree(&alloc, mlist); |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
496 | cx_strfree(&mtest); |
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
497 | |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
498 | EXPECT_TRUE(alloc.verify()); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
499 | } |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
500 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
501 | TEST(String, strtrim) { |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
502 | cxstring t1 = cx_strtrim(CX_STR(" ein test \t ")); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
503 | cxstring t2 = cx_strtrim(CX_STR("abc")); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
504 | cxstring t3 = cx_strtrim(CX_STR(" 123")); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
505 | cxstring t4 = cx_strtrim(CX_STR("xyz ")); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
506 | cxstring t5 = cx_strtrim(CX_STR(" ")); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
507 | cxstring empty = cx_strtrim(CX_STR("")); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
508 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
509 | EXPECT_EQ(cx_strcmp(t1, CX_STR("ein test")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
510 | EXPECT_EQ(cx_strcmp(t2, CX_STR("abc")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
511 | EXPECT_EQ(cx_strcmp(t3, CX_STR("123")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
512 | EXPECT_EQ(cx_strcmp(t4, CX_STR("xyz")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
513 | EXPECT_EQ(cx_strcmp(t5, CX_STR("")), 0); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
514 | EXPECT_EQ(cx_strcmp(empty, CX_STR("")), 0); |
585
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
515 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
598
diff
changeset
|
516 | // call the _m variant just for coverage |
585
038f5e99e00f
add test coverage for _m variant functions
Mike Becker <universe@uap-core.de>
parents:
583
diff
changeset
|
517 | cxmutstr m1 = cx_strtrim_m(cx_mutstr((char *) " ein test \t ")); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
518 | EXPECT_EQ(cx_strcmp(cx_strcast(m1), CX_STR("ein test")), 0); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
519 | } |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
520 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
521 | TEST(String, strprefix) { |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
522 | cxstring str = CX_STR("test my prefix and my suffix"); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
523 | cxstring empty = CX_STR(""); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
524 | EXPECT_FALSE(cx_strprefix(empty, CX_STR("pref"))); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
525 | EXPECT_TRUE(cx_strprefix(str, empty)); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
526 | EXPECT_TRUE(cx_strprefix(empty, empty)); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
527 | EXPECT_TRUE(cx_strprefix(str, CX_STR("test "))); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
528 | EXPECT_FALSE(cx_strprefix(str, CX_STR("8-) fsck "))); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
529 | } |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
530 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
531 | TEST(String, strsuffix) { |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
532 | cxstring str = CX_STR("test my prefix and my suffix"); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
533 | cxstring empty = CX_STR(""); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
534 | EXPECT_FALSE(cx_strsuffix(empty, CX_STR("suf"))); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
535 | EXPECT_TRUE(cx_strsuffix(str, empty)); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
536 | EXPECT_TRUE(cx_strsuffix(empty, empty)); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
537 | EXPECT_TRUE(cx_strsuffix(str, CX_STR("fix"))); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
538 | EXPECT_FALSE(cx_strsuffix(str, CX_STR("fox"))); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
539 | } |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
540 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
541 | TEST(String, strcaseprefix) { |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
542 | cxstring str = CX_STR("test my prefix and my suffix"); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
543 | cxstring empty = CX_STR(""); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
544 | EXPECT_FALSE(cx_strcaseprefix(empty, CX_STR("pREf"))); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
545 | EXPECT_TRUE(cx_strcaseprefix(str, empty)); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
546 | EXPECT_TRUE(cx_strcaseprefix(empty, empty)); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
547 | EXPECT_TRUE(cx_strcaseprefix(str, CX_STR("TEST "))); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
548 | EXPECT_FALSE(cx_strcaseprefix(str, CX_STR("8-) fsck "))); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
549 | } |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
550 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
551 | TEST(String, strcasesuffix) { |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
552 | cxstring str = CX_STR("test my prefix and my suffix"); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
553 | cxstring empty = CX_STR(""); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
554 | EXPECT_FALSE(cx_strcasesuffix(empty, CX_STR("sUf"))); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
555 | EXPECT_TRUE(cx_strcasesuffix(str, empty)); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
556 | EXPECT_TRUE(cx_strcasesuffix(empty, empty)); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
557 | EXPECT_TRUE(cx_strcasesuffix(str, CX_STR("FIX"))); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
558 | EXPECT_FALSE(cx_strcasesuffix(str, CX_STR("fox"))); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
559 | } |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
560 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
561 | TEST(String, strreplace) { |
598
70b7456b5b12
#217 cover cx_strreplace_a() macro
Mike Becker <universe@uap-core.de>
parents:
597
diff
changeset
|
562 | CxTestingAllocator alloc; |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
563 | cxstring str = CX_STR("test ababab string aba"); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
564 | cxstring longstr = CX_STR( |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
565 | "xyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacd"); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
566 | cxstring notrail = CX_STR("test abab"); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
567 | cxstring empty = CX_STR(""); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
568 | cxstring astr = CX_STR("aaaaaaaaaa"); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
569 | cxstring csstr = CX_STR("test AB ab TEST xyz"); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
570 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
571 | cxmutstr repl = cx_strreplace(str, CX_STR("abab"), CX_STR("muchlonger")); |
589
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
572 | auto expected = "test muchlongerab string aba"; |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
573 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
574 | cxmutstr repln = cx_strreplacen(str, CX_STR("ab"), CX_STR("c"), 2); |
589
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
575 | auto expectedn = "test ccab string aba"; |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
576 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
577 | cxmutstr longrepl = cx_strreplace(longstr, CX_STR("a"), CX_STR("z")); |
589
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
578 | auto longexpect = "xyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzcd"; |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
579 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
580 | cxmutstr replnotrail = cx_strreplace(notrail, CX_STR("ab"), CX_STR("z")); |
589
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
581 | auto notrailexpect = "test zz"; |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
582 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
583 | cxmutstr repleq = cx_strreplace(str, str, CX_STR("hello")); |
589
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
584 | auto eqexpect = "hello"; |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
585 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
586 | cxmutstr replempty1 = cx_strreplace(empty, CX_STR("ab"), CX_STR("c")); // expect: empty |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
587 | cxmutstr replempty2 = cx_strreplace(str, CX_STR("abab"), empty); |
589
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
588 | auto emptyexpect2 = "test ab string aba"; |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
589 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
590 | cxmutstr replpre = cx_strreplace(str, CX_STR("test "), CX_STR("TEST ")); |
589
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
591 | auto preexpected = "TEST ababab string aba"; |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
592 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
593 | cxmutstr replan1 = cx_strreplacen(astr, CX_STR("a"), CX_STR("x"), 1); |
589
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
594 | auto an1expected = "xaaaaaaaaa"; |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
595 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
596 | cxmutstr replan4 = cx_strreplacen(astr, CX_STR("a"), CX_STR("x"), 4); |
589
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
597 | auto an4expected = "xxxxaaaaaa"; |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
598 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
599 | cxmutstr replan9 = cx_strreplacen(astr, CX_STR("a"), CX_STR("x"), 9); |
589
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
600 | auto an9expected = "xxxxxxxxxa"; |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
601 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
602 | cxmutstr replan10 = cx_strreplacen(astr, CX_STR("a"), CX_STR("x"), 10); |
589
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
603 | auto an10expected = "xxxxxxxxxx"; |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
604 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
605 | cxmutstr repl1_a = cx_strreplace_a(&alloc, csstr, CX_STR("AB"), CX_STR("*")); |
598
70b7456b5b12
#217 cover cx_strreplace_a() macro
Mike Becker <universe@uap-core.de>
parents:
597
diff
changeset
|
606 | auto expeced1_a = "test * ab TEST xyz"; |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
607 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
608 | cxmutstr repl2_a = cx_strreplace_a(&alloc, csstr, CX_STR("test"), CX_STR("TEST")); |
598
70b7456b5b12
#217 cover cx_strreplace_a() macro
Mike Becker <universe@uap-core.de>
parents:
597
diff
changeset
|
609 | auto expected2_a = "TEST AB ab TEST xyz"; |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
610 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
611 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
612 | EXPECT_NE(repl.ptr, str.ptr); |
589
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
613 | EXPECT_ZERO_TERMINATED(repl); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
614 | EXPECT_STREQ(repl.ptr, expected); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
615 | EXPECT_ZERO_TERMINATED(repln); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
616 | EXPECT_STREQ(repln.ptr, expectedn); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
617 | EXPECT_ZERO_TERMINATED(longrepl); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
618 | EXPECT_STREQ(longrepl.ptr, longexpect); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
619 | EXPECT_ZERO_TERMINATED(replnotrail); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
620 | EXPECT_STREQ(replnotrail.ptr, notrailexpect); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
621 | EXPECT_ZERO_TERMINATED(repleq); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
622 | EXPECT_STREQ(repleq.ptr, eqexpect); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
623 | EXPECT_ZERO_TERMINATED(replempty1); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
624 | EXPECT_STREQ(replempty1.ptr, ""); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
625 | EXPECT_ZERO_TERMINATED(replempty2); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
626 | EXPECT_STREQ(replempty2.ptr, emptyexpect2); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
627 | EXPECT_ZERO_TERMINATED(replpre); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
628 | EXPECT_STREQ(replpre.ptr, preexpected); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
629 | EXPECT_ZERO_TERMINATED(replan1); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
630 | EXPECT_STREQ(replan1.ptr, an1expected); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
631 | EXPECT_ZERO_TERMINATED(replan4); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
632 | EXPECT_STREQ(replan4.ptr, an4expected); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
633 | EXPECT_ZERO_TERMINATED(replan9); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
634 | EXPECT_STREQ(replan9.ptr, an9expected); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
635 | EXPECT_ZERO_TERMINATED(replan10); |
c290f8fd979e
add zero-termination guarantees
Mike Becker <universe@uap-core.de>
parents:
588
diff
changeset
|
636 | EXPECT_STREQ(replan10.ptr, an10expected); |
598
70b7456b5b12
#217 cover cx_strreplace_a() macro
Mike Becker <universe@uap-core.de>
parents:
597
diff
changeset
|
637 | EXPECT_ZERO_TERMINATED(repl1_a); |
70b7456b5b12
#217 cover cx_strreplace_a() macro
Mike Becker <universe@uap-core.de>
parents:
597
diff
changeset
|
638 | EXPECT_STREQ(repl1_a.ptr, expeced1_a); |
70b7456b5b12
#217 cover cx_strreplace_a() macro
Mike Becker <universe@uap-core.de>
parents:
597
diff
changeset
|
639 | EXPECT_ZERO_TERMINATED(repl2_a); |
70b7456b5b12
#217 cover cx_strreplace_a() macro
Mike Becker <universe@uap-core.de>
parents:
597
diff
changeset
|
640 | EXPECT_STREQ(repl2_a.ptr, expected2_a); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
641 | |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
642 | cx_strfree(&repl); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
643 | cx_strfree(&repln); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
644 | cx_strfree(&longrepl); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
645 | cx_strfree(&replnotrail); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
646 | cx_strfree(&repleq); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
647 | cx_strfree(&replempty1); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
648 | cx_strfree(&replempty2); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
649 | cx_strfree(&replpre); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
650 | cx_strfree(&replan1); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
651 | cx_strfree(&replan4); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
652 | cx_strfree(&replan9); |
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
653 | cx_strfree(&replan10); |
598
70b7456b5b12
#217 cover cx_strreplace_a() macro
Mike Becker <universe@uap-core.de>
parents:
597
diff
changeset
|
654 | |
70b7456b5b12
#217 cover cx_strreplace_a() macro
Mike Becker <universe@uap-core.de>
parents:
597
diff
changeset
|
655 | cx_strfree_a(&alloc, &repl1_a); |
70b7456b5b12
#217 cover cx_strreplace_a() macro
Mike Becker <universe@uap-core.de>
parents:
597
diff
changeset
|
656 | cx_strfree_a(&alloc, &repl2_a); |
70b7456b5b12
#217 cover cx_strreplace_a() macro
Mike Becker <universe@uap-core.de>
parents:
597
diff
changeset
|
657 | EXPECT_TRUE(alloc.verify()); |
583
0f3c9662f9b5
add tests and missing implementations for strings
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
658 | } |
586
aa51aaa907b9
add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents:
585
diff
changeset
|
659 | |
aa51aaa907b9
add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents:
585
diff
changeset
|
660 | TEST(String, strupper) { |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
661 | cxmutstr str = cx_strdup(CX_STR("thIs 1s @ Te$t")); |
586
aa51aaa907b9
add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents:
585
diff
changeset
|
662 | cx_strupper(str); |
aa51aaa907b9
add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents:
585
diff
changeset
|
663 | EXPECT_STREQ(str.ptr, "THIS 1S @ TE$T"); |
aa51aaa907b9
add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents:
585
diff
changeset
|
664 | cx_strfree(&str); |
aa51aaa907b9
add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents:
585
diff
changeset
|
665 | } |
aa51aaa907b9
add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents:
585
diff
changeset
|
666 | |
aa51aaa907b9
add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents:
585
diff
changeset
|
667 | TEST(String, strlower) { |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
668 | cxmutstr str = cx_strdup(CX_STR("thIs 1s @ Te$t")); |
586
aa51aaa907b9
add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents:
585
diff
changeset
|
669 | cx_strlower(str); |
aa51aaa907b9
add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents:
585
diff
changeset
|
670 | EXPECT_STREQ(str.ptr, "this 1s @ te$t"); |
aa51aaa907b9
add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents:
585
diff
changeset
|
671 | cx_strfree(&str); |
aa51aaa907b9
add tests for strupper and strlower
Mike Becker <universe@uap-core.de>
parents:
585
diff
changeset
|
672 | } |
645
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
673 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
674 | TEST(String, strtok) { |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
675 | cxstring str = CX_STR("a,comma,separated,string"); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
676 | cxstring delim = CX_STR(","); |
645
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
677 | CxStrtokCtx ctx = cx_strtok(str, delim, 3); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
678 | EXPECT_EQ(ctx.str.ptr, str.ptr); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
679 | EXPECT_EQ(ctx.str.length, str.length); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
680 | EXPECT_EQ(ctx.delim.ptr, delim.ptr); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
681 | EXPECT_EQ(ctx.delim.length, delim.length); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
682 | EXPECT_EQ(ctx.limit, 3); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
683 | EXPECT_EQ(ctx.found, 0); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
684 | EXPECT_EQ(ctx.pos, 0); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
685 | EXPECT_EQ(ctx.next_pos, 0); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
686 | EXPECT_EQ(ctx.delim_more, nullptr); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
687 | EXPECT_EQ(ctx.delim_more_count, 0); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
688 | } |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
689 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
690 | TEST(String, strtok_m) { |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
691 | cxmutstr str = cx_strdup(CX_STR("a,comma,separated,string")); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
692 | cxstring delim = CX_STR(","); |
645
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
693 | CxStrtokCtx ctx = cx_strtok_m(str, delim, 3); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
694 | EXPECT_EQ(ctx.str.ptr, str.ptr); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
695 | EXPECT_EQ(ctx.str.length, str.length); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
696 | EXPECT_EQ(ctx.delim.ptr, delim.ptr); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
697 | EXPECT_EQ(ctx.delim.length, delim.length); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
698 | EXPECT_EQ(ctx.limit, 3); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
699 | EXPECT_EQ(ctx.found, 0); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
700 | EXPECT_EQ(ctx.pos, 0); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
701 | EXPECT_EQ(ctx.next_pos, 0); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
702 | EXPECT_EQ(ctx.delim_more, nullptr); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
703 | EXPECT_EQ(ctx.delim_more_count, 0); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
704 | cx_strfree(&str); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
705 | } |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
706 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
707 | TEST(String, strtok_delim) { |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
708 | cxstring str = CX_STR("an,arbitrarily|separated;string"); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
709 | cxstring delim = CX_STR(","); |
645
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
710 | cxstring delim_more[2] = {CX_STR("|"), CX_STR(";")}; |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
711 | CxStrtokCtx ctx = cx_strtok(str, delim, 3); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
712 | cx_strtok_delim(&ctx, delim_more, 2); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
713 | EXPECT_EQ(ctx.str.ptr, str.ptr); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
714 | EXPECT_EQ(ctx.str.length, str.length); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
715 | EXPECT_EQ(ctx.delim.ptr, delim.ptr); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
716 | EXPECT_EQ(ctx.delim.length, delim.length); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
717 | EXPECT_EQ(ctx.limit, 3); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
718 | EXPECT_EQ(ctx.found, 0); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
719 | EXPECT_EQ(ctx.pos, 0); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
720 | EXPECT_EQ(ctx.next_pos, 0); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
721 | EXPECT_EQ(ctx.delim_more, delim_more); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
722 | EXPECT_EQ(ctx.delim_more_count, 2); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
723 | } |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
724 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
725 | TEST(String, strtok_next_easy) { |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
726 | cxstring str = CX_STR("a,comma,separated,string"); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
727 | cxstring delim = CX_STR(","); |
645
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
728 | CxStrtokCtx ctx = cx_strtok(str, delim, 3); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
729 | bool ret; |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
730 | cxstring tok; |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
731 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
732 | ret = cx_strtok_next(&ctx, &tok); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
733 | ASSERT_TRUE(ret); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
734 | EXPECT_EQ(cx_strcmp(tok, CX_STR("a")), 0); |
645
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
735 | EXPECT_EQ(ctx.pos, 0); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
736 | EXPECT_EQ(ctx.next_pos, 2); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
737 | EXPECT_EQ(ctx.delim_pos, 1); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
738 | EXPECT_EQ(ctx.found, 1); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
739 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
740 | ret = cx_strtok_next(&ctx, &tok); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
741 | ASSERT_TRUE(ret); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
742 | EXPECT_EQ(cx_strcmp(tok, CX_STR("comma")), 0); |
645
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
743 | EXPECT_EQ(ctx.pos, 2); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
744 | EXPECT_EQ(ctx.next_pos, 8); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
745 | EXPECT_EQ(ctx.delim_pos, 7); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
746 | EXPECT_EQ(ctx.found, 2); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
747 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
748 | ret = cx_strtok_next(&ctx, &tok); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
749 | ASSERT_TRUE(ret); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
750 | EXPECT_EQ(cx_strcmp(tok, CX_STR("separated")), 0); |
645
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
751 | EXPECT_EQ(ctx.pos, 8); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
752 | EXPECT_EQ(ctx.next_pos, 18); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
753 | EXPECT_EQ(ctx.delim_pos, 17); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
754 | EXPECT_EQ(ctx.found, 3); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
755 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
756 | ret = cx_strtok_next(&ctx, &tok); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
757 | ASSERT_FALSE(ret); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
758 | EXPECT_EQ(ctx.pos, 8); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
759 | EXPECT_EQ(ctx.next_pos, 18); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
760 | EXPECT_EQ(ctx.delim_pos, 17); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
761 | EXPECT_EQ(ctx.found, 3); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
762 | } |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
763 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
764 | TEST(String, strtok_next_unlimited) { |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
765 | cxstring str = CX_STR("some;-;otherwise;-;separated;-;string;-;"); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
766 | cxstring delim = CX_STR(";-;"); |
645
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
767 | CxStrtokCtx ctx = cx_strtok(str, delim, SIZE_MAX); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
768 | bool ret; |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
769 | cxstring tok; |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
770 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
771 | ret = cx_strtok_next(&ctx, &tok); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
772 | ASSERT_TRUE(ret); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
773 | EXPECT_EQ(cx_strcmp(tok, CX_STR("some")), 0); |
645
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
774 | EXPECT_EQ(ctx.pos, 0); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
775 | EXPECT_EQ(ctx.next_pos, 7); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
776 | EXPECT_EQ(ctx.delim_pos, 4); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
777 | EXPECT_EQ(ctx.found, 1); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
778 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
779 | ret = cx_strtok_next(&ctx, &tok); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
780 | ASSERT_TRUE(ret); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
781 | EXPECT_EQ(cx_strcmp(tok, CX_STR("otherwise")), 0); |
645
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
782 | EXPECT_EQ(ctx.pos, 7); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
783 | EXPECT_EQ(ctx.next_pos, 19); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
784 | EXPECT_EQ(ctx.delim_pos, 16); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
785 | EXPECT_EQ(ctx.found, 2); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
786 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
787 | ret = cx_strtok_next(&ctx, &tok); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
788 | ASSERT_TRUE(ret); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
789 | EXPECT_EQ(cx_strcmp(tok, CX_STR("separated")), 0); |
645
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
790 | EXPECT_EQ(ctx.pos, 19); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
791 | EXPECT_EQ(ctx.next_pos, 31); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
792 | EXPECT_EQ(ctx.delim_pos, 28); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
793 | EXPECT_EQ(ctx.found, 3); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
794 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
795 | ret = cx_strtok_next(&ctx, &tok); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
796 | ASSERT_TRUE(ret); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
797 | EXPECT_EQ(cx_strcmp(tok, CX_STR("string")), 0); |
645
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
798 | EXPECT_EQ(ctx.pos, 31); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
799 | EXPECT_EQ(ctx.next_pos, 40); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
800 | EXPECT_EQ(ctx.delim_pos, 37); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
801 | EXPECT_EQ(ctx.found, 4); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
802 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
803 | ret = cx_strtok_next(&ctx, &tok); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
804 | ASSERT_TRUE(ret); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
805 | EXPECT_EQ(cx_strcmp(tok, CX_STR("")), 0); |
645
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
806 | EXPECT_EQ(ctx.pos, 40); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
807 | EXPECT_EQ(ctx.next_pos, 40); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
808 | EXPECT_EQ(ctx.delim_pos, 40); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
809 | EXPECT_EQ(ctx.found, 5); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
810 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
811 | ret = cx_strtok_next(&ctx, &tok); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
812 | ASSERT_FALSE(ret); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
813 | EXPECT_EQ(ctx.pos, 40); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
814 | EXPECT_EQ(ctx.delim_pos, 40); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
815 | EXPECT_EQ(ctx.found, 5); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
816 | } |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
817 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
818 | TEST(String, strtok_next_advanced) { |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
819 | cxmutstr str = cx_strdup(CX_STR("an,arbitrarily;||separated;string")); |
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
820 | cxstring delim = CX_STR(","); |
645
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
821 | cxstring delim_more[2] = {CX_STR("||"), CX_STR(";")}; |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
822 | CxStrtokCtx ctx = cx_strtok_m(str, delim, 10); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
823 | cx_strtok_delim(&ctx, delim_more, 2); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
824 | bool ret; |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
825 | cxmutstr tok; |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
826 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
827 | ret = cx_strtok_next_m(&ctx, &tok); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
828 | ASSERT_TRUE(ret); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
829 | EXPECT_EQ(cx_strcmp(cx_strcast(tok), CX_STR("an")), 0); |
645
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
830 | EXPECT_EQ(ctx.pos, 0); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
831 | EXPECT_EQ(ctx.next_pos, 3); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
832 | EXPECT_EQ(ctx.delim_pos, 2); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
833 | EXPECT_EQ(ctx.found, 1); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
834 | cx_strupper(tok); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
835 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
836 | ret = cx_strtok_next_m(&ctx, &tok); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
837 | ASSERT_TRUE(ret); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
838 | EXPECT_EQ(cx_strcmp(cx_strcast(tok), CX_STR("arbitrarily")), 0); |
645
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
839 | EXPECT_EQ(ctx.pos, 3); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
840 | EXPECT_EQ(ctx.next_pos, 15); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
841 | EXPECT_EQ(ctx.delim_pos, 14); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
842 | EXPECT_EQ(ctx.found, 2); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
843 | cx_strupper(tok); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
844 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
845 | ret = cx_strtok_next_m(&ctx, &tok); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
846 | ASSERT_TRUE(ret); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
847 | EXPECT_EQ(cx_strcmp(cx_strcast(tok), CX_STR("")), 0); |
645
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
848 | EXPECT_EQ(ctx.pos, 15); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
849 | EXPECT_EQ(ctx.next_pos, 17); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
850 | EXPECT_EQ(ctx.delim_pos, 15); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
851 | EXPECT_EQ(ctx.found, 3); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
852 | cx_strupper(tok); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
853 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
854 | ret = cx_strtok_next_m(&ctx, &tok); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
855 | ASSERT_TRUE(ret); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
856 | EXPECT_EQ(cx_strcmp(cx_strcast(tok), CX_STR("separated")), 0); |
645
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
857 | EXPECT_EQ(ctx.pos, 17); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
858 | EXPECT_EQ(ctx.next_pos, 27); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
859 | EXPECT_EQ(ctx.delim_pos, 26); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
860 | EXPECT_EQ(ctx.found, 4); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
861 | cx_strupper(tok); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
862 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
863 | ret = cx_strtok_next_m(&ctx, &tok); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
864 | ASSERT_TRUE(ret); |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
865 | EXPECT_EQ(cx_strcmp(cx_strcast(tok), CX_STR("string")), 0); |
645
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
866 | EXPECT_EQ(ctx.pos, 27); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
867 | EXPECT_EQ(ctx.next_pos, 33); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
868 | EXPECT_EQ(ctx.delim_pos, 33); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
869 | EXPECT_EQ(ctx.found, 5); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
870 | cx_strupper(tok); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
871 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
872 | ret = cx_strtok_next_m(&ctx, &tok); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
873 | ASSERT_FALSE(ret); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
874 | EXPECT_EQ(ctx.pos, 27); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
875 | EXPECT_EQ(ctx.next_pos, 33); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
876 | EXPECT_EQ(ctx.delim_pos, 33); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
877 | EXPECT_EQ(ctx.found, 5); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
878 | |
684
380bd45bc94a
change CX_STR: use compound literal in C and ctor in C++
Mike Becker <universe@uap-core.de>
parents:
671
diff
changeset
|
879 | EXPECT_EQ(cx_strcmp(cx_strcast(str), CX_STR("AN,ARBITRARILY;||SEPARATED;STRING")), 0); |
645
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
880 | |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
881 | cx_strfree(&str); |
ec50abb285ad
add strtok API - fixes #220
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
882 | } |