"use strict";

var _vitest = require("vitest");
var _index = _interopRequireDefault(require("../../lib/stream/index"));
var _index2 = require("../../lib/parsec/index");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
(0, _vitest.describe)('F Layer Tests', function () {
  (0, _vitest.it)('expect F.layer(parser) to work as parser with backtrak on success', function () {
    var parser = _index2.C["char"]('a').thenEos();
    var successInput = 'a';
    var failInput = 'b';
    var layer = _index2.F.layer(parser);
    var response = layer.parse(_index["default"].ofString(successInput));
    (0, _vitest.expect)(response.isAccepted()).toBe(true);
    (0, _vitest.expect)(response.offset).toBe(0);
    response = layer.parse(_index["default"].ofString(failInput));
    (0, _vitest.expect)(response.isAccepted()).toBe(false);
    (0, _vitest.expect)(response.offset).toBe(0);
  });
  (0, _vitest.it)('expect F.layer(parser).and(other) to succeed', function () {
    var first = _index2.C["char"]('a').then(_index2.C["char"]('a')).thenEos().array().map(function (r) {
      return r.length;
    });
    var second = _index2.C.string('aa').thenEos();
    var successInput = 'aa';
    var layer = _index2.F.layer(first).and(second).and(second).array();
    var response = layer.parse(_index["default"].ofString(successInput));
    (0, _vitest.expect)(response.isAccepted()).toBe(true);
    (0, _vitest.expect)(response.value).toEqual([2, 'aa', 'aa']);
    (0, _vitest.expect)(response.offset).toBe(2);
  });
  (0, _vitest.it)('expect F.layer(first).and(second).and(third) to be associative', function () {
    var first = _index2.C["char"]('a').then(_index2.C["char"]('a')).thenEos().array().map(function (r) {
      return r.length;
    });
    var second = _index2.C["char"]('a').then(_index2.C["char"]('a')).thenEos().array().map(function (r) {
      return r.join('-');
    });
    var third = _index2.C.string('aa').thenEos();
    var input = 'aa';
    var layer = _index2.F.layer(first).and(second).and(third).array();
    var response = layer.parse(_index["default"].ofString(input));
    (0, _vitest.expect)(response.isAccepted()).toBe(true);
    (0, _vitest.expect)(response.value).toEqual([2, 'a-a', 'aa']);
    (0, _vitest.expect)(response.offset).toBe(2);
  });
  (0, _vitest.it)('expect F.layer(parser).and(other) to fail with second', function () {
    var first = _index2.C["char"]('a').then(_index2.C["char"]('a')).array().thenEos().map(function (r) {
      return r.length;
    });
    var second = _index2.C.string('aaFAIL').thenEos();
    var successInput = 'aa';
    var layer = _index2.F.layer(first).and(second).array();
    var response = layer.parse(_index["default"].ofString(successInput));
    (0, _vitest.expect)(response.isAccepted()).toBe(false);
    (0, _vitest.expect)(response.offset).toBe(0);
    (0, _vitest.expect)(response.value).toBeUndefined();
  });
  (0, _vitest.it)('expect F.layer(parser).and(other) to fail with first', function () {
    var first = _index2.C["char"]('a').then(_index2.C["char"]('a')).thenEos().map(function (r) {
      return r.length;
    });
    var second = _index2.C.string('aaSUCCESS').thenEos();
    var successInput = 'aaSUCCESS';
    var layer = _index2.F.layer(first).and(second);
    var response = layer.parse(_index["default"].ofString(successInput));
    (0, _vitest.expect)(response.isAccepted()).toBe(false);
    (0, _vitest.expect)(response.offset).toBe(2);
    (0, _vitest.expect)(response.value).toBeUndefined();
  });
  (0, _vitest.it)('expect F.layer(parser).and(other) to not move on the second after first fails', function () {
    var first = _index2.C["char"]('a').then(_index2.C["char"]('a')).thenEos().map(function (r) {
      return r.length;
    });
    var found = false;
    var second = _index2.C.string('aaSUCCESS').thenEos().map(function (x) {
      found = true;
      return x;
    });
    var successInput = 'aaSUCCESS';
    var layer = _index2.F.layer(first).and(second);
    var response = layer.parse(_index["default"].ofString(successInput));
    (0, _vitest.expect)(response.isAccepted()).toBe(false);
    (0, _vitest.expect)(response.offset).toBe(2);
    (0, _vitest.expect)(found).toBe(false);
  });
});
//# sourceMappingURL=f-layer-test.spec.js.map