"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _response = _interopRequireDefault(require("../../lib/parsec/response"));
var _index = _interopRequireDefault(require("../../lib/stream/index"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/*
  ======== 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)
*/
var _default = exports["default"] = {
  setUp: function setUp(done) {
    done();
  },
  'response accepted': function response_accepted(test) {
    test.expect(1);
    // tests here
    test.ok(_response["default"].accept().isAccepted(), 'should be accepted.');
    test.done();
  },
  'response as a success': function response_as_a_success(test) {
    test.expect(1);
    // tests here
    test.ok(_response["default"].accept().toTry().isSuccess(), 'should be success.');
    test.done();
  },
  'response accepted map to accepted': function response_accepted_map_to_accepted(test) {
    test.expect(1);
    // tests here
    test.ok(_response["default"].accept().map(function (a) {
      return a;
    }).isAccepted(), 'should be accepted.');
    test.done();
  },
  'response accepted map to return the value': function response_accepted_map_to_return_the_value(test) {
    test.expect(1);
    // tests here
    test.equal(_response["default"].accept('a').map(function (a) {
      return a;
    }).value, 'a', 'should be accepted.');
    test.done();
  },
  'response accepted map to pass in response as second argument': function response_accepted_map_to_pass_in_response_as_second_argument(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_response["default"].accept('a').map(function (_, response) {
      return response;
    }).value, _response["default"].accept('a'), 'should return the response.');
    test.done();
  },
  'response accepted flatMap to accepted': function response_accepted_flatMap_to_accepted(test) {
    test.expect(1);
    // tests here
    test.ok(_response["default"].accept('a').flatMap(function (a) {
      return _response["default"].accept(a);
    }).isAccepted(), 'should be accepted.');
    test.done();
  },
  'response accepted flatMap knows the offset': function response_accepted_flatMap_knows_the_offset(test) {
    test.expect(1);
    // tests here
    var responseOffset = _response["default"].accept('a', 'abc', 1, false).flatMap(function (a, response) {
      return response.offset;
    });
    test.ok(responseOffset === 1, 'found the offset');
    test.done();
  },
  'response accepted flatMap to return the value': function response_accepted_flatMap_to_return_the_value(test) {
    test.expect(1);
    // tests here
    test.ok(_response["default"].accept('a').flatMap(function (a) {
      return _response["default"].accept(a);
    }).isAccepted(), 'a', 'should be accepted.');
    test.done();
  },
  'response accepted flatMap to reject': function response_accepted_flatMap_to_reject(test) {
    test.expect(1);
    // tests here
    test.equal(_response["default"].accept().flatMap(function () {
      return _response["default"].reject();
    }).isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'response rejected map to rejected': function response_rejected_map_to_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_response["default"].reject().map(function (t) {
      return t;
    }).isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'response rejected map callback not called': function response_rejected_map_callback_not_called(test) {
    test.expect(1);
    // tests here
    var calls = 0;
    _response["default"].reject().map(function () {
      calls++;
    });
    test.equal(calls, 0, 'should not have called the callback.');
    test.done();
  },
  'response rejected flatMap to rejected': function response_rejected_flatMap_to_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_response["default"].reject().flatMap(function () {
      return _response["default"].accept();
    }).isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'response rejected flatMap callback not called': function response_rejected_flatMap_callback_not_called(test) {
    test.expect(1);
    // tests here
    var calls = 0;
    _response["default"].reject().flatMap(function () {
      calls++;
    });
    test.equal(calls, 0, 'should not have called the callback.');
    test.done();
  },
  'response accepted fold': function response_accepted_fold(test) {
    test.expect(1);
    // tests here
    test.equal(_response["default"].accept('a').fold(function (a) {
      return a.value;
    }), 'a', 'should retrieve the value.');
    test.done();
  },
  'fold takes a function to map the value depending on result': function fold_takes_a_function_to_map_the_value_depending_on_result(test) {
    var value = _response["default"].accept('a').fold(function (accept) {
      return accept.value + '-potato';
    },
    // Accept has value, input, offset, consumed
    function (reject) {
      return reject.offset + '-tomato';
    }); // Reject has offset, consumed

    // we accept, so it should be a-potato
    test.equal(value, 'a-potato');
    value = _response["default"].reject().fold(function (accept) {
      return accept.value + '-potato';
    }, function (reject) {
      return reject.offset + '-tomato';
    });

    // we reject, so it should use the second function
    // Offset is undefined because it's up to the parser to know which offset it's parsing
    test.equal(value, 'undefined-tomato');
    test.done();
  },
  'response filter accepted': function response_filter_accepted(test) {
    test.expect(1);
    // tests here
    test.ok(_response["default"].accept('a').filter(function (a) {
      return a === 'a';
    }).isAccepted(), 'should filter the response.');
    test.done();
  },
  'response not filter accepted ': function response_not_filter_accepted_(test) {
    test.expect(1);
    // tests here
    test.equal(_response["default"].accept('a').filter(function (a) {
      return a !== 'a';
    }).isAccepted(), false, 'should not filter the response.');
    test.done();
  },
  'accept can be consumed': function accept_can_be_consumed(test) {
    test.expect(1);
    // tests here
    var myStream = _index["default"].ofString('abc');
    var acceptance = _response["default"].accept('c', myStream, 3, false);
    var consumed = acceptance.isEos();
    test.equal(consumed, true, 'should be consumed');
    test.done();
  },
  'accept should not be yet consumed': function accept_should_not_be_yet_consumed(test) {
    test.expect(1);
    // tests here
    var myStream = _index["default"].ofString('abc');
    test.equal(_response["default"].accept('b', myStream, 2, false).isEos(), false, 'should be consumed');
    test.done();
  },
  'response rejected': function response_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_response["default"].reject().isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'response rejected should not be consumed': function response_rejected_should_not_be_consumed(test) {
    test.expect(1);
    // tests here
    test.equal(_response["default"].reject().isEos(), false, 'should be not consumed.');
    test.done();
  },
  'response as a failure': function response_as_a_failure(test) {
    test.expect(1);
    // tests here
    test.equal(_response["default"].reject().toTry().isSuccess(), false, 'should be failure.');
    test.done();
  },
  'response rejected fold': function response_rejected_fold(test) {
    test.expect(1);
    // tests here
    test.equal(_response["default"].reject().fold(function (a) {
      return a.value;
    }, function () {
      return 'b';
    }), 'b', 'should generate the value.');
    test.done();
  },
  'response filter rejected': function response_filter_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_response["default"].reject().filter(function () {
      return true;
    }).isAccepted(), false, 'should not filter the response.');
    test.done();
  },
  'response not filter rejected': function response_not_filter_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_response["default"].reject().filter(function () {
      return false;
    }).isAccepted(), false, 'should not filter the response.');
    test.done();
  }
};
//# sourceMappingURL=response_test.js.map