<!doctype html>
<html>
<head>
    <script src="../../resources/testharness.js"></script>
    <script src="../../resources/testharnessreport.js"></script>
</head>
<body>
<script type="application/javascript">
test(() => {
    assert_true(!!window.internals);
    const maplike = internals.createInternalsMapLike();
    maplike.delete("init");
    maplike.set("init", 0);

    assert_array_equals(maplike.inspectKeys(), ["init"], "init keys");
    assert_array_equals(maplike.inspectValues(), [0], "init values");
    assert_true(maplike.has("init"));

    maplike.set("testA", 1);
    assert_array_equals(maplike.inspectKeys(), ["init", "testA"]);
    assert_array_equals(maplike.inspectValues(), [0, 1]);
    maplike.set("testA", 2);
    assert_array_equals(maplike.inspectKeys(), ["init", "testA"]);
    assert_array_equals(maplike.inspectValues(), [0, 2]);
    maplike.set("testB", 3);
    assert_array_equals(maplike.inspectKeys(), ["init", "testA", "testB"]);
    assert_array_equals(maplike.inspectValues(), [0, 2, 3]);

    maplike.delete("init");
    assert_array_equals(maplike.inspectKeys(), ["testA", "testB"]);
    assert_array_equals(maplike.inspectValues(), [2, 3]);

    assert_equals(maplike.size, 2, "size");

    let entriesTest = "";
    for (let entry of maplike.entries()) {
        entriesTest += entry;
        entriesTest += ' ';
    }
    assert_equals(entriesTest, "testA,2 testB,3 ", "entries test");

    let valuesTest = "";
    for (let entry of maplike.values()) {
        valuesTest += entry;
    }
    assert_equals(valuesTest, "23", "values test");

    let keysTest = "";
    for (let entry of maplike.keys()) {
        keysTest += entry;
    }
    assert_equals(keysTest, "testAtestB", "keys test");

    assert_equals(maplike.forEach.length, 1);
    let forEachTest = "";
    const forEachResult = maplike.forEach((value, key, object) => {
        forEachTest += key;
        forEachTest += ',';
        forEachTest += value;
        forEachTest += ' ';
        assert_equals(object, maplike);
    });
    assert_equals(forEachTest, "testA,2 testB,3 ", "forEach test");
    assert_equals(forEachResult, undefined);

    maplike.clear();
    assert_array_equals(maplike.inspectKeys(), []);
    assert_array_equals(maplike.inspectValues(), []);
}, "Basic add/remove/clear functionality");
</script>
</body>
</html>
