"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const assert_1 = __importDefault(require("assert"));
const Graph_1 = require("../../Class/Graph");
const debug_1 = require("../../debug");
const _ids_1 = require("../../system/_ids");
const Throw_1 = __importDefault(require("../../system/f/control/Throw"));
const system_1 = require("../util/system");
const spec = system_1.system.newSpec({});
const composition0 = new Graph_1.Graph(spec, {}, system_1.system);
const throwId0 = 'throw0';
const throwId1 = 'throw1';
false && (0, debug_1.watchUnitAndLog)(composition0);
false && (0, debug_1.watchGraphAndLog)(composition0);
composition0.addUnitSpec(throwId0, {
    unit: { id: _ids_1.ID_THROW, input: {}, output: {} },
});
composition0.play();
const throw0 = composition0.getUnit(throwId0);
assert_1.default.equal(composition0.getErr(), null);
throw0.push('message', 'kaboom!');
assert_1.default.equal(composition0.getErr(), 'kaboom!');
assert_1.default.equal(composition0.takeErr(), 'kaboom!');
// err should go away after reset
composition0.reset();
assert_1.default.equal(composition0.getErr(), null);
composition0.exposeInputSet({ name: 'message', plug: { 0: { unitId: throwId0, pinId: 'message' } } }, 'message');
// test err backpressure
composition0.push('message', 'xablèau');
assert_1.default.equal(composition0.peakInput('message'), 'xablèau');
assert_1.default.equal(composition0.takeErr(), 'xablèau');
composition0.push('message', 'kpop');
assert_1.default.equal(composition0.peakInput('message'), 'kpop');
assert_1.default.equal(composition0.takeErr(), 'kpop');
assert_1.default.equal(composition0.takeErr(), null);
const spec1 = system_1.system.newSpec({});
const composition1 = new Graph_1.Graph(spec1, {}, system_1.system);
composition1.play();
false && (0, debug_1.watchUnitAndLog)(composition1);
false && (0, debug_1.watchGraphAndLog)(composition1);
composition1.addUnitSpec(throwId0, {
    unit: {
        id: _ids_1.ID_THROW,
        input: { message: { data: '"honolulu"' } },
        output: {},
    },
});
assert_1.default.equal(composition1.takeErr(), 'honolulu');
composition1.removeUnit(throwId0);
assert_1.default.equal(composition1.takeErr(), null);
const spec2 = system_1.system.newSpec({});
const composition2 = new Graph_1.Graph(spec2, {}, system_1.system);
composition2.play();
false && (0, debug_1.watchUnitAndLog)(composition2);
false && (0, debug_1.watchGraphAndLog)(composition2);
composition2.addUnitSpec(throwId0, {
    unit: { id: _ids_1.ID_THROW, input: { message: { data: '"bang!"' } }, output: {} },
});
composition2.addUnitSpec(throwId1, {
    unit: {
        id: _ids_1.ID_THROW,
        input: { message: { data: '"baboom"' } },
        output: {},
    },
});
assert_1.default.equal(composition2.getErr(), 'bang!');
composition2.removeUnit(throwId0);
assert_1.default.equal(composition2.getErr(), 'baboom');
composition2.removeUnit(throwId1);
assert_1.default.equal(composition2.getErr(), null);
const spec3 = system_1.system.newSpec({});
const composition3 = new Graph_1.Graph(spec3, {}, system_1.system);
composition3.play();
false && (0, debug_1.watchUnitAndLog)(composition3);
false && (0, debug_1.watchGraphAndLog)(composition3);
composition3.addUnitSpec(throwId0, {
    unit: {
        id: _ids_1.ID_THROW,
        input: { message: { data: '"badumtz"' } },
        output: {},
    },
});
assert_1.default.equal(composition3.getErr(), 'badumtz');
const spec4 = system_1.system.newSpec({});
const composition4 = new Graph_1.Graph(spec4, {}, system_1.system);
composition4.play();
const throwUnit = new Throw_1.default(system_1.system);
throwUnit.pushInput('message', 'mameleco');
composition4.addUnit('throw', throwUnit);
assert_1.default.equal(composition4.getErr(), 'mameleco');
//# sourceMappingURL=throw.js.map