body common control
{
  bundlesequence => { "check" };
}

bundle agent test(context, index)
{
  meta:
    "description" -> { "ENT-6193", "CFE-3421" }
      string => "Test for expected results from policy function classfilterdata() with array of arrays using context '$(with)' and index $(index)",
      with => join("', '", "context");

  vars:
    "test"
      data => '[
        [ "foo", "!foo", "foo&bar", "foo|bar" ],
        [ "bar", "!bar", "bar&baz", "bar|baz" ],
        [ "baz", "!baz", "foo&baz", "foo|baz" ],
      ]';

    "actual"
      data => classfilterdata("@(test)", "array_of_arrays", "$(index)");

  classes:
    "$(context)";

  reports:
    "$(with)"
      with => storejson("@(actual)"),
      bundle_return_value_index => "$(index)";
}

bundle agent check
{
  vars:
    "num_indices" string => "3";
    "context" slist => { "foo" };
    "range" slist => expandrange("[0-$(num_indices)]", "1");

    "expected[0]"
      string => storejson('[
        [ "foo", "!foo", "foo&bar", "foo|bar" ],
      ]');
    "expected[1]"
      string => storejson('[
        [ "bar", "!bar", "bar&baz", "bar|baz" ],
        [ "baz", "!baz", "foo&baz", "foo|baz" ],
      ]');
    "expected[2]"
      string => storejson('[
      ]');
    "expected[3]"
      string => storejson('[
        [ "foo", "!foo", "foo&bar", "foo|bar" ],
        [ "baz", "!baz", "foo&baz", "foo|baz" ],
      ]');

  classes:
    "ok_$(range)"
      expression => strcmp("$(expected[$(range)])",
                           "$(actual[$(range)])");
    "ok"
      expression => and(expandrange("ok_[0-$(num_indices)]", "1"));

  methods:
    "context: '$(with)' and index: $(range)"
      usebundle => test("@(context)", "$(range)"),
      useresult => "actual",
      with => join(", ", "context");

  reports:
      "Context '$(with)'; index $(range); expected '$(expected[$(range)])'; actual '$(actual[$(range)])'"
        with => join("', '", "context");
    ok::
      "$(this.promise_filename) Pass";
    !ok::
      "$(this.promise_filename) FAIL";
}
