"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const assert = require("assert");
const STRING_1 = require("../../constant/STRING");
const parser_1 = require("../../spec/parser");
const type_1 = require("../../spec/type");
const _ids_1 = require("../../system/_ids");
const _specs_1 = require("../../system/_specs");
assert.equal((0, type_1.mostSpecific)('<A>', '<B>'), '<A>');
assert.equal((0, type_1.mostSpecific)('<B>', '<A>'), '<A>');
assert.equal((0, type_1.mostSpecific)('<A>', '<B>[]'), '<B>[]');
assert.equal((0, type_1.mostSpecific)('<A>', 'number'), 'number');
assert.equal((0, type_1.mostSpecific)('<A>[]', 'number[]'), 'number[]');
assert.equal((0, type_1.mostSpecific)('number', 'any'), 'number');
assert.equal((0, type_1.mostSpecific)('<A>', 'any'), '<A>');
assert.equal((0, type_1.mostSpecific)('`U`', '`EE`'), '`U`');
assert.deepEqual((0, type_1.getGraphTypeMapById)(_ids_1.ID_SINGLE, _specs_1.default), {
    append: { input: { a: '<A>[]', b: '<A>' }, output: { a: '<A>[]' } },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_SINGLE, _specs_1.default), {
    input: { a: '<A>' },
    output: { '[a]': '<A>[]' },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_TAG, _specs_1.default), {
    input: { k: 'string', v: 'any' },
    output: { kv: 'object' },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_WAIT_ALL_2, _specs_1.default), {
    input: { a: '<A>', b: '<B>' },
    output: { a: '<A>', b: '<B>' },
});
assert.deepEqual((0, type_1.getGraphTypeMapById)(_ids_1.ID_MERGE_AB, _specs_1.default), {
    deepmerge: {
        input: { a: 'object', b: 'object' },
        output: { ab: 'object' },
    },
    tag0: { input: { k: 'string', v: 'any' }, output: { kv: 'object' } },
    tag1: { input: { k: 'string', v: 'any' }, output: { kv: 'object' } },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_MERGE_AB, _specs_1.default), {
    input: { a: 'any', b: 'any' },
    output: { ab: 'object' },
});
assert.deepEqual((0, type_1.getGraphTypeMapById)(_ids_1.ID_CONSTANT_ONE, _specs_1.default), {
    identity: { input: { a: 'number' }, output: { a: 'number' } },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_CONSTANT_ONE, _specs_1.default), {
    input: {},
    output: { 1: 'number' },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_INCREMENT, _specs_1.default), {
    input: { a: 'number' },
    output: { 'a + 1': 'number' },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_LAST_INDEX, _specs_1.default), {
    input: { a: '<A>[]' },
    output: { last: 'number' },
});
const cache = {};
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_LOOP_INCREMENT, _specs_1.default, cache), {
    input: { init: 'number', test: 'boolean' },
    output: { local: 'number', current: 'number', final: 'number' },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_CONCAT_3_0, _specs_1.default), {
    input: { a: 'string', b: 'string', c: 'string' },
    output: { abc: 'string' },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_CONCAT_3, _specs_1.default), {
    input: { a: '<A>[]', b: '<A>[]', c: '<A>[]' },
    output: { abc: '<A>[]' },
});
assert.deepEqual((0, type_1.getGraphTypeMapById)(_ids_1.ID_SWAP, _specs_1.default), {
    set0: {
        input: { a: '<A>[]', v: '<A>', i: 'number' },
        output: { a: '<A>[]' },
    },
    set1: {
        input: { a: '<D>[]', v: '<D>', i: 'number' },
        output: { a: '<A>[]' },
    },
    at0: { input: { a: '<B>[]', i: 'number' }, output: { 'a[i]': '<A>' } },
    at1: { input: { a: '<C>[]', i: 'number' }, output: { 'a[i]': '<A>' } },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_SWAP, _specs_1.default), {
    input: { a: '<A>[]', i: 'number', j: 'number' },
    output: { a: '<A>[]' },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_RANDOM_NATURAL_LTE, _specs_1.default), {
    input: { max: 'number' },
    output: { i: 'number' },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_RANDOM_BIT, _specs_1.default), {
    input: { any: 'any' },
    output: { bit: 'number' },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_ARRAY_BUILDER_FROM, _specs_1.default), {
    input: { init: '<A>[]', a: '<A>', test: 'boolean' },
    output: {
        acc: '<A>[]',
        'a[]': '<A>[]',
        local: '<A>[]',
    },
});
assert.deepEqual((0, type_1._getSpecTypeInterfaceById)(_ids_1.ID_ARRAY_BUILDER_FROM, _specs_1.default), {
    input: {
        a: {
            value: '<A>',
            type: 'generic',
            children: [],
        },
        test: {
            value: 'boolean',
            type: 'boolean',
            children: [],
        },
        init: {
            value: '<A>[]',
            type: 'array expression',
            children: [
                {
                    value: '<A>',
                    type: 'generic',
                    children: [],
                },
            ],
        },
    },
    output: {
        acc: {
            value: '<A>[]',
            type: 'array expression',
            children: [
                {
                    value: '<A>',
                    type: 'generic',
                    children: [],
                },
            ],
        },
        'a[]': {
            value: '<A>[]',
            type: 'array expression',
            children: [
                {
                    value: '<A>',
                    type: 'generic',
                    children: [],
                },
            ],
        },
        local: {
            value: '<A>[]',
            type: 'array expression',
            children: [
                {
                    value: '<A>',
                    type: 'generic',
                    children: [],
                },
            ],
        },
    },
});
assert.deepEqual((0, type_1._getGraphTypeMapById)(_ids_1.ID_N_ARRAY_BUILDER_FROM, _specs_1.default), {
    lengthlessthan: {
        input: {
            a: {
                value: '<A>[]',
                type: 'array expression',
                children: [{ value: '<A>', type: 'generic', children: [] }],
            },
            b: { value: 'number', type: 'number', children: [] },
        },
        output: { test: { value: 'boolean', type: 'boolean', children: [] } },
    },
    arraybuilderfrom: {
        input: {
            a: { value: '<B>', type: 'generic', children: [] },
            test: { value: 'boolean', type: 'boolean', children: [] },
            init: {
                value: '<B>[]',
                type: 'array expression',
                children: [{ value: '<B>', type: 'generic', children: [] }],
            },
        },
        output: {
            acc: {
                value: '<A>[]',
                type: 'array expression',
                children: [{ value: '<A>', type: 'generic', children: [] }],
            },
            'a[]': {
                value: '<A>[]',
                type: 'array expression',
                children: [{ value: '<A>', type: 'generic', children: [] }],
            },
            local: {
                value: '<A>[]',
                type: 'array expression',
                children: [{ value: '<A>', type: 'generic', children: [] }],
            },
        },
    },
    looprepeat: {
        input: {
            init: { value: '<C>', type: 'generic', children: [] },
            test: { value: 'boolean', type: 'boolean', children: [] },
        },
        output: {
            local: { value: 'number', type: 'number', children: [] },
            current: { value: 'number', type: 'number', children: [] },
            final: { value: 'number', type: 'number', children: [] },
        },
    },
});
assert.deepEqual((0, type_1._getGraphTypeMapById)(_ids_1.ID_N_ARRAY_BUILDER, _specs_1.default), {
    buildarrayfrom: {
        input: {
            a: { value: '<A>', type: parser_1.TreeNodeType.Generic, children: [] },
            from: {
                value: '<A>[]',
                type: parser_1.TreeNodeType.ArrayExpression,
                children: [{ value: '<A>', type: parser_1.TreeNodeType.Generic, children: [] }],
            },
            n: { value: 'number', type: parser_1.TreeNodeType.Number, children: [] },
        },
        output: {
            'a[]': {
                value: '<A>[]',
                type: parser_1.TreeNodeType.ArrayExpression,
                children: [{ value: '<A>', type: parser_1.TreeNodeType.Generic, children: [] }],
            },
            test: { value: 'boolean', type: parser_1.TreeNodeType.Boolean, children: [] },
            acc: {
                value: '<A>[]',
                type: parser_1.TreeNodeType.ArrayExpression,
                children: [{ value: '<A>', type: parser_1.TreeNodeType.Generic, children: [] }],
            },
        },
    },
});
assert.deepEqual((0, type_1.getGraphTypeMapById)(_ids_1.ID_N_ARRAY_BUILDER, _specs_1.default), {
    buildarrayfrom: {
        input: { n: 'number', from: '<A>[]', a: '<A>' },
        output: { 'a[]': '<A>[]', test: 'boolean', acc: '<A>[]' },
    },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_N_ARRAY_BUILDER_FROM, _specs_1.default), {
    input: { n: 'number', from: '<A>[]', a: '<A>' },
    output: { 'a[]': '<A>[]', test: 'boolean', acc: '<A>[]' },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_RANDOM_BIT_ARRAY, _specs_1.default), {
    input: { n: 'number' },
    output: { a: 'number[]' },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_RANDOM_BIT_MATRIX, _specs_1.default), {
    input: { n: 'number' },
    output: { a: 'number[][]' },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_RANGE_ARRAY, _specs_1.default), {
    input: { n: 'number' },
    output: { a: 'number[]' },
});
assert.deepEqual((0, type_1.getGraphTypeMap)({
    name: STRING_1.UNTITLED,
    units: {
        state: { id: 'c899b675-c3c4-428e-b548-b228305c0302' },
    },
    merges: {},
    inputs: {},
    outputs: {},
    metadata: { icon: null, description: '' },
}, _specs_1.default), {
    state: {
        input: { init: '<A>', done: 'any' },
        output: { data: '<A>&`V`' },
    },
});
assert.deepEqual((0, type_1.getGraphTypeMap)({
    name: STRING_1.UNTITLED,
    units: {
        id: { id: '260d774e-bc89-4027-aa92-cb1985fb312b' },
        id0: { id: '260d774e-bc89-4027-aa92-cb1985fb312b' },
        id1: { id: '260d774e-bc89-4027-aa92-cb1985fb312b' },
    },
    merges: {
        0: {
            id: { output: { a: true } },
            id0: { input: { a: true } },
        },
    },
    inputs: {},
    outputs: {},
    metadata: { icon: null, description: '' },
}, _specs_1.default), {
    id: { input: { a: '<A>' }, output: { a: '<A>' } },
    id0: { input: { a: '<B>' }, output: { a: '<A>' } },
    id1: { input: { a: '<A>' }, output: { a: '<A>' } },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_PICK_LESSER, _specs_1.default), {
    input: { a: 'number', b: 'number' },
    output: {
        'a < b': 'boolean',
        lesser: 'number',
    },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_HEAD_OR_DEFAULT, _specs_1.default), {
    input: { a: '<A>[]', default: '<A>' },
    output: {
        a: '<A>[]',
        head: '<A>',
        empty: 'boolean',
    },
});
//# sourceMappingURL=type.js.map