"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 }; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
(0, _vitest.describe)('Chars Bundle Tests', function () {
  (0, _vitest.it)('expect (char) to be accepted', function () {
    (0, _vitest.expect)(_index2.C["char"]('a').parse(_index["default"].ofString('a'), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect (char) to be rejected', function () {
    (0, _vitest.expect)(_index2.C["char"]('a').parse(_index["default"].ofString('b'), 0).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect (char) to be refused', function () {
    (0, _vitest.expect)(function () {
      return _index2.C["char"]('aa');
    }).toThrow();
  });
  (0, _vitest.it)('expect (notChar) to be accepted', function () {
    (0, _vitest.expect)(_index2.C.notChar('a').parse(_index["default"].ofString('b'), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect (notChar) to be rejected', function () {
    (0, _vitest.expect)(_index2.C.notChar('a').parse(_index["default"].ofString('a'), 0).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect (notChar) to be refused', function () {
    (0, _vitest.expect)(function () {
      return _index2.C.notChar('aa');
    }).toThrow();
  });
  (0, _vitest.it)('expect (charNotIn) to be accepted', function () {
    (0, _vitest.expect)(_index2.C.charNotIn('a').parse(_index["default"].ofString('b'), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect (charNotIn) to be rejected', function () {
    (0, _vitest.expect)(_index2.C.charNotIn('a').parse(_index["default"].ofString('a'), 0).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect (charIn) to be accepted', function () {
    (0, _vitest.expect)(_index2.C.charIn('a').parse(_index["default"].ofString('a'), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect (charIn) to be rejected', function () {
    (0, _vitest.expect)(_index2.C.charIn('a').parse(_index["default"].ofString('b'), 0).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect (lowerCase) to be accepted', function () {
    (0, _vitest.expect)(_index2.C.lowerCase().parse(_index["default"].ofString('a'), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect (lowerCase) to be rejected', function () {
    (0, _vitest.expect)(_index2.C.lowerCase().parse(_index["default"].ofString('A'), 0).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect (upperCase) to be accepted', function () {
    (0, _vitest.expect)(_index2.C.upperCase().parse(_index["default"].ofString('A'), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect (upperCase) to be rejected', function () {
    (0, _vitest.expect)(_index2.C.upperCase().parse(_index["default"].ofString('z'), 0).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect upper (letter) to be accepted', function () {
    (0, _vitest.expect)(_index2.C.letter().parse(_index["default"].ofString('A'), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect lower (letter) to be accepted', function () {
    (0, _vitest.expect)(_index2.C.letter().parse(_index["default"].ofString('z'), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect space (letter) to be rejected', function () {
    (0, _vitest.expect)(_index2.C.letter().parse(_index["default"].ofString(' '), 0).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect non (letter) to be rejected', function () {
    (0, _vitest.expect)(_index2.C.letter().parse(_index["default"].ofString('0'), 0).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect occidental letter to be accepted', function () {
    (0, _vitest.expect)(_index2.C.letter().parse(_index["default"].ofString('a'), 0).isAccepted()).toBe(true);
    (0, _vitest.expect)(_index2.C.letterAs().parse(_index["default"].ofString('a'), 0).isAccepted()).toBe(true);
    (0, _vitest.expect)(_index2.C.letterAs(_index2.C.OCCIDENTAL_LETTER).parse(_index["default"].ofString('a')).isAccepted()).toBe(true);
    (0, _vitest.expect)(_index2.C.letterAs(_index2.C.OCCIDENTAL_LETTER).parse(_index["default"].ofString('é')).isAccepted()).toBe(true);
    (0, _vitest.expect)(_index2.C.letterAs(_index2.C.OCCIDENTAL_LETTER).parse(_index["default"].ofString('Б')).isAccepted()).toBe(false);
    (0, _vitest.expect)(_index2.C.letterAs(_index2.C.OCCIDENTAL_LETTER).parse(_index["default"].ofString('÷')).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect occidental letters to be accepted', function () {
    (0, _vitest.expect)(_index2.C.letters().then(_index2.F.eos()).parse(_index["default"].ofString('aéÉ'), 0).isAccepted()).toBe(true);
    (0, _vitest.expect)(_index2.C.lettersAs().then(_index2.F.eos()).parse(_index["default"].ofString('aéÉ'), 0).isAccepted()).toBe(true);
    (0, _vitest.expect)(_index2.C.lettersAs(_index2.C.OCCIDENTAL_LETTER).parse(_index["default"].ofString('a')).isAccepted()).toBe(true);
    (0, _vitest.expect)(_index2.C.lettersAs(_index2.C.OCCIDENTAL_LETTER).then(_index2.F.eos()).parse(_index["default"].ofString('éA')).isAccepted()).toBe(true);
    (0, _vitest.expect)(_index2.C.lettersAs(_index2.C.OCCIDENTAL_LETTER).then(_index2.F.eos()).parse(_index["default"].ofString('БAs')).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect ascii letter to be accepted', function () {
    (0, _vitest.expect)(_index2.C.letterAs(_index2.C.ASCII_LETTER).parse(_index["default"].ofString('a'), 0).isAccepted()).toBe(true);
    (0, _vitest.expect)(_index2.C.letterAs(_index2.C.ASCII_LETTER).parse(_index["default"].ofString('é')).isAccepted()).toBe(false);
    (0, _vitest.expect)(_index2.C.letterAs(_index2.C.ASCII_LETTER).parse(_index["default"].ofString('Б')).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect ascii letters to be accepted', function () {
    (0, _vitest.expect)(_index2.C.lettersAs(_index2.C.ASCII_LETTER).then(_index2.F.eos()).parse(_index["default"].ofString('a')).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect utf8 letter to be accepted', function () {
    (0, _vitest.expect)(_index2.C.letterAs(_index2.C.UTF8_LETTER).parse(_index["default"].ofString('a')).isAccepted()).toBe(true);
    (0, _vitest.expect)(_index2.C.letterAs(_index2.C.UTF8_LETTER).parse(_index["default"].ofString('é')).isAccepted()).toBe(true);
    (0, _vitest.expect)(_index2.C.letterAs(_index2.C.UTF8_LETTER).parse(_index["default"].ofString('Б')).isAccepted()).toBe(true);
    (0, _vitest.expect)(_index2.C.letterAs(_index2.C.UTF8_LETTER).parse(_index["default"].ofString('÷')).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect utf8 letters to be accepted', function () {
    (0, _vitest.expect)(_index2.C.lettersAs(_index2.C.UTF8_LETTER).then(_index2.F.eos()).parse(_index["default"].ofString('a')).isAccepted()).toBe(true);
    (0, _vitest.expect)(_index2.C.lettersAs(_index2.C.UTF8_LETTER).then(_index2.F.eos()).parse(_index["default"].ofString('éA')).isAccepted()).toBe(true);
    (0, _vitest.expect)(_index2.C.lettersAs(_index2.C.UTF8_LETTER).then(_index2.F.eos()).parse(_index["default"].ofString('БAs')).isAccepted()).toBe(true);
    (0, _vitest.expect)(_index2.C.letterAs(_index2.C.UTF8_LETTER).then(_index2.F.eos()).parse(_index["default"].ofString('Б÷As')).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect unknown letters to be rejected', function () {
    var line = _index["default"].ofString('a');
    (0, _vitest.expect)(function () {
      var combinator = _index2.C.lettersAs(Symbol('UNKNOWN')).then(_index2.F.eos());
      combinator.parse(line);
    }).toThrow();
  });
  (0, _vitest.it)('expect (letters) to be accepted', function () {
    var parsing = _index2.C.letters().thenLeft(_index2.F.eos()).single().parse(_index["default"].ofString('someLetters'), 0);
    (0, _vitest.expect)(parsing.isAccepted()).toBe(true);
    (0, _vitest.expect)(parsing.value).toBe('someLetters');
  });
  (0, _vitest.it)('expect (letters) with space to be rejected', function () {
    var parsing = _index2.C.letters().then(_index2.F.eos()).parse(_index["default"].ofString('some Letters'), 0);
    (0, _vitest.expect)(parsing.isAccepted()).toBe(false);
    (0, _vitest.expect)(parsing.offset).toBe(4);
  });
  (0, _vitest.it)('expect (letters) with number to be rejected', function () {
    var parsing = _index2.C.letters().then(_index2.F.eos()).parse(_index["default"].ofString('some2Letters'), 0);
    (0, _vitest.expect)(parsing.isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect (letters) to return a string, not an array of letters', function () {
    var parsing = _index2.C.letters().thenLeft(_index2.F.eos()).single().parse(_index["default"].ofString('someLetters'), 0);
    (0, _vitest.expect)(parsing.value).toBe('someLetters');
  });
  (0, _vitest.it)('expect (string) to be accepted', function () {
    (0, _vitest.expect)(_index2.C.string('Hello').parse(_index["default"].ofString('Hello'), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect (string) to be rejected', function () {
    (0, _vitest.expect)(_index2.C.string('hello').parse(_index["default"].ofString('hell'), 0).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('test stringIn', function () {
    var line = _index["default"].ofString('James Bond');
    var combinator = _index2.C.stringIn(['The', 'James', 'Bond', 'series']);
    var value = combinator.parse(line).value;
    (0, _vitest.expect)(_typeof(value)).toBe('string');
    (0, _vitest.expect)(value).toBe('James');
  });
  (0, _vitest.it)('test stringIn Similar', function () {
    var line = _index["default"].ofString('Jack James Jane');
    var combinator = _index2.C.stringIn(['Jamie', 'Jacko', 'Jack']);
    var parsing = combinator.parse(line);
    var value = parsing.value;
    (0, _vitest.expect)(_typeof(value)).toBe('string');
    (0, _vitest.expect)(value).toBe('Jack');
    (0, _vitest.expect)(parsing.offset).toBe('Jack'.length);
  });
  (0, _vitest.it)('test stringIn one string sidecase', function () {
    var line = _index["default"].ofString('James');
    var combinator = _index2.C.stringIn(['James']);
    var value = combinator.parse(line).value;
    (0, _vitest.expect)(_typeof(value)).toBe('string');
    (0, _vitest.expect)(value).toBe('James');
  });
  (0, _vitest.it)('test stringIn empty sidecase', function () {
    var line = _index["default"].ofString('James');
    var combinator = _index2.C.stringIn([]).then(_index2.F.eos());
    var parsing = combinator.parse(line);
    (0, _vitest.expect)(parsing.isAccepted()).toBe(false);
  });
  (0, _vitest.it)('test stringIn empty accept nothing sidecase', function () {
    var line = _index["default"].ofString('');
    var combinator = _index2.C.stringIn([]).then(_index2.F.eos());
    var parsing = combinator.parse(line);
    (0, _vitest.expect)(parsing.isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect (notString) to be accepted', function () {
    (0, _vitest.expect)(_index2.C.notString('**').parse(_index["default"].ofString('hello'), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect (notString) to be h', function () {
    (0, _vitest.expect)(_index2.C.notString('**').parse(_index["default"].ofString('hello'), 0).value).toBe('h');
  });
  (0, _vitest.it)('expect (notString) to be rejected', function () {
    (0, _vitest.expect)(_index2.C.notString('**').parse(_index["default"].ofString('**hello'), 0).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect accent to be accepted', function () {
    (0, _vitest.expect)(_index2.C.utf8Letter().parse(_index["default"].ofString('é'), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect cyriliq to be accepted', function () {
    (0, _vitest.expect)(_index2.C.utf8Letter().parse(_index["default"].ofString('Б'), 0).isAccepted()).toBe(true);
    (0, _vitest.expect)(_index2.C.utf8Letter().parse(_index["default"].ofString('б'), 0).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect dash to be rejected', function () {
    (0, _vitest.expect)(_index2.C.utf8Letter().parse(_index["default"].ofString('-'), 0).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect "nothing" to be rejected', function () {
    (0, _vitest.expect)(_index2.C.utf8Letter().parse(_index["default"].ofString(''), 0).isAccepted()).toBe(false);
  });
  (0, _vitest.it)('expect emoji to be accepted', function () {
    (0, _vitest.expect)(_index2.C.emoji().then(_index2.F.eos()).parse(_index["default"].ofString('б'), 0).isAccepted()).toBe(false);
    (0, _vitest.expect)(_index2.C.emoji().then(_index2.F.eos()).parse(_index["default"].ofString('a'), 0).isAccepted()).toBe(false);
    (0, _vitest.expect)(_index2.C.emoji().then(_index2.F.eos()).parse(_index["default"].ofString('🐵🐵✈️'), 0).isAccepted()).toBe(true);
    (0, _vitest.expect)(_index2.C.emoji().then(_index2.F.eos()).parse(_index["default"].ofString('✈️'), 0).isAccepted()).toBe(true);
    (0, _vitest.expect)(_index2.C.emoji().then(_index2.F.eos()).parse(_index["default"].ofString('🥪')).isAccepted()).toBe(true);
  });
  (0, _vitest.it)('expect subString to works', function () {
    var stream = _index["default"].ofString('James Bond');
    var parser = _index2.C.subString(6).then(_index2.C.string('Bond'));
    var response = parser.parse(stream);
    (0, _vitest.expect)(response.value.array()).toEqual(['James ', 'Bond']);
    (0, _vitest.expect)(response.isEos()).toBe(true);
  });
});
//# sourceMappingURL=chars-bundle-test.spec.js.map