#######################################################
#
# Insert lines with preserve_block "after" and check convergence
#
#######################################################

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 => "START";

      "expected" string =>
"START
         1
        x2x
       xx3xx
        x4x
         5
        x6x
       xx7xx
      xxx8xxx
     xxxx9xxxx
    xxxxx10xxxx
   xxxxxx11xxxxx
  xxxxxxx12xxxxxx
 xxxxxxxx13xxxxxxx
xxxxxxxxx14xxxxxxxx
xxxxxxxxx15xxxxxxxxx
      xxx16xx
      xxx17xx
      xxx18xx
      xxx19xx
      xxx20xx
xxxxxxxxx21xxxxxxx";

  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_insert("$(init.insert)");
}

bundle edit_line test_insert(lines)
{
insert_lines:

"         1
        x2x
       xx3xx
        x4x
         5
        x6x
       xx7xx
      xxx8xxx
     xxxx9xxxx
    xxxxx10xxxx
   xxxxxx11xxxxx
  xxxxxxx12xxxxxx
 xxxxxxxx13xxxxxxx
xxxxxxxxx14xxxxxxxx
xxxxxxxxx15xxxxxxxxx
      xxx16xx
      xxx17xx
      xxx18xx
      xxx19xx
      xxx20xx
xxxxxxxxx21xxxxxxx"

      location => prepend,
   insert_type => "preserve_block";
}

body location prepend
{
before_after => "after";
}

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

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


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