1####################################################### 2# 3# Test readstringarrayidx(), add some weird indices, real comments, no empty fields 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)","^#.*",":+",10,14); 57 "num" int => "3"; 58} 59 60####################################################### 61 62bundle agent check 63{ 64 vars: 65 "idx" slist => getindices("test.ary"); 66 67 classes: 68 "bad" or => { 69 isvariable("test.ary[2][1]"), 70 isvariable("test.ary[3][0]"), 71 }; 72 73 "ok" and => { 74 "!bad", 75 76 strcmp("$(test.num)", "$(test.cnt)"), 77 78 strcmp("$(test.ary[0][0])", "0"), 79 strcmp("$(test.ary[0][1])", "1"), 80 strcmp("$(test.ary[0][2])", "2"), 81 82 strcmp("$(test.ary[1][0])", "1"), 83 strcmp("$(test.ary[1][1])", "2"), 84 strcmp("$(test.ary[1][2])", "3"), 85 86 strcmp("$(test.ary[2][0])", "he"), 87 }; 88 89 reports: 90 DEBUG:: 91 "expected $(test.num) entries, saw $(test.cnt)"; 92 93 "saw array indices '$(idx)'"; 94 95 "saw 'bad'-class things"; 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[1][0] = '1', saw '$(test.ary[1][0])'"; 102 "expected test.ary[1][1] = '2', saw '$(test.ary[1][1])'"; 103 "expected test.ary[1][2] = '3', saw '$(test.ary[1][2])'"; 104 105 "expected test.ary[2][0] = 'he', saw '$(test.ary[2][0])'"; 106 107 ok:: 108 "$(this.promise_filename) Pass"; 109 110 !ok:: 111 "$(this.promise_filename) FAIL"; 112} 113