1#######################################################
2#
3# Test readstringarrayidx(), add some weird indices (including a duplicate)
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 => readstringarrayidx("ary", "$(G.testfile)","NoComment",":",10,1000);
57      "num" int => "9";
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[2][0])", "here is"),
80		    strcmp("$(test.ary[2][1])", "a line"),
81		    strcmp("$(test.ary[2][2])", " with spaces "),
82		    strcmp("$(test.ary[2][3])", " in it"),
83
84		    strcmp("$(test.ary[3][0])", "blank"),
85		    strcmp("$(test.ary[3][1])", "fields"),
86		    strcmp("$(test.ary[3][2])", ""),
87		    strcmp("$(test.ary[3][3])", ""),
88		    strcmp("$(test.ary[3][4])", "in here"),
89		    strcmp("$(test.ary[3][5])", ""),
90		    strcmp("$(test.ary[3][6])", ""),
91
92		    strcmp("$(test.ary[4][0])", ""),
93		    strcmp("$(test.ary[4][1])", "leading blank field"),
94
95		    strcmp("$(test.ary[5][0])", "this"),
96		    strcmp("$(test.ary[5][1])", "is"),
97		    strcmp("$(test.ary[5][2])", "a"),
98		    strcmp("$(test.ary[5][3])", "test"),
99
100		    strcmp("$(test.ary[6][0])", "# A duplicate follows"),
101		    strcmp("$(test.ary[6][1])", " this line is not always a comment"),
102
103		    strcmp("$(test.ary[7][0])", "this"),
104		    strcmp("$(test.ary[7][1])", "also"),
105
106		    strcmp("$(test.ary[8][0])", "last"),
107		    strcmp("$(test.ary[8][1])", "one"),
108      };
109
110  reports:
111    DEBUG::
112      "expected $(test.num) entries, saw $(test.cnt)";
113
114      "saw array indices '$(idx)'";
115
116      "expected test.ary[0][0] = '0', saw '$(test.ary[0][0])'";
117      "expected test.ary[0][1] = '1', saw '$(test.ary[0][1])'";
118      "expected test.ary[0][2] = '2', saw '$(test.ary[0][2])'";
119
120      "expected test.ary[1][0] = '1', saw '$(test.ary[1][0])'";
121      "expected test.ary[1][1] = '2', saw '$(test.ary[1][1])'";
122      "expected test.ary[1][2] = '3', saw '$(test.ary[1][2])'";
123
124      "expected test.ary[2][0] = 'here is', saw '$(test.ary[2][0])'";
125      "expected test.ary[2][1] = 'a line', saw '$(test.ary[2][1])'";
126      "expected test.ary[2][2] = ' with spaces ', saw '$(test.ary[2][2])'";
127      "expected test.ary[2][3] = ' in it', saw '$(test.ary[2][3])'";
128
129      "expected test.ary[3][0] = 'blank', saw '$(test.ary[3][0])'";
130      "expected test.ary[3][1] = 'fields', saw '$(test.ary[3][1])'";
131      "expected test.ary[3][2] = '', saw '$(test.ary[3][2])'";
132      "expected test.ary[3][3] = '', saw '$(test.ary[3][3])'";
133      "expected test.ary[3][4] = 'in here', saw '$(test.ary[3][4])'";
134      "expected test.ary[3][5] = '', saw '$(test.ary[3][5])'";
135      "expected test.ary[3][6] = '', saw '$(test.ary[3][6])'";
136
137      "expected test.ary[4][0] = '', saw '$(test.ary[4][0])'";
138      "expected test.ary[4][1] = 'leading blank field', saw '$(test.ary[4][1])'";
139
140      "expected test.ary[5][0] = 'this', saw '$(test.ary[5][0])'";
141      "expected test.ary[5][1] = 'is', saw '$(test.ary[5][1])'";
142      "expected test.ary[5][2] = 'a', saw '$(test.ary[5][2])'";
143      "expected test.ary[5][3] = 'test', saw '$(test.ary[5][3])'";
144
145      "expected test.ary[6][0] = '# A duplicate follows', saw '$(test.ary[6][0])'";
146      "expected test.ary[6][1] = ' this line is not always a comment', saw '$(test.ary[6][1])'";
147
148      "expected test.ary[7][0] = 'this', saw '$(test.ary[7][0])'";
149      "expected test.ary[7][1] = 'also', saw '$(test.ary[7][1])'";
150
151      "expected test.ary[8][0] = 'last', saw '$(test.ary[8][0])'";
152      "expected test.ary[8][1] = 'one', saw '$(test.ary[8][1])'";
153
154    ok::
155      "$(this.promise_filename) Pass";
156
157    !ok::
158      "$(this.promise_filename) FAIL";
159}
160