#######################################################
#
# Delete a line, set a class
# Double (nested) header/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
BEGIN
header
BEGIN
    One potato
    Two potato
    Three potatoe
    Four
END
trailer
END
trailer";

      "expected" string =>
      "header
BEGIN
header
BEGIN
    One potato
    Two potato
    Four
END
trailer
END
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" string => "    Three potatoe";

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

}

bundle edit_line test_delete(str)
{
  delete_lines:
      "$(str)"
      classes => test_class("ok"),
      select_region => test_select;
}

body select_region test_select
{
      select_start => "header";
      select_end => "trailer";
}


body classes test_class(a)
{
      promise_repaired => { "$(a)" };
}


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

bundle agent check
{
  reports:
    ok::
      "$(this.promise_filename) Pass";
    !ok::
      "$(this.promise_filename) FAIL";
}

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