1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
#######################################################
#
# Test readstringarray(), don't read comment, duplicate key or last line
#
# The 4xx tests are all related, and 400-419 are the readstringarray tests,
# 420-439 the same for readstringarrayidx, 440-459 parsestringarray, and
# 460-479 parsestringarrayidx
#
#######################################################
body common control
{
inputs => { "../../default.cf.sub" };
bundlesequence => { default("$(this.promise_filename)") };
version => "1.0";
}
bundle agent init
{
files:
"$(G.testfile)"
delete => init_delete;
"$(G.testfile)"
create => "true",
edit_line => init_fill_in;
}
bundle edit_line init_fill_in
{
insert_lines:
"0:1:2
1:2:3
here is:a line: with spaces : in it
blank:fields:::in here::
:leading blank field
this:is:a:test
# A duplicate follows: this line is not always a comment
this:also
last:one";
}
body delete init_delete
{
dirlinks => "delete";
rmdirs => "true";
}
#######################################################
bundle agent test
{
vars:
"cnt" int => readstringarray("ary", "$(G.testfile)","NoComment",":",6,1000);
"num" int => "6";
}
#######################################################
bundle agent check
{
vars:
"idx" slist => getindices("test.ary");
classes:
"ok" and => {
strcmp("$(test.num)", "$(test.cnt)"),
strcmp("$(test.ary[0][0])", "0"),
strcmp("$(test.ary[0][1])", "1"),
strcmp("$(test.ary[0][2])", "2"),
strcmp("$(test.ary[1][0])", "1"),
strcmp("$(test.ary[1][1])", "2"),
strcmp("$(test.ary[1][2])", "3"),
strcmp("$(test.ary[here is][0])", "here is"),
strcmp("$(test.ary[here is][1])", "a line"),
strcmp("$(test.ary[here is][2])", " with spaces "),
strcmp("$(test.ary[here is][3])", " in it"),
strcmp("$(test.ary[blank][0])", "blank"),
strcmp("$(test.ary[blank][1])", "fields"),
strcmp("$(test.ary[blank][2])", ""),
strcmp("$(test.ary[blank][3])", ""),
strcmp("$(test.ary[blank][4])", "in here"),
strcmp("$(test.ary[blank][5])", ""),
strcmp("$(test.ary[blank][6])", ""),
strcmp("$(test.ary[][0])", ""),
strcmp("$(test.ary[][1])", "leading blank field"),
strcmp("$(test.ary[this][0])", "this"),
strcmp("$(test.ary[this][1])", "is"),
strcmp("$(test.ary[this][2])", "a"),
strcmp("$(test.ary[this][3])", "test"),
};
reports:
DEBUG::
"expected $(test.num) entries, saw $(test.cnt)";
"saw array indices '$(idx)'";
"expected test.ary[0][0] = '0', saw '$(test.ary[0][0])'";
"expected test.ary[0][1] = '1', saw '$(test.ary[0][1])'";
"expected test.ary[0][2] = '2', saw '$(test.ary[0][2])'";
"expected test.ary[1][0] = '1', saw '$(test.ary[1][0])'";
"expected test.ary[1][1] = '2', saw '$(test.ary[1][1])'";
"expected test.ary[1][2] = '3', saw '$(test.ary[1][2])'";
"expected test.ary[here is][0] = 'here is', saw '$(test.ary[here is][0])'";
"expected test.ary[here is][1] = 'a line', saw '$(test.ary[here is][1])'";
"expected test.ary[here is][2] = ' with spaces ', saw '$(test.ary[here is][2])'";
"expected test.ary[here is][3] = ' in it', saw '$(test.ary[here is][3])'";
"expected test.ary[blank][0] = 'blank', saw '$(test.ary[blank][0])'";
"expected test.ary[blank][1] = 'fields', saw '$(test.ary[blank][1])'";
"expected test.ary[blank][2] = '', saw '$(test.ary[blank][2])'";
"expected test.ary[blank][3] = '', saw '$(test.ary[blank][3])'";
"expected test.ary[blank][4] = 'in here', saw '$(test.ary[blank][4])'";
"expected test.ary[blank][5] = '', saw '$(test.ary[blank][5])'";
"expected test.ary[blank][6] = '', saw '$(test.ary[blank][6])'";
"expected test.ary[][0] = '', saw '$(test.ary[][0])'";
"expected test.ary[][1] = 'leading blank field', saw '$(test.ary[][1])'";
"expected test.ary[this][0] = 'this', saw '$(test.ary[this][0])'";
"expected test.ary[this][1] = 'is', saw '$(test.ary[this][1])'";
"expected test.ary[this][2] = 'a', saw '$(test.ary[this][2])'";
"expected test.ary[this][3] = 'test', saw '$(test.ary[this][3])'";
"expected test.ary[# A duplicate follows][0] = '# A duplicate follows', saw '$(test.ary[# A duplicate follows][0])'";
"expected test.ary[# A duplicate follows][1] = 'this line is not always a comment', saw '$(test.ary[# A duplicate follows][1])'";
ok::
"$(this.promise_filename) Pass";
!ok::
"$(this.promise_filename) FAIL";
}
|