"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)('Parser Extensions Tests', function () {
  (0, _vitest.it)('expect (returns) to be accepted', function () {
    (0, _vitest.expect)(_index2.F.returns().parse(_index["default"].ofString(''), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect (returns) to return a given value', function () {
    (0, _vitest.expect)(_index2.F.returns(123).parse(_index["default"].ofString(''), 0).value).toBe(123);
  });
  (0, _vitest.it)('expect (returns) to be rejected', function () {
    (0, _vitest.expect)(_index2.F.error().parse(_index["default"].ofString(''), 0).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect (lazy) to be accepted', function () {
    (0, _vitest.expect)(_index2.F.lazy(function () {
      return _index2.F.returns();
    }).parse(_index["default"].ofString(''), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect (lazy) to return a given value', function () {
    (0, _vitest.expect)(_index2.F.lazy(function () {
      return _index2.F.returns(123);
    }).parse(_index["default"].ofString(''), 0).value).toBe(123);
  });
  (0, _vitest.it)('expect (lazy with empty params) to return a given value', function () {
    (0, _vitest.expect)(_index2.F.lazy(function () {
      return _index2.F.returns(123);
    }, []).parse(_index["default"].ofString(''), 0).value).toBe(123);
  });
  (0, _vitest.it)('expect (lazy) to be rejected', function () {
    (0, _vitest.expect)(_index2.F.lazy(function () {
      return _index2.F.error();
    }).parse(_index["default"].ofString(''), 0).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect (lazy) with a parameter to return a given value', function () {
    (0, _vitest.expect)(_index2.F.lazy(function (v) {
      return _index2.F.returns(v);
    }, [123]).parse(_index["default"].ofString(''), 0).value).toBe(123);
  });
  (0, _vitest.it)('expect (lazy) with multiple parameters to return a given value', function () {
    (0, _vitest.expect)(_index2.F.lazy(function (v1, v2) {
      return _index2.F.returns(v1 + v2);
    }, [10, 20]).parse(_index["default"].ofString(''), 0).value).toBe(30);
  });
  (0, _vitest.it)('expect (lazy) with unpacked parameters to fail', function () {
    var found = false;
    try {
      var combinator = _index2.F.lazy(function (v1, v2) {
        return _index2.F.returns(v1 + v2);
      }, 10, 20);
      combinator.parse(_index["default"].ofString(''), 0);
    } catch (e) {
      if (e.includes('packed into an array')) {
        found = true;
      }
    }
    (0, _vitest.expect)(found).toBe(true);
  });
  (0, _vitest.it)('expect (error) to be rejected', function () {
    (0, _vitest.expect)(_index2.F.error().parse(_index["default"].ofString(''), 0).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect (eos) to be accepted', function () {
    (0, _vitest.expect)(_index2.F.eos().parse(_index["default"].ofString(''), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect (eos) to be rejected', function () {
    (0, _vitest.expect)(_index2.F.eos().parse(_index["default"].ofString('a'), 0).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect (satisfy) to be accepted', function () {
    (0, _vitest.expect)(_index2.F.satisfy(function (v) {
      return v === 'a';
    }).parse(_index["default"].ofString('a'), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect (satisfy) to be return the right value', function () {
    (0, _vitest.expect)(_index2.F.satisfy(function (v) {
      return v === 'a';
    }).parse(_index["default"].ofString('a'), 0).value).toBe('a');
  });
  (0, _vitest.it)('expect (satisfy) to be return the right offset', function () {
    (0, _vitest.expect)(_index2.F.satisfy(function (v) {
      return v === 'a';
    }).parse(_index["default"].ofString('a'), 0).offset).toBe(1);
  });
  (0, _vitest.it)('expect (satisfy) to be rejected', function () {
    (0, _vitest.expect)(_index2.F.satisfy(function (v) {
      return v === 'b';
    }).parse(_index["default"].ofString('a'), 0).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect (doTry satisfy) to be accepted', function () {
    (0, _vitest.expect)(_index2.F["try"](_index2.F.satisfy(function (v) {
      return v === 'a';
    })).parse(_index["default"].ofString('a'), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect (doTry satisfy) to be rejected', function () {
    (0, _vitest.expect)(_index2.F["try"](_index2.F.satisfy(function (v) {
      return v === 'b';
    })).parse(_index["default"].ofString('a'), 0).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect (digit) to be accepted', function () {
    (0, _vitest.expect)(_index2.N.digit().parse(_index["default"].ofString('1'), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect (digit) to be rejected', function () {
    (0, _vitest.expect)(_index2.N.digit().parse(_index["default"].ofString('a'), 0).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect (number) to be accepted', function () {
    (0, _vitest.expect)(_index2.N.number().parse(_index["default"].ofString('123'), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect (number) to return 123', function () {
    (0, _vitest.expect)(_index2.N.number().parse(_index["default"].ofString('123'), 0).value).toBe(123);
  });
  (0, _vitest.it)('expect negative (number) to be accepted', function () {
    (0, _vitest.expect)(_index2.N.number().parse(_index["default"].ofString('-123'), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect negative (number) to return -123', function () {
    (0, _vitest.expect)(_index2.N.number().parse(_index["default"].ofString('-123'), 0).value).toBe(-123);
  });
  (0, _vitest.it)('expect float (number) to be accepted', function () {
    (0, _vitest.expect)(_index2.N.number().parse(_index["default"].ofString('123.34e-34'), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect float (number) to return 123.34e-34', function () {
    (0, _vitest.expect)(_index2.N.number().parse(_index["default"].ofString('123.34e-34'), 0).value).toBe(123.34e-34);
  });
  (0, _vitest.it)('expect (charLiteral) to be accepted', function () {
    (0, _vitest.expect)(_index2.C.charLiteral().parse(_index["default"].ofString("'a'"), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect (charLiteral) to return a', function () {
    (0, _vitest.expect)(_index2.C.charLiteral().parse(_index["default"].ofString("'a'"), 0).value).toBe('a');
  });
  (0, _vitest.it)('expect (charLiteral) quote to be accepted', function () {
    (0, _vitest.expect)(_index2.C.charLiteral().parse(_index["default"].ofString("'\\''"), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect (charLiteral) to be rejected', function () {
    (0, _vitest.expect)(_index2.C.charLiteral().parse(_index["default"].ofString("''"), 0).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect (stringLiteral) to be accepted', function () {
    (0, _vitest.expect)(_index2.C.stringLiteral().parse(_index["default"].ofString('"a"'), 0).isAccepted()).toBe(true);
  });
});
//# sourceMappingURL=parser_extensions_test.spec.js.map