1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // <regex>
10
11 // Test that replacing zero-length matches works correctly.
12
13 #include <cassert>
14 #include <regex>
15 #include <string>
16 #include "test_macros.h"
17
main(int,char **)18 int main(int, char**) {
19 // Various patterns that produce zero-length matches.
20 assert(std::regex_replace("abc", std::regex(""), "!") == "!a!b!c!");
21 assert(std::regex_replace("abc", std::regex("X*"), "!") == "!a!b!c!");
22 assert(std::regex_replace("abc", std::regex("X{0,3}"), "!") == "!a!b!c!");
23
24 // Replacement string has several characters.
25 assert(std::regex_replace("abc", std::regex(""), "[!]") == "[!]a[!]b[!]c[!]");
26
27 // Empty replacement string.
28 assert(std::regex_replace("abc", std::regex(""), "") == "abc");
29
30 // Empty input.
31 assert(std::regex_replace("", std::regex(""), "!") == "!");
32
33 // Not all matches are zero-length.
34 assert(std::regex_replace("abCabCa", std::regex("C*"), "!") == "!a!b!!a!b!!a!");
35
36 return 0;
37 }
38