"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _index = _interopRequireDefault(require("../../lib/stream/index"));
var _index2 = require("../../lib/parsec/index");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var _default = exports["default"] = {
  setUp: function setUp(done) {
    done();
  },
  'expect F.layer(parser) to work as parser with backtrak on success': function expect_FLayerParser_to_work_as_parser_with_backtrak_on_success(test) {
    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));
    test.ok(response.isAccepted());
    test.equal(response.offset, 0);

    // Fail test
    response = layer.parse(_index["default"].ofString(failInput));
    test.ok(!response.isAccepted());
    test.equal(response.offset, 0);
    test.done();
  },
  'expect F.layer(parser).and(other) to succeed': function expect_FLayerParserAndOther_to_succeed(test) {
    try {
      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));
      test.ok(response.isAccepted());
      test.deepEqual(response.value, [2, 'aa', 'aa']);
      test.equal(response.offset, 2);
    } catch (e) {
      console.log(e);
    }
    test.done();
  },
  'expect F.layer(first).and(second).and(third) to be associative': function expect_FLayerFirstAndSecondAndThird_to_be_associative(test) {
    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));
    test.ok(response.isAccepted());
    test.deepEqual(response.value, [2, 'a-a', 'aa']);
    test.equal(response.offset, 2);
    test.done();
  },
  'expect F.layer(parser).and(other) to fail with second': function expect_FLayerParserAndOther_to_fail_with_second(test) {
    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));
    test.ok(!response.isAccepted());
    test.equal(response.offset, 0);
    test.equal(response.value, undefined);
    test.done();
  },
  'expect F.layer(parser).and(other) to fail with first': function expect_FLayerParserAndOther_to_fail_with_first(test) {
    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'; // first fail by not meeting Eos
    var layer = _index2.F.layer(first).and(second);
    var response = layer.parse(_index["default"].ofString(successInput));
    test.ok(!response.isAccepted());
    test.equal(response.offset, 2); // stop at first because could not find the Eos
    test.equal(response.value, undefined);
    test.done();
  },
  'expect F.layer(parser).and(other) to not move on the second after first fails': function expect_FLayerParserAndOther_to_not_move_on_the_second_after_first_fails(test) {
    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'; // first fail by not meeting Eos

    var layer = _index2.F.layer(first).and(second);
    var response = layer.parse(_index["default"].ofString(successInput));
    test.ok(!response.isAccepted());
    test.equal(response.offset, 2);
    test.equal(false, found); // second was not even tried
    test.done();
  }
};
//# sourceMappingURL=f-layer-test.js.map