Debian Codegraph @

Tests/RunCMake/string/RegexEmptyMatch.cmake

raw
1 cmake_policy(SET CMP0186 NEW)
2
3 function(check_output name expected)
4 set(output "${${name}}")
5 if(NOT output STREQUAL expected)
6 message(FATAL_ERROR "\"string(REGEX)\" set ${name} to \"${output}\", expected \"${expected}\"")
7 endif()
8 endfunction()
9
10 # Zero-length matches in REGEX MATCH
11
12 string(REGEX MATCH "" out "")
13 check_output(out "")
14
15 string(REGEX MATCH "" out "a")
16 check_output(out "")
17
18 string(REGEX MATCH "a*" out "")
19 check_output(out "")
20
21 string(REGEX MATCH "a*" out "a")
22 check_output(out "a")
23
24 string(REGEX MATCH "a*" out "b")
25 check_output(out "")
26
27 string(REGEX MATCH "a*" out "ba")
28 check_output(out "")
29
30 # Zero-length matches in REGEX MATCHALL
31
32 string(REGEX MATCHALL "" out "")
33 check_output(out "")
34
35 string(REGEX MATCHALL "" out "ab")
36 check_output(out ";;")
37
38 string(REGEX MATCHALL "^" out "ab")
39 check_output(out "")
40
41 string(REGEX MATCHALL "(^|,)" out "a,b")
42 check_output(out ";,")
43
44 string(REGEX MATCHALL "(,|^)" out "a,b")
45 check_output(out ";,")
46
47 string(REGEX MATCHALL "(^|)" out "")
48 check_output(out "")
49
50 string(REGEX MATCHALL "(^|)" out "ab")
51 check_output(out ";;")
52
53 string(REGEX MATCHALL "a|^" out "ab")
54 check_output(out "a")
55
56 string(REGEX MATCHALL "$" out "ab")
57 check_output(out "")
58
59 string(REGEX MATCHALL "($|,)" out "a,b")
60 check_output(out ",;")
61
62 string(REGEX MATCHALL "(,|$)" out "a,b")
63 check_output(out ",;")
64
65 string(REGEX MATCHALL "(|$)" out "")
66 check_output(out "")
67
68 string(REGEX MATCHALL "(|$)" out "ab")
69 check_output(out ";;")
70
71 string(REGEX MATCHALL "(b|)" out "abc")
72 check_output(out ";b;;")
73
74 string(REGEX MATCHALL "(|b)" out "abc")
75 check_output(out ";;b;;")
76
77 string(REGEX MATCHALL "a*" out "aaa")
78 check_output(out "aaa;")
79
80 string(REGEX MATCHALL "(a)?(b)?" out "")
81 check_output(out "")
82
83 string(REGEX MATCHALL "(a)?(b)?" out "abba")
84 check_output(out "ab;b;a;")
85
86 # Zero-length matches in REGEX REPLACE
87
88 string(REGEX REPLACE "" "" out "")
89 check_output(out "")
90
91 string(REGEX REPLACE "" "x" out "")
92 check_output(out "x")
93
94 string(REGEX REPLACE "" "x" out "ab")
95 check_output(out "xaxbx")
96
97 string(REGEX REPLACE "^" "x" out "ab")
98 check_output(out "xab")
99
100 string(REGEX REPLACE "(^|,)" "x" out "a,b")
101 check_output(out "xaxb")
102
103 string(REGEX REPLACE "(,|^)" "x" out "a,b")
104 check_output(out "xaxb")
105
106 string(REGEX REPLACE "(^|)" "x" out "")
107 check_output(out "x")
108
109 string(REGEX REPLACE "(^|)" "x" out "ab")
110 check_output(out "xaxbx")
111
112 string(REGEX REPLACE "a|^" "x" out "ab")
113 check_output(out "xb")
114
115 string(REGEX REPLACE "$" "x" out "ab")
116 check_output(out "abx")
117
118 string(REGEX REPLACE "($|,)" "x" out "a,b")
119 check_output(out "axbx")
120
121 string(REGEX REPLACE "(,|$)" "x" out "a,b")
122 check_output(out "axbx")
123
124 string(REGEX REPLACE "(|$)" "x" out "")
125 check_output(out "x")
126
127 string(REGEX REPLACE "(|$)" "x" out "ab")
128 check_output(out "xaxbx")
129
130 string(REGEX REPLACE "(b|)" "x" out "abc")
131 check_output(out "xaxxcx")
132
133 string(REGEX REPLACE "(|b)" "x" out "abc")
134 check_output(out "xaxxxcx")
135
136 string(REGEX REPLACE "a*" "x" out "aaa")
137 check_output(out "xx")
138
139 string(REGEX REPLACE "(a)?(b)?" "x" out "")
140 check_output(out "x")
141
142 string(REGEX REPLACE "(a)?(b)?" "x" out "abba")
143 check_output(out "xxxx")