1# data_regextract() test 2 3body common control 4{ 5 inputs => { "../../default.cf.sub" }; 6 bundlesequence => { default("$(this.promise_filename)") }; 7} 8 9bundle agent test 10{ 11 vars: 12 "patterns" data => parsejson('["^(?<name1>...)(...)(..)-(?<name2>...)-(..).*", "", ".*", "(?<myword>...)"]'); 13 "plength" int => length(patterns); 14 "pi" slist => expandrange("[0-$(plength)]", 1); # this is one more than the valid indices 15 16 "strings" data => parsejson('[ "abcdef12-345-67andsoon", "", "!!!", "one two three"]'); 17 "slength" int => length(strings); 18 "si" slist => expandrange("[0-$(slength)]", 1); # this is one more than the valid indices 19 20 "parsed_$(pi)_$(si)" data => data_regextract(nth(patterns, $(pi)), 21 nth(strings, $(si))); 22 "parsed_$(pi)_$(si)_str" string => format("%S", "parsed_$(pi)_$(si)"); 23 24 reports: 25 EXTRA:: 26 "$(this.bundle): $(pi) $(si) '$(patterns[$(pi)])' matching '$(strings[$(si)])' => $(parsed_$(pi)_$(si)_str)"; 27} 28 29bundle agent check 30{ 31 vars: 32 "actual" string => " 330 0 $(test.parsed_0_0_str) 34 351 0 $(test.parsed_1_0_str) 361 1 $(test.parsed_1_1_str) 371 2 $(test.parsed_1_2_str) 381 3 $(test.parsed_1_3_str) 39 402 0 $(test.parsed_2_0_str) 412 1 $(test.parsed_2_1_str) 422 2 $(test.parsed_2_2_str) 432 3 $(test.parsed_2_3_str) 44 453 0 $(test.parsed_3_0_str) 463 2 $(test.parsed_3_2_str) 473 3 $(test.parsed_3_3_str) 48"; 49 50 "expected" string => ' 510 0 {"0":"abcdef12-345-67andsoon","2":"def","3":"12","5":"67","name1":"abc","name2":"345"} 52 531 0 {"0":""} 541 1 {"0":""} 551 2 {"0":""} 561 3 {"0":""} 57 582 0 {"0":"abcdef12-345-67andsoon"} 592 1 {"0":""} 602 2 {"0":"!!!"} 612 3 {"0":"one two three"} 62 633 0 {"0":"abc","myword":"abc"} 643 2 {"0":"!!!","myword":"!!!"} 653 3 {"0":"one","myword":"one"} 66'; 67 68 methods: 69 "" usebundle => dcs_check_strcmp($(actual), $(expected), 70 $(this.promise_filename), 71 "no"); 72 73} 74