#######################################################
#
# Delete a line using a list, all of which match
# select_region, doesn't include header or trailer
#
#######################################################

body common control
{
      inputs => { "../../default.cf.sub" };
      bundlesequence  => { default("$(this.promise_filename)") };
      version => "1.0";
}

#######################################################

bundle agent init
{
  vars:
      "states" slist => { "actual", "expected" };

      "actual" string =>
      "header
header
BEGIN
    One potato
    Two potato
    Three potatoe
    Four
END
trailer
trailer";

      "expected" string =>
      "header
header
BEGIN
    Four
END
trailer
trailer";

  files:
      "$(G.testfile).$(states)"
      create => "true",
      edit_line => init_insert("$(init.$(states))"),
      edit_defaults => init_empty;
}

bundle edit_line init_insert(str)
{
  insert_lines:
      "$(str)";
}

body edit_defaults init_empty
{
      empty_file_before_editing => "true";
}

#######################################################

bundle agent test
{
  vars:
      "tstr" slist => { "T", "O" };

  files:
      "$(G.testfile).actual"
      edit_line => test_delete(".*potat.*", "@(test.tstr)");

}

bundle edit_line test_delete(str, match)
{
  delete_lines:
      "$(str)"
      delete_select => test_match(@{match}),
      select_region => test_select;
}

body select_region test_select
{
      select_start => "BEGIN";
      select_end => "END";
}


body delete_select test_match(m)
{
      delete_if_contains_from_list => { @{m} };
}

#######################################################

bundle agent check
{
  methods:
      "any" usebundle => dcs_check_diff("$(G.testfile).actual",
                                            "$(G.testfile).expected",
                                            "$(this.promise_filename)");
}

### PROJECT_ID: core
### CATEGORY_ID: 27
