Skip to content

Commit aaa58b6

Browse files
committed
Updated tests for string_replace with lists
Signed-off-by: Victor Moene <victor.moene@northern.tech>
1 parent 682158b commit aaa58b6

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

examples/string_replace.cf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,25 @@ bundle agent main
3030

3131
# replace ambiguous order
3232
"replace_ambiguous" string => string_replace("aaaaa", "aaa", "b");
33+
"matches" slist => { "e", "r" };
34+
"subs" slist => { "E", "R" };
35+
36+
"replace_list"
37+
string => string_replace("Hello World", "@(matches)", "@(subs)", "lists");
38+
39+
"replace_list_json"
40+
string => string_replace(
41+
"Hello World", '["World", "o"]', '["Everyone", "0"]', "lists"
42+
);
3343

3444
reports:
3545
# in order, the above...
3646
"replace_once = '$(replace_once)'";
3747
"replace_several = '$(replace_several)'";
3848
"replace_none = '$(replace_none)'";
3949
"replace_ambiguous = '$(replace_ambiguous)'";
50+
"replace_list = '$(replace_list)'";
51+
"replace_list_json = '$(replace_list_json)'";
4052
}
4153

4254
#+end_src
@@ -47,5 +59,7 @@ bundle agent main
4759
#@ R: replace_several = 'Thos os a strong'
4860
#@ R: replace_none = 'This is a string'
4961
#@ R: replace_ambiguous = 'baa'
62+
#@ R: replace_list = 'HEllo WoRld'
63+
#@ R: replace_list_json = 'Hell0 Every0ne'
5064
#@ ```
5165
#+end_src

tests/acceptance/01_vars/02_functions/string_replace.cf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ bundle agent test
1616
vars:
1717
"test" string => "abcdefghij\t\n";
1818
"test2" string => "(){}[].*?";
19+
"match_list" slist => { "a", "b", "d" };
20+
"sub_list" slist => { "b", "c", "e" };
1921

2022
# normal tests
2123
"match_once" string => string_replace("abcd", "abc", "ABC");
@@ -35,6 +37,18 @@ bundle agent test
3537
# empty cases
3638
"empty" string => string_replace("", "abc", "ABC");
3739
"empty2" string => string_replace("", "abc", "");
40+
41+
# list
42+
"list_replace"
43+
string => string_replace("abcd", "@(match_list)", "@(sub_list)", "lists");
44+
45+
"list_replace_inline_json"
46+
string => string_replace(
47+
"Hello World",
48+
'["World", "o"]',
49+
parsejson('["Everyone", "0"]'),
50+
"lists"
51+
);
3852
}
3953

4054
#######################################################

tests/acceptance/01_vars/02_functions/string_replace.cf.expected.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
{
22
"empty": "",
33
"empty2": "",
4+
"list_replace": "ccce",
5+
"list_replace_inline_json": "Hell0 Every0ne",
6+
"match_list": [
7+
"a",
8+
"b",
9+
"d"
10+
],
411
"match_none": "abdc",
512
"match_none2": "abcdefghij\\t\\n",
613
"match_once": "ABCd",
@@ -12,6 +19,11 @@
1219
"special": "1{}[].*?",
1320
"special2": "()\\1[].*?",
1421
"special3": "(){}[]\\2",
22+
"sub_list": [
23+
"b",
24+
"c",
25+
"e"
26+
],
1527
"test": "abcdefghij\\t\\n",
1628
"test2": "(){}[].*?"
1729
}

0 commit comments

Comments
 (0)