"use strict";

var _vitest = require("vitest");
var _try = _interopRequireDefault(require("../../lib/data/try.js"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
// Added .js extension

/*
  ======== A Handy Little Nodeunit Reference ========
  https://github.com/caolan/nodeunit

  Test methods:
    test.expect(numAssertions)
    test.done()
  Test assertions:
    test.ok(value, [message])
    test.equal(actual, expected, [message])
    test.notEqual(actual, expected, [message])
    test.deepEqual(actual, expected, [message])
    test.notDeepEqual(actual, expected, [message])
    test.strictEqual(actual, expected, [message])
    test.notStrictEqual(actual, expected, [message])
    test.throws(block, [error], [message])
    test.doesNotThrow(block, [error], [message])
    test.ifError(value)
*/

(0, _vitest.describe)('Try Data Type Tests', function () {
  // Original test: 'atry success'
  (0, _vitest.it)('atry success', function () {
    (0, _vitest.expect)(_try["default"].success(1).isSuccess()).toBe(true);
  });

  // Original test: 'atry failure'
  (0, _vitest.it)('atry failure', function () {
    (0, _vitest.expect)(_try["default"].failure(new Error('failure')).isFailure()).toBe(true);
  });

  // Original test: 'atry success map can be a success'
  (0, _vitest.it)('atry success map can be a success', function () {
    (0, _vitest.expect)(_try["default"].success(1).map(function (i) {
      return i + 1;
    }).isSuccess()).toBe(true);
  });

  // Original test: 'atry success map can be a failure'
  (0, _vitest.it)('atry success map can be a failure', function () {
    (0, _vitest.expect)(_try["default"].success(1).map(function () {
      throw new Error('test error');
    }).isFailure()).toBe(true);
  });

  // Original test: 'atry success map'
  (0, _vitest.it)('atry success map', function () {
    (0, _vitest.expect)(_try["default"].success(1).map(function (i) {
      return i + 1;
    }).success()).toBe(2);
  });

  // Original test: 'atry failure map is a failure'
  (0, _vitest.it)('atry failure map is a failure', function () {
    (0, _vitest.expect)(_try["default"].failure(new Error('failure')).map(function (i) {
      return i + 1;
    }) // This map function won't be executed
    .isFailure()).toBe(true);
  });

  // Original test: 'atry failure map'
  (0, _vitest.it)('atry failure map', function () {
    var failureValue = new Error('original failure');
    (0, _vitest.expect)(_try["default"].failure(failureValue).map(function (i) {
      return i + 1;
    }) // This map function won't be executed
    .failure()).toBe(failureValue);
  });

  // Original test: 'atry success flatMap of atry'
  (0, _vitest.it)('atry success flatMap of atry', function () {
    (0, _vitest.expect)(_try["default"].success(1).flatMap(function (i) {
      return _try["default"].success(i + 1);
    }).success()).toBe(2);
  });

  // Original test: 'atry failure flatMap of int' 
  (0, _vitest.it)('atry failure flatMap of atry (original name: atry failure flatMap of int)', function () {
    var failureValue = new Error('original failure');
    (0, _vitest.expect)(_try["default"].failure(failureValue).flatMap(function (i) {
      return _try["default"].success(i + 1);
    }) // This function won't be executed
    .failure()).toBe(failureValue);
  });

  // Original test: 'atry failure flatMap of Error'
  (0, _vitest.it)('atry success flatMap that throws (original name: atry failure flatMap of Error)', function () {
    var errorThrown = new Error('flatMap error');
    var result = _try["default"].success(1).flatMap(function () {
      throw errorThrown;
    });
    (0, _vitest.expect)(result.isFailure()).toBe(true);
    (0, _vitest.expect)(result.failure()).toBe(errorThrown);
  });

  // Original test: 'atry success recoverWith'
  (0, _vitest.it)('atry success recoverWith', function () {
    var result = _try["default"].success(1).recoverWith(2);
    (0, _vitest.expect)(result).toBe(1);
  });

  // Original test: 'atry failure recoverWith'
  (0, _vitest.it)('atry failure recoverWith', function () {
    (0, _vitest.expect)(_try["default"].failure(1).recoverWith(2)).toBe(2);
  });

  // Original test: 'atry success lazyRecoverWith'
  (0, _vitest.it)('atry success lazyRecoverWith', function () {
    var result = _try["default"].success(1).lazyRecoverWith(function () {
      return 2;
    });
    (0, _vitest.expect)(result).toBe(1);
  });

  // Original test: 'atry failure lazyRecoverWith'
  (0, _vitest.it)('atry failure lazyRecoverWith', function () {
    (0, _vitest.expect)(_try["default"].failure(new Error('failure')).lazyRecoverWith(function () {
      return 2;
    })).toBe(2);
  });

  // Original test: 'atry success filter'
  (0, _vitest.it)('atry success filter', function () {
    (0, _vitest.expect)(_try["default"].success(1).filter(function (v) {
      return v === 1;
    }).isSuccess()).toBe(true);
  });

  // Original test: 'atry success wrong filter'
  (0, _vitest.it)('atry success wrong filter', function () {
    (0, _vitest.expect)(_try["default"].success(1).filter(function (v) {
      return v === 2;
    }).isFailure()).toBe(true);
  });

  // Original test: 'atry failure filter'
  (0, _vitest.it)('atry failure filter', function () {
    var failureValue = new Error('original failure');
    var result = _try["default"].failure(failureValue).filter(function (v) {
      return v === 1;
    }); // Filter function won't be executed
    (0, _vitest.expect)(result.isFailure()).toBe(true);
    (0, _vitest.expect)(result.failure()).toBe(failureValue);
  });

  // Original test: 'atry success onSuccess'
  (0, _vitest.it)('atry success onSuccess', function () {
    var success = false;
    _try["default"].success(1).onSuccess(function () {
      success = true;
    });
    (0, _vitest.expect)(success).toBe(true);
  });

  // Original test: 'atry failure onSuccess'
  (0, _vitest.it)('atry failure onSuccess', function () {
    var success = false;
    _try["default"].failure(new Error('failure')).onSuccess(function () {
      success = true;
    });
    (0, _vitest.expect)(success).toBe(false);
  });

  // Original test: 'atry success onFailure'
  (0, _vitest.it)('atry success onFailure', function () {
    var failure = false;
    _try["default"].success(1).onFailure(function () {
      failure = true;
    });
    (0, _vitest.expect)(failure).toBe(false);
  });

  // Original test: 'atry failure onFailure'
  (0, _vitest.it)('atry failure onFailure', function () {
    var failureCallbackCalled = false;
    _try["default"].failure(new Error('failure')).onFailure(function () {
      failureCallbackCalled = true;
    });
    (0, _vitest.expect)(failureCallbackCalled).toBe(true);
  });
});
//# sourceMappingURL=try.spec.js.map