"use strict";

var _vitest = require("vitest");
var _index = _interopRequireDefault(require("../../lib/stream/index"));
var _parsec = require("../../lib/parsec");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
(0, _vitest.describe)('Stream Offset Tests', function () {
  (0, _vitest.it)('response ok with a StringStream', function () {
    var stream = _index["default"].ofString('The world is a vampire');
    var parser = _parsec.C.string('The');
    var response = parser.parse(stream, 0);
    (0, _vitest.expect)(response.isAccepted()).toBe(true);
    (0, _vitest.expect)(response.isEos()).toBe(false);
    (0, _vitest.expect)(response.offset).toBe(3);
  });
  (0, _vitest.it)('response ok inside a StringStream', function () {
    var stream = _index["default"].ofString('The world is a vampire');
    var parser = _parsec.C.string('world');
    var response = parser.parse(stream, 4);
    (0, _vitest.expect)(response.isAccepted()).toBe(true);
    (0, _vitest.expect)(response.isEos()).toBe(false);
    (0, _vitest.expect)(response.offset).toBe(9);
  });
  (0, _vitest.it)('response ok completing a StringStream', function () {
    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);
    (0, _vitest.expect)(response.isAccepted()).toBe(true);
    (0, _vitest.expect)(response.isEos()).toBe(true);
    (0, _vitest.expect)(response.offset).toBe(22);
  });
  (0, _vitest.it)('response fails at StringStream start', function () {
    var stream = _index["default"].ofString('The world is a vampire');
    var parser = _parsec.C.string('That');
    var response = parser.parse(stream);
    (0, _vitest.expect)(response.isAccepted()).toBe(false);
    (0, _vitest.expect)(response.offset).toBe(0);
  });
  (0, _vitest.it)('response fails inside a StringStream', function () {
    var stream = _index["default"].ofString('abc de');
    var parser = _parsec.C.string('abc').then(_parsec.C.string('fails'));
    var response = parser.parse(stream);
    (0, _vitest.expect)(response.isAccepted()).toBe(false);
    (0, _vitest.expect)(response.offset).toBe(3);
  });
  (0, _vitest.it)('response passes the StringStream', function () {
    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);
    (0, _vitest.expect)(response.isAccepted()).toBe(false);

    // because an error has NEVER stream consumed
    (0, _vitest.expect)(response.isEos()).toBe(false);
    (0, _vitest.expect)(response.offset).toBe(stream.source.length);
  });
  (0, _vitest.it)('response with a failed try is rejected, and offset is 0', function () {
    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);
    (0, _vitest.expect)(response.isAccepted()).toBe(false);
    (0, _vitest.expect)(response.offset).toBe(0);
  });
});
//# sourceMappingURL=offset-test.spec.js.map