1#######################################################
2#
3# Test readstringarray(), don't read comment, duplicate key or last line
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
341:2:3
35here is:a line: with spaces : in it
36blank:fields:::in here::
37:leading blank field
38this:is:a:test
39# A duplicate follows: this line is not always a comment
40this:also
41last:one";
42
43}
44
45body delete init_delete
46{
47      dirlinks => "delete";
48      rmdirs   => "true";
49}
50
51#######################################################
52
53bundle agent test
54{
55  vars:
56      "cnt" int => readstringarray("ary", "$(G.testfile)","NoComment",":",6,1000);
57      "num" int => "6";
58}
59
60#######################################################
61
62bundle agent check
63{
64  vars:
65      "idx" slist => getindices("test.ary");
66
67  classes:
68      "ok" and => {
69		    strcmp("$(test.num)", "$(test.cnt)"),
70
71		    strcmp("$(test.ary[0][0])", "0"),
72		    strcmp("$(test.ary[0][1])", "1"),
73		    strcmp("$(test.ary[0][2])", "2"),
74
75		    strcmp("$(test.ary[1][0])", "1"),
76		    strcmp("$(test.ary[1][1])", "2"),
77		    strcmp("$(test.ary[1][2])", "3"),
78
79		    strcmp("$(test.ary[here is][0])", "here is"),
80		    strcmp("$(test.ary[here is][1])", "a line"),
81		    strcmp("$(test.ary[here is][2])", " with spaces "),
82		    strcmp("$(test.ary[here is][3])", " in it"),
83
84		    strcmp("$(test.ary[blank][0])", "blank"),
85		    strcmp("$(test.ary[blank][1])", "fields"),
86		    strcmp("$(test.ary[blank][2])", ""),
87		    strcmp("$(test.ary[blank][3])", ""),
88		    strcmp("$(test.ary[blank][4])", "in here"),
89		    strcmp("$(test.ary[blank][5])", ""),
90		    strcmp("$(test.ary[blank][6])", ""),
91
92		    strcmp("$(test.ary[][0])", ""),
93		    strcmp("$(test.ary[][1])", "leading blank field"),
94
95		    strcmp("$(test.ary[this][0])", "this"),
96		    strcmp("$(test.ary[this][1])", "is"),
97		    strcmp("$(test.ary[this][2])", "a"),
98		    strcmp("$(test.ary[this][3])", "test"),
99      };
100
101  reports:
102    DEBUG::
103      "expected $(test.num) entries, saw $(test.cnt)";
104
105      "saw array indices '$(idx)'";
106
107      "expected test.ary[0][0] = '0', saw '$(test.ary[0][0])'";
108      "expected test.ary[0][1] = '1', saw '$(test.ary[0][1])'";
109      "expected test.ary[0][2] = '2', saw '$(test.ary[0][2])'";
110
111      "expected test.ary[1][0] = '1', saw '$(test.ary[1][0])'";
112      "expected test.ary[1][1] = '2', saw '$(test.ary[1][1])'";
113      "expected test.ary[1][2] = '3', saw '$(test.ary[1][2])'";
114
115      "expected test.ary[here is][0] = 'here is', saw '$(test.ary[here is][0])'";
116      "expected test.ary[here is][1] = 'a line', saw '$(test.ary[here is][1])'";
117      "expected test.ary[here is][2] = ' with spaces ', saw '$(test.ary[here is][2])'";
118      "expected test.ary[here is][3] = ' in it', saw '$(test.ary[here is][3])'";
119
120      "expected test.ary[blank][0] = 'blank', saw '$(test.ary[blank][0])'";
121      "expected test.ary[blank][1] = 'fields', saw '$(test.ary[blank][1])'";
122      "expected test.ary[blank][2] = '', saw '$(test.ary[blank][2])'";
123      "expected test.ary[blank][3] = '', saw '$(test.ary[blank][3])'";
124      "expected test.ary[blank][4] = 'in here', saw '$(test.ary[blank][4])'";
125      "expected test.ary[blank][5] = '', saw '$(test.ary[blank][5])'";
126      "expected test.ary[blank][6] = '', saw '$(test.ary[blank][6])'";
127
128      "expected test.ary[][0] = '', saw '$(test.ary[][0])'";
129      "expected test.ary[][1] = 'leading blank field', saw '$(test.ary[][1])'";
130
131      "expected test.ary[this][0] = 'this', saw '$(test.ary[this][0])'";
132      "expected test.ary[this][1] = 'is', saw '$(test.ary[this][1])'";
133      "expected test.ary[this][2] = 'a', saw '$(test.ary[this][2])'";
134      "expected test.ary[this][3] = 'test', saw '$(test.ary[this][3])'";
135
136      "expected test.ary[# A duplicate follows][0] = '# A duplicate follows', saw '$(test.ary[# A duplicate follows][0])'";
137      "expected test.ary[# A duplicate follows][1] = 'this line is not always a comment', saw '$(test.ary[# A duplicate follows][1])'";
138
139    ok::
140      "$(this.promise_filename) Pass";
141
142    !ok::
143      "$(this.promise_filename) FAIL";
144}
145