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

bundle agent main
{
  methods:
    "test";
    "check";
}

bundle agent test
{
  meta:
    "description" -> { "CFE-2551" }
      string => "Test that variables defined in other bundles with the same name are not included in a merged result";

    "test_soft_fail"
      string => "any",
      meta => { "CFE-2551" };

  vars:
    "a" string => "string a";
    "b" string => "string b";
    "vars1[a]" string => "$(a)";
    "vars1[b]" string => "$(b)";

  methods:
    "run_low_test_merged" usebundle => test_merged_low;
}

bundle agent test_merged_low
{
  vars:
    "c" string => "string c";
    "vars1[c]" string => "$(c)";

    # We expect that only the values from the classic array vars1 in this
    # bundle will be merged together. And thus, we should only end up with ={ "vars1" : { "c": "string c" } }=
    "merged_data_vars" data => mergedata('{ "vars1": vars1 }');
    "merged_data_vars_str" string => format("%S", merged_data_vars);

  reports:
    DEBUG|EXTRA::
      "$(this.bundle) : merged_data_vars_str : $(merged_data_vars_str)";
}

bundle agent check
{
  vars:
    "expected" string => '{"vars1":{"c":"string c"}}';

  classes:
    "pass"
      expression => strcmp(
        $(expected), $(test_merged_low.merged_data_vars_str)
      );

  reports:
    pass::
      "$(this.promise_filename) Pass";

    !pass::
      "$(this.promise_filename) FAIL";
      "expected: '$(expected)'";
      "got: '$(test_merged_low.merged_data_vars_str)'";
}
