<!DOCTYPE HTML>
<html>
<head>
<title>IdlInterface.prototype.get_reverse_inheritance_stack()</title>
</head>
<body>
<div id="log"></div>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/WebIDLParser.js"></script>
<script src="/resources/idlharness.js"></script>
<script src="../../../idl-helper.js"></script>
<script>
    "use strict";
    test(function() {
        var stack = interfaceFrom('interface A { };').get_reverse_inheritance_stack();
        assert_array_equals(stack.map(i => i.name), ["A"]);
    }, 'should return an array that includes itself.');

    test(function() {
        var i = interfaceFrom('interface A : B { };');
        assert_throws_js(Error, _ => i.get_reverse_inheritance_stack());
    }, "should throw for interfaces which inherit from another interface which wasn't added to the IdlArray");

    test(function() {
        var idl = new IdlArray();
        idl.add_idls('interface A : B { };');
        idl.add_untested_idls('interface B : C { }; interface C { };');
        var A = idl.members["A"];
        assert_array_equals(A.get_reverse_inheritance_stack().map(i => i.name), ["C", "B", "A"]);
    }, 'should return an array of interfaces in order of inheritance, starting with the base interface');

    test(function () {
        var idl = new IdlArray();
        idl.add_untested_idls('interface A : B { };');
        idl.add_untested_idls('interface B : A { };');
        idl.assert_throws('A has a circular dependency: A,B,A', i => i.test());
    }, 'should throw when inheritance is circular');

    test(function () {
        var idl = new IdlArray();
        idl.add_untested_idls('interface A : B { };');
        idl.assert_throws(
            'Duplicate identifier A',
            i => i.add_untested_idls('interface A : C { };'));
    }, 'should throw when multiple inheritances defined');
</script>
</body>
</html>
