#######################################################
#
# Delete a number of lines via an slist, different way (different order than original)
# Region editing, include_start_delimiter and include_end_delimiter
# Second edit destroys the region
#
#######################################################
body common control
{
  inputs => { "../../default.sub.cf" };
  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
    One potato
    Two potato
    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
{
  files:
    "$(G.testfile).actual" edit_line => test_delete;
}

bundle edit_line test_delete
{
  vars:
    "str" slist => { "    Three potatoe", "BEGIN", "END" };

  delete_lines:
    # Second edit destroys the region
    "$(str)" select_region => test_select;
}

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

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

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