toJSONHierarchy

string
toJSONHierarchy
(
T
)
(
const(T)[][string] items
)

Examples

convert an assoc array to JSON hierarchy

  struct Mock {
    string val;

    string toString() inout {
      return `"` ~ val ~ `"`;
    }
  }

  const(Mock)[][string] mocks;

  mocks["a.b"] = [ Mock("val1"), Mock("val2") ];
  mocks["a.c"] = [ Mock("val3") ];

  auto result = mocks.toJSONHierarchy;

  result.should.contain(`
    "b": [
      "val1",
      "val2"
    ]`);
  result.should.contain(`"c": [
      "val3"
    ]`);
  result.should.startWith(`{
  "a": {`);
  result.should.endWith(`
    ]
  }
}`);

it should have an empty key for items that contain both values and childs

  struct Mock {
    string val;

    string toString() inout {
      return `"` ~ val ~ `"`;
    }
  }

  const(Mock)[][string] mocks;

  mocks["a.b"] = [ Mock("val1"), Mock("val2") ];
  mocks["a.b.c"] = [ Mock("val3") ];

  mocks.toJSONHierarchy.should.equal(`{
  "a": {
    "b": {
      "c": [
        "val3"
      ],
      "": [
      "val1",
      "val2"
      ]
    }
  }
}`);

describeTests should return the tests cases serialised in json format

void TestMock() @system { }

TestCase[] tests;
tests ~= TestCase("a.b", "some test", &TestMock, [ Label("some label", "label value") ]);
tests ~= TestCase("a.c", "other test", &TestMock);

auto result = describeTests(tests);

result.values.length.should.equal(2);
result.keys.should.containOnly([ "a.b", "a.c" ]);
result["a.b"].length.should.equal(1);
result["a.c"].length.should.equal(1);

Meta