"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _index = _interopRequireDefault(require("../../lib/stream/index"));
var _parsec = require("../../lib/parsec");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
;
var _default = exports["default"] = {
  setUp: function setUp(done) {
    done();
  },
  'response ok with a StringStream': function response_ok_with_a_StringStream(test) {
    var stream = _index["default"].ofString('The world is a vampire');
    var parser = _parsec.C.string('The');
    var response = parser.parse(stream, 0);
    test.ok(response.isAccepted());
    test.ok(!response.isEos());
    test.equal(response.offset, 3);
    test.done();
  },
  'response ok inside a StringStream': function response_ok_inside_a_StringStream(test) {
    var stream = _index["default"].ofString('The world is a vampire');
    var parser = _parsec.C.string('world');
    var response = parser.parse(stream, 4);
    test.ok(response.isAccepted());
    test.ok(!response.isEos());
    test.equal(response.offset, 9);
    test.done();
  },
  'response ok completing a StringStream': function response_ok_completing_a_StringStream(test) {
    var stream = _index["default"].ofString('The world is a vampire');
    var parser = _parsec.C.letter().or(_parsec.C["char"](' ')).rep();
    var response = parser.parse(stream);
    test.ok(response.isAccepted());
    test.ok(response.isEos());
    test.equal(response.offset, 22);
    test.done();
  },
  'response fails at StringStream start': function response_fails_at_StringStream_start(test) {
    var stream = _index["default"].ofString('The world is a vampire');
    var parser = _parsec.C.string('That');
    var response = parser.parse(stream);
    test.ok(!response.isAccepted());
    test.equal(response.offset, 0);
    test.done();
  },
  'response fails inside a StringStream': function response_fails_inside_a_StringStream(test) {
    var stream = _index["default"].ofString('abc de');
    var parser = _parsec.C.string('abc').then(_parsec.C.string('fails'));
    var response = parser.parse(stream);
    test.ok(!response.isAccepted());
    test.equal(response.offset, 3);
    test.done();
  },
  'response passes the StringStream': function response_passes_the_StringStream(test) {
    var stream = _index["default"].ofString('abc de');
    var parser = _parsec.C.letter().or(_parsec.C["char"](' ')).rep().then(_parsec.C.string('!!!'));
    var response = parser.parse(stream);
    test.ok(!response.isAccepted());

    // because an error has NEVER stream consumed
    test.ok(!response.isEos());
    test.equal(response.offset, stream.source.length);
    test.done();
  },
  'response with a failed try is rejected, and offset is 0': function response_with_a_failed_try_is_rejected_and_offset_is_0(test) {
    var stream = _index["default"].ofString('abc de');
    var parser = _parsec.F["try"](_parsec.C.string('abc').then(_parsec.C["char"]('x'))).or(_parsec.C.string('x'));
    var response = parser.parse(stream);
    test.ok(!response.isAccepted());
    test.equal(response.offset, 0);
    test.done();
  }
};
//# sourceMappingURL=offset-test.js.map