#######################################################
#
# Insert a number of lines after the first instance of a line
#
#######################################################

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 =>
      "BEGIN
    One potato
    Two potato
    Two potatoes
    Four
END";

      "expected" string =>
      "BEGIN
    One potato
    Three potatoe
    Two potato
    Two potatoes
    Four
END";

  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 =>
      "    One potato
    Two potato
    Three potatoe
    Four";

  files:
      "$(G.testfile).actual"
      create => "true",
      edit_line => test_insert("$(test.tstr)");

}

bundle edit_line test_insert(str)
{
  insert_lines:
      "$(str)"
      location => test_after_first(".*potato.*");
}

body location test_after_first(line)
{
      before_after => "after";
      first_last => "first";
      select_line_matching => "$(line)";
}

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

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

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