"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.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: 'number|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: 'number|string', v: 'any' }, output: { kv: 'object' } },
    tag1: { input: { k: 'number|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' },
});
// TODO
// assert.deepEqual(getSpecTypeInterfaceByPath(MERGE_AB, _specs), {
//   input: { a: '<A>', b: '<B>' },
//   output: { ab: '<A>&<B>' },
// })
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' },
});
// console.log(cache)
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: '<A>[]', v: '<A>', i: 'number' },
        output: { a: '<A>[]' },
    },
    at0: { input: { a: '<A>[]', i: 'number' }, output: { 'a[i]': '<A>' } },
    at1: { input: { a: '<A>[]', 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.getGraphTypeMapById)(_ids_1.ID_SHUFFLE_TO_REC, _specs_1.default), {
    greaterthan: {
        input: { a: 'number', b: 'number' },
        output: { 'a > b': 'boolean' },
    },
    randomnaturallte: {
        input: { max: 'number' },
        output: { i: 'number' },
    },
    if: {
        input: { a: 'number', b: 'boolean' },
        output: { 'a if b': 'number' },
    },
    swap: {
        input: { a: '<A>[]', i: 'number', j: 'number' },
        output: { a: '<A>[]' },
    },
    decrement: {
        input: { a: 'number' },
        output: { 'a - 1': 'number' },
    },
    shuffletorec: {
        input: { a: '<A>[]', to: 'number' },
        output: { a: '<A>[]' },
    },
    ifelse: {
        input: {
            a: '<A>[]',
            b: 'boolean',
        },
        output: {
            if: '<A>[]',
            else: '<A>[]',
        },
    },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_SHUFFLE_TO_REC, _specs_1.default), {
    input: { a: '<A>[]', to: 'number' },
    output: { a: '<A>[]' },
});
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: 2,
            children: [],
        },
        test: {
            value: 'boolean',
            type: 12,
            children: [],
        },
        init: {
            value: '<A>[]',
            type: 5,
            children: [
                {
                    value: '<A>',
                    type: 2,
                    children: [],
                },
            ],
        },
    },
    output: {
        acc: {
            value: '<A>[]',
            type: 5,
            children: [
                {
                    value: '<A>',
                    type: 2,
                    children: [],
                },
            ],
        },
        'a[]': {
            value: '<A>[]',
            type: 5,
            children: [
                {
                    value: '<A>',
                    type: 2,
                    children: [],
                },
            ],
        },
        local: {
            value: '<A>[]',
            type: 5,
            children: [
                {
                    value: '<A>',
                    type: 2,
                    children: [],
                },
            ],
        },
    },
});
assert.deepEqual((0, type_1._getGraphTypeMapById)(_ids_1.ID_N_ARRAY_BUILDER_FROM, _specs_1.default), {
    lengthlessthan: {
        input: {
            a: {
                value: '<A>[]',
                type: 5,
                children: [{ value: '<A>', type: 2, children: [] }],
            },
            b: { value: 'number', type: 11, children: [] },
        },
        output: { test: { value: 'boolean', type: 12, children: [] } },
    },
    arraybuilderfrom: {
        input: {
            a: { value: '<A>', type: 2, children: [] },
            test: { value: 'boolean', type: 12, children: [] },
            init: {
                value: '<A>[]',
                type: 5,
                children: [{ value: '<A>', type: 2, children: [] }],
            },
        },
        output: {
            acc: {
                value: '<A>[]',
                type: 5,
                children: [{ value: '<A>', type: 2, children: [] }],
            },
            'a[]': {
                value: '<A>[]',
                type: 5,
                children: [{ value: '<A>', type: 2, children: [] }],
            },
            local: {
                value: '<A>[]',
                type: 5,
                children: [{ value: '<A>', type: 2, children: [] }],
            },
        },
    },
    looprepeat: {
        input: {
            init: { value: 'number', type: 11, children: [] },
            test: { value: 'boolean', type: 12, children: [] },
        },
        output: {
            local: { value: 'number', type: 11, children: [] },
            current: { value: 'number', type: 11, children: [] },
            final: { value: 'number', type: 11, children: [] },
        },
    },
});
assert.deepEqual((0, type_1._getGraphTypeMapById)(_ids_1.ID_N_ARRAY_BUILDER, _specs_1.default), {
    buildarrayfrom: {
        input: {
            n: { value: 'number', type: parser_1.TreeNodeType.Number, children: [] },
            from: {
                value: '<A>[]',
                type: parser_1.TreeNodeType.ArrayExpression,
                children: [{ value: '<A>', type: parser_1.TreeNodeType.Generic, children: [] }],
            },
            a: { value: '<A>', type: parser_1.TreeNodeType.Generic, children: [] },
        },
        output: {
            'a[]': {
                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>[]' },
    },
});
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>[]' },
});
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: '`V<A>`' },
    },
});
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: '<A>' },
        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',
    },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_PRIORITY_HEAD, _specs_1.default), {
    input: { a: 'number[]', b: 'number[]' },
    output: {
        head: 'number',
        a: 'number[]',
        b: 'number[]',
    },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_PRIORITY_MERGE_FROM, _specs_1.default), {
    input: { a: 'number[]', b: 'number[]', from: 'number[]' },
    output: {
        ab: 'number[]',
    },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_PRIORITY_MERGE, _specs_1.default), {
    input: { a: 'number[]', b: 'number[]' },
    output: {
        ab: 'number[]',
    },
});
assert.deepEqual((0, type_1.getSpecTypeInterfaceById)(_ids_1.ID_MERGE_SORT, _specs_1.default), {
    input: { a: 'number[]' },
    output: {
        a: 'number[]',
    },
});
// TODO
// assert.deepEqual(getGraphTypeMapByPath(PROP_PATH, _specs), {
//   if: {
//     input: {
//       a: 'string[]',
//       b: 'boolean',
//     },
//     output: {
//       'a if b': 'string[]',
//     },
//   },
//   ifelse: {
//     input: {
//       a: 'object',
//       b: 'boolean',
//     },
//     output: {
//       if: 'object',
//       else: 'object',
//     },
//   },
//   lengthgt: {
//     input: {
//       a: 'string[]',
//       b: 'number',
//     },
//     output: {
//       true: 'boolean',
//     },
//   },
//   head: {
//     input: {
//       a: 'string[]',
//     },
//     output: {
//       a: 'string[]',
//       head: 'string',
//     },
//   },
//   prop: {
//     input: {
//       obj: 'object',
//       key: 'string',
//     },
//     output: {
//       value: 'any',
//     },
//   },
//   proppath: {
//     input: {
//       path: 'string[]',
//       obj: 'object',
//     },
//     output: {
//       result: 'any',
//     },
//   },
// })
// TODO
// assert.deepEqual(getSpecTypeInterfaceByPath(PROP_PATH, _specs), {
//   input: { obj: 'object', path: '(number|string)[]' },
//   output: { result: 'any' },
// })
// TODO
// assert.deepEqual(getSpecTypeInterfaceByPath(LOOP_2, _specs), {
//   input: {
//     inita: '<A>',
//     initb: '<B>',
//     "next a": '<A>',
//     "next b": '<B>',
//     test: 'boolean',
//   },
//   output: { locala: '<A>', localb: '<B>', currenta: '<A>', currentb: '<B>' },
// })
//# sourceMappingURL=type.js.map