1#######################################################
2#
3# Test regex_replace function
4#
5#######################################################
6
7body common control
8{
9      inputs => { "../../default.cf.sub" };
10      bundlesequence  => { default("$(this.promise_filename)") };
11      version => "1.0";
12}
13
14#######################################################
15
16bundle agent test
17{
18  vars:
19      "test" string => "abcdefghij";
20
21      # replace the empty string with empty string, globally
22      "void" string => regex_replace($(test), "", "", "g");
23      # replace any character with empty string, globally
24      "void1" string => regex_replace($(test), ".", "", "g");
25      # replace the empty string with 'x', globally (matches on character boundaries)
26      "void2" string => regex_replace($(test), "", "x", "g");
27
28      # replace the whole string
29      "allofitwithTEST" string => regex_replace($(test), ".*", "TEST", "");
30      # no matches, original intact
31      "nomatch" string => regex_replace($(test), "nonesuch", "TEST", "g");
32      "nomatch2" string => regex_replace($(test), "nonesuch", "TEST\1\2\3\4\5\6\7\8\9", "g");
33      # replace any character with -DOT-
34      "dots_everywhere" string => regex_replace($(test), ".", "-DOT-", "g");
35      # capture any three characters and replace with a backreference
36      "cap123" string => regex_replace($(test), "(...)", "[cap=$1]", "g");
37      # capture any three characters and replace with a backreference
38      "cap123_backslash" string => regex_replace($(test), "(...)", "[cap=\1]", "g");
39      # note that this is the same as above because the CFE parser tries to be clever in this case, converting \\1 to \1
40      "cap123_backslash2" string => regex_replace($(test), "(...)", "[cap=\\1]", "g");
41      "cap123_backslashes1to9missing" string => regex_replace($(test), "...", "[cap=\1\2\3\4\5\6\7\8\9]", "g");
42      "cap123_backslashes1to9havesome" string => regex_replace($(test), "(.)(.)(.)", "[cap=\1\2\3\4\5\6\7\8\9]", "g");
43      # match ABC case-insensitive and replace with ABC
44      "simple_nocase" string => regex_replace($(test), "ABC", "ABC", "gi"); # case-insensitive
45      # match abc and replace with ABC
46      "simple" string => regex_replace($(test), "abc", "ABC", "g");
47
48      # empty cases
49      "empty1" string => regex_replace("", "abc", "ABC", "g");
50      "empty2" string => regex_replace("", "abc", "", "g");
51}
52
53#######################################################
54
55bundle agent check
56{
57  methods:
58      "check"  usebundle => dcs_check_state(test,
59                                           "$(this.promise_filename).expected.json",
60                                           $(this.promise_filename));
61}
62