// Generated by purs version 0.12.5
"use strict";
var $foreign = require("./foreign.js");
var Control_Applicative = require("../Control.Applicative/index.js");
var Control_Bind = require("../Control.Bind/index.js");
var Data_Either = require("../Data.Either/index.js");
var Data_Foldable = require("../Data.Foldable/index.js");
var Data_Functor = require("../Data.Functor/index.js");
var Data_List = require("../Data.List/index.js");
var Data_List_Types = require("../Data.List.Types/index.js");
var Data_Maybe = require("../Data.Maybe/index.js");
var Data_Semigroup = require("../Data.Semigroup/index.js");
var Data_Show = require("../Data.Show/index.js");
var Data_String_Common = require("../Data.String.Common/index.js");
var Data_Tuple = require("../Data.Tuple/index.js");
var Data_Unfoldable = require("../Data.Unfoldable/index.js");
var Data_Unit = require("../Data.Unit/index.js");
var Effect_Aff = require("../Effect.Aff/index.js");
var Effect_Exception = require("../Effect.Exception/index.js");
var Test_Unit = require("../Test.Unit/index.js");
var Test_Unit_Console = require("../Test.Unit.Console/index.js");
var printStack = function (err) {
    var v = Effect_Exception.stack(err);
    if (v instanceof Data_Maybe.Nothing) {
        return Control_Applicative.pure(Effect_Aff.applicativeAff)(Data_Unit.unit);
    };
    if (v instanceof Data_Maybe.Just) {
        return Control_Bind.discard(Control_Bind.discardUnit)(Effect_Aff.bindAff)(Test_Unit_Console.log(Effect_Aff.monadEffectAff)("  stack: |-"))(function () {
            return Test_Unit_Console.log(Effect_Aff.monadEffectAff)(Data_String_Common.joinWith("\x0a")(Data_Functor.map(Data_Functor.functorArray)(Data_Semigroup.append(Data_Semigroup.semigroupString)("    "))(Data_String_Common.split("\x0a")(v.value0))));
        });
    };
    throw new Error("Failed pattern match at Test.Unit.Output.TAP (line 22, column 18 - line 26, column 67): " + [ v.constructor.name ]);
};
var runTest = function (suite) {
    var run = function (v) {
        return function (v1) {
            return Data_Tuple.Tuple.create(v.value0 + 1 | 0)(Data_List.snoc(v.value1)((function () {
                var label = Data_String_Common.joinWith(" / ")(Data_List.toUnfoldable(Data_Unfoldable.unfoldableArray)(v1.value0));
                return Control_Bind.bind(Effect_Aff.bindAff)(Effect_Aff.attempt(v1.value1))(function (v2) {
                    if (v2 instanceof Data_Either.Left) {
                        return Control_Bind.discard(Control_Bind.discardUnit)(Effect_Aff.bindAff)(Test_Unit_Console.log(Effect_Aff.monadEffectAff)("not ok " + (Data_Show.show(Data_Show.showInt)(v.value0) + (" " + label))))(function () {
                            return Control_Bind.discard(Control_Bind.discardUnit)(Effect_Aff.bindAff)(Test_Unit_Console.log(Effect_Aff.monadEffectAff)("  ---"))(function () {
                                return Control_Bind.discard(Control_Bind.discardUnit)(Effect_Aff.bindAff)(Test_Unit_Console.log(Effect_Aff.monadEffectAff)("  message: " + Effect_Exception.message(v2.value0)))(function () {
                                    return Control_Bind.discard(Control_Bind.discardUnit)(Effect_Aff.bindAff)(printStack(v2.value0))(function () {
                                        return Test_Unit_Console.log(Effect_Aff.monadEffectAff)("  ...");
                                    });
                                });
                            });
                        });
                    };
                    if (v2 instanceof Data_Either.Right) {
                        return Test_Unit_Console.log(Effect_Aff.monadEffectAff)("ok " + (Data_Show.show(Data_Show.showInt)(v.value0) + (" " + label)));
                    };
                    throw new Error("Failed pattern match at Test.Unit.Output.TAP (line 39, column 7 - line 46, column 58): " + [ v2.constructor.name ]);
                });
            })()));
        };
    };
    return Control_Bind.bind(Effect_Aff.bindAff)(Test_Unit.collectTests(suite))(function (v) {
        return Control_Bind.discard(Control_Bind.discardUnit)(Effect_Aff.bindAff)(Test_Unit_Console.log(Effect_Aff.monadEffectAff)("1.." + Data_Show.show(Data_Show.showInt)(Data_List.length(v))))(function () {
            var acts = Data_Foldable.foldl(Data_List_Types.foldableList)(run)(new Data_Tuple.Tuple(1, Data_List_Types.Nil.value))(v);
            return Control_Bind.discard(Control_Bind.discardUnit)(Effect_Aff.bindAff)(Data_Foldable.sequence_(Effect_Aff.applicativeAff)(Data_List_Types.foldableList)(Data_Tuple.snd(acts)))(function () {
                return Control_Applicative.pure(Effect_Aff.applicativeAff)(v);
            });
        });
    });
};
module.exports = {
    runTest: runTest,
    requested: $foreign.requested
};
