1#######################################################
2#
3# Test parsestringarray(), simple
4#
5# The 4xx tests are all related, and 400-419 are the readstringarray tests,
6# 420-439 the same for readstringarrayidx, 440-459 parsestringarray, and
7# 460-479 parsestringarrayidx
8#
9#######################################################
10
11body common control
12{
13      inputs => { "../../default.cf.sub" };
14      bundlesequence  => { default("$(this.promise_filename)") };
15      version => "1.0";
16}
17
18bundle agent init
19{
20  files:
21      "$(G.testfile)"
22      delete => init_delete;
23
24      "$(G.testfile)"
25      create => "true",
26      edit_line => init_fill_in;
27}
28
29bundle edit_line init_fill_in
30{
31  insert_lines:
32
33      "0:1:2
34this:is:a:test
351:2:3";
36
37}
38
39body delete init_delete
40{
41      dirlinks => "delete";
42      rmdirs   => "true";
43}
44
45#######################################################
46
47bundle agent test
48{
49  vars:
50      "teststr" string => readfile("$(G.testfile)",1000);
51      "cnt" int => parsestringarray("ary", "$(teststr)","NoComment",":",10,1000);
52      # ensure that bare words are OK
53      "ignore" int => parsestringarray("ary", "mydata","NoComment",":",10,1000);
54      "num" int => "3";
55}
56
57#######################################################
58
59bundle agent check
60{
61  vars:
62      "idx" slist => getindices("test.ary");
63
64  classes:
65      "good" and => {
66		      strcmp("$(test.num)", "$(test.cnt)"),
67
68		      strcmp("$(test.ary[0][0])", "0"),
69		      strcmp("$(test.ary[0][1])", "1"),
70		      strcmp("$(test.ary[0][2])", "2"),
71
72		      strcmp("$(test.ary[this][0])", "this"),
73		      strcmp("$(test.ary[this][1])", "is"),
74		      strcmp("$(test.ary[this][2])", "a"),
75		      strcmp("$(test.ary[this][3])", "test"),
76
77		      strcmp("$(test.ary[1][0])", "1"),
78		      strcmp("$(test.ary[1][1])", "2"),
79		      strcmp("$(test.ary[1][2])", "3"),
80      };
81
82      # Make sure there are no trailing elements
83      "bad" or => {
84		    isvariable("test.ary[0][3]"),
85		    isvariable("test.ary[this][4]"),
86		    isvariable("test.ary[1][3]"),
87      };
88
89      "ok" expression => "good&!bad";
90
91  reports:
92    DEBUG::
93      "expected $(test.num) entries, saw $(test.cnt)";
94
95      "saw array indices '$(idx)'";
96
97      "expected test.ary[0][0] = '0', saw '$(test.ary[0][0])'";
98      "expected test.ary[0][1] = '1', saw '$(test.ary[0][1])'";
99      "expected test.ary[0][2] = '2', saw '$(test.ary[0][2])'";
100
101      "expected test.ary[this][0] = 'this', saw '$(test.ary[this][0])'";
102      "expected test.ary[this][1] = 'is', saw '$(test.ary[this][1])'";
103      "expected test.ary[this][2] = 'a', saw '$(test.ary[this][2])'";
104      "expected test.ary[this][3] = 'test', saw '$(test.ary[this][3])'";
105
106      "expected test.ary[1][0] = '1', saw '$(test.ary[1][0])'";
107      "expected test.ary[1][1] = '2', saw '$(test.ary[1][1])'";
108      "expected test.ary[1][2] = '3', saw '$(test.ary[1][2])'";
109
110    ok::
111      "$(this.promise_filename) Pass";
112
113    !ok::
114      "$(this.promise_filename) FAIL";
115}
116