"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 val to be a nice shortcut': function expect_val_to_be_a_nice_shortcut(test) {
    var parser = _index2.C.string('xyz');
    var val = parser.val('xyz');
    test.equal(val, 'xyz');
    test.done();
  },
  'expect (map) to be accepted': function expect_Map_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').map(function (a) {
      return a + 'b';
    }).parse(_index["default"].ofString('a'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (map) to be rejected': function expect_Map_to_be_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').map(function (a) {
      return a + 'b';
    }).parse(_index["default"].ofString('b'), 0).isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'expect (map) to be return ab': function expect_Map_to_be_return_ab(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').map(function (a) {
      return a + 'b';
    }).parse(_index["default"].ofString('a'), 0).value, 'ab', 'should be accepted.');
    test.done();
  },
  'expect (map) to be return 5x8': function expect_Map_to_be_return_5x8(test) {
    test.expect(1);
    try {
      var st = _index["default"].ofString('5x8');
      var combinator = _index2.N.integer().then(_index2.C["char"]('x').drop()).then(_index2.N.integer()).array().map(function (values) {
        return values[0] * values[1];
      });
      test.equal(combinator.parse(st).value, 40, 'should be accepted.');
    } catch (e) {
      console.log(e);
    }
    test.done();
  },
  'expect (flatMap) to be accepted': function expect_FlatMap_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').flatMap(function () {
      return _index2.F.returns('b');
    }).parse(_index["default"].ofString('a'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (flatMap) to be rejected ': function expect_FlatMap_to_be_rejected_(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').flatMap(function () {
      return _index2.F.returns('b');
    }).parse(_index["default"].ofString('b'), 0).isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'expect (flatMap) to be return ab': function expect_FlatMap_to_be_return_ab(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').flatMap(function () {
      return _index2.C["char"]('b');
    }).parse(_index["default"].ofString('ab'), 0).value, 'b', 'should be accepted.');
    test.done();
  },
  'expect (filter) to be accepted': function expect_Filter_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').filter(function (a) {
      return a === 'a';
    }).parse(_index["default"].ofString('a'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (filter) to be rejected': function expect_Filter_to_be_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').filter(function (a) {
      return a === 'b';
    }).parse(_index["default"].ofString('a'), 0).isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'expect (match) to be accepted': function expect_Match_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').match('a').parse(_index["default"].ofString('a'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (match) to be rejected': function expect_Match_to_be_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').match('b').parse(_index["default"].ofString('a'), 0).isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'expect (then) to be accepted': function expect_Then_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').then(_index2.C["char"]('b')).parse(_index["default"].ofString('ab'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (then) left to be rejected': function expect_Then_left_to_be_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').then(_index2.C["char"]('b')).parse(_index["default"].ofString('cb'), 0).isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'expect (then) right to be rejected': function expect_Then_right_to_be_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').then(_index2.C["char"]('b')).parse(_index["default"].ofString('ac'), 0).isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'expect (then) to return [a,b]': function expect_Then_to_return_AB(test) {
    test.expect(1);
    // tests here
    // const stream = stream.ofString("ab");
    test.deepEqual(_index2.C["char"]('a').then(_index2.C["char"]('b')).array().parse(_index["default"].ofString('ab'), 0).value, ['a', 'b'], 'should be accepted.');
    test.done();
  },
  'expect (then) to return [a,b,d]': function expect_Then_to_return_ABD(test) {
    test.expect(1);
    // tests here
    // const stream = stream.ofString("ab");
    test.deepEqual(_index2.C["char"]('a').then(_index2.C["char"]('b').then(_index2.C["char"]('c').drop()).then(_index2.C["char"]('d'))).array().parse(_index["default"].ofString('abcd'), 0).value, ['a', 'b', 'd'], 'should be accepted.');
    test.done();
  },
  'expect (then) to be empty with two drops ': function expect_Then_to_be_empty_with_two_drops_(test) {
    var parser = _index2.C["char"]('a').drop().then(_index2.C["char"]('b').drop());
    var value = parser.parse(_index["default"].ofString('ab')).value.value;
    test.ok(Array.isArray(value));
    test.equal(value.length, 0);
    test.done();
  },
  'expect (then) to be associative ': function expect_Then_to_be_associative_(test) {
    test.expect(1);
    var first = _index2.C["char"]('a').then(_index2.C["char"]('b')).then(_index2.C["char"]('c').drop()).then(_index2.C["char"]('d')).array();
    var second = _index2.C["char"]('a').then(_index2.C["char"]('b')).then(_index2.C["char"]('c').drop().then(_index2.C["char"]('d'))).array();
    test.deepEqual(first.parse(_index["default"].ofString('abcd')).value, second.parse(_index["default"].ofString('abcd')).value);
    test.done();
  },
  'expect (then) to be replaced by concat ': function expect_Then_to_be_replaced_by_concat_(test) {
    test.expect(1);
    // tests here
    // const stream = stream.ofString("ab");
    test.deepEqual(_index2.C["char"]('a').concat(_index2.C["char"]('b')).then(_index2.C["char"]('c').drop()).concat(_index2.C["char"]('d')).array().parse(_index["default"].ofString('abcd'), 0).value, ['a', 'b', 'd'], 'should be accepted.');
    test.done();
  },
  'expect (thenLeft) to be accepted': function expect_ThenLeft_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').thenLeft(_index2.C["char"]('b')).parse(_index["default"].ofString('ab'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (thenLeft) to return a': function expect_ThenLeft_to_return_a(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_index2.C["char"]('a').thenLeft(_index2.C["char"]('b')).single().parse(_index["default"].ofString('ab'), 0).value, 'a', 'should be accepted.');
    test.done();
  },
  'expect (thenLeft) to be rejected': function expect_ThenLeft_to_be_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').thenLeft(_index2.C["char"]('b')).parse(_index["default"].ofString('b'), 0).isAccepted(), false, 'should be accepted.');
    test.done();
  },
  'expect (thenRight) to be accepted': function expect_ThenRight_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').thenRight(_index2.C["char"]('b')).parse(_index["default"].ofString('ab'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (thenRight) to return a': function expect_ThenRight_to_return_a(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_index2.C["char"]('a').thenRight(_index2.C["char"]('b')).single().parse(_index["default"].ofString('ab'), 0).value, 'b', 'should be accepted.');
    test.done();
  },
  'expect (thenRight) to be rejected': function expect_ThenRight_to_be_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').thenRight(_index2.C["char"]('b')).parse(_index["default"].ofString('b'), 0).isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'expect (drop/then) to be accepted': function expect_Drop_then_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').drop().then(_index2.C["char"]('b')).parse(_index["default"].ofString('ab'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (drop/then) to be return b': function expect_Drop_then_to_be_return_b(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').drop().then(_index2.C["char"]('b')).single().parse(_index["default"].ofString('ab'), 0).value, 'b', 'should be accepted.');
    test.done();
  },
  'expect (then/drop) to be accepted': function expect_Then_drop_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').then(_index2.C["char"]('b').drop()).parse(_index["default"].ofString('ab'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (drop/then) to be return a': function expect_Drop_then_to_be_return_a(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').then(_index2.C["char"]('b').drop()).single().parse(_index["default"].ofString('ab'), 0).value, 'a', 'should be accepted.');
    test.done();
  },
  'expect (eos) to be accepted at the end': function expect_Eos_to_be_accepted_at_the_end(test) {
    var parser = _index2.C.string('abc').eos();
    var response = parser.parse(_index["default"].ofString('abc'));
    test.ok(response.isAccepted(), 'should be accepted.');
    test.ok(response.isEos());
    test.equal(response.value, 'abc'); // not tuple([a]) !
    test.done();
  },
  'expect (eos) to be rejected without eating char': function expect_Eos_to_be_rejected_without_eating_char(test) {
    var parser = _index2.C["char"]('a').eos();
    var response = parser.parse(_index["default"].ofString('ab'));
    test.ok(!response.isAccepted(), 'should not be accepted.');
    test.ok(!response.isEos());
    test.equal(response.offset, 1);
    test.equal(response.value, undefined); // not tuple([a]) !
    test.done();
  },
  'expect rejected (eos) to be rejected keeping previous offset': function expect_rejected_Eos_to_be_rejected_keeping_previous_offset(test) {
    var parser = _index2.C["char"]('a').then(_index2.C["char"]('a')).eos();

    // this will pass by the reject argument function of .eos()
    var response = parser.parse(_index["default"].ofString('ab is ending at 1'));
    test.ok(!response.isAccepted(), 'should not be accepted.');
    test.ok(!response.isEos());
    test.equal(response.offset, 1);
    test.equal(response.value, undefined); // not tuple([a]) !
    test.done();
  },
  'expect (thenEos) to be accepted at the end': function expect_ThenEos_to_be_accepted_at_the_end(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').thenEos().parse(_index["default"].ofString('a')).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (thenEos) to be rejected if not the end': function expect_ThenEos_to_be_rejected_if_not_the_end(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').thenEos().parse(_index["default"].ofString('abc')).isAccepted(), false, 'should be rejected');
    test.done();
  },
  'expect (returns) to be accepted': function expect_Returns_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').returns('b').parse(_index["default"].ofString('ab'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (returns) to return b': function expect_Returns_to_return_b(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').returns('b').parse(_index["default"].ofString('ab'), 0).value, 'b', 'should be accepted.');
    test.done();
  },
  'expect (returns) not to eat char': function expect_Returns_not_to_eat_char(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_index2.C["char"]('a').returns('X').then(_index2.C["char"]('b')).array().parse(_index["default"].ofString('ab'), 0).value, ['X', 'b'], 'should be accepted.');
    test.done();
  },
  'expect (returns) to be rejected': function expect_Returns_to_be_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').returns('b').parse(_index["default"].ofString('b'), 0).isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'expect (or) to be accepted': function expect_Or_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').or(_index2.C["char"]('b')).parse(_index["default"].ofString('a'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (or) to be rejected': function expect_Or_to_be_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').or(_index2.C["char"]('b')).parse(_index["default"].ofString('c'), 0).isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'expect (or) LL(1) to be rejected': function expect_Or_LL1_to_be_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').then(_index2.C["char"]('b')).or(_index2.C["char"]('a')).parse(_index["default"].ofString('ac'), 0).isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'expect (or) to return a': function expect_Or_to_return_a(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_index2.C["char"]('a').or(_index2.C["char"]('b')).parse(_index["default"].ofString('a'), 0).value, 'a', 'should be accepted.');
    test.done();
  },
  'expect (or) to return b': function expect_Or_to_return_b(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_index2.C["char"]('a').or(_index2.C["char"]('b')).parse(_index["default"].ofString('b'), 0).value, 'b', 'should be accepted.');
    test.done();
  },
  'expect (then.or) left to be rejected': function expect_ThenOr_left_to_be_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').then(_index2.C["char"]('b').or(_index2.C["char"]('c'))).parse(_index["default"].ofString('ad'), 0).isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'expect (then.or) left to be consumed': function expect_ThenOr_left_to_be_consumed(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C["char"]('a').then(_index2.C["char"]('b').or(_index2.C["char"]('c'))).parse(_index["default"].ofString('ad'), 0).consumed, true, 'should be consumed.');
    test.done();
  },
  'expect (opt) some to accepted': function expect_Opt_some_to_accepted(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_index2.C["char"]('a').opt().parse(_index["default"].ofString('a'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (opt) some to return some a': function expect_Opt_some_to_return_some_a(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_index2.C["char"]('a').opt().parse(_index["default"].ofString('a'), 0).value.get(), 'a', 'should be a.');
    test.done();
  },
  'expect (opt) none to accepted': function expect_Opt_none_to_accepted(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_index2.C["char"]('a').opt().parse(_index["default"].ofString('b'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (opt) none to return none': function expect_Opt_none_to_return_none(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_index2.C["char"]('a').opt().parse(_index["default"].ofString('b'), 0).value.isPresent(), false, 'should be accepted but none.');
    test.done();
  },
  'expect (rep) to accepted': function expect_Rep_to_accepted(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_index2.C["char"]('a').rep().parse(_index["default"].ofString('a'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (rep) to rejected': function expect_Rep_to_rejected(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_index2.C["char"]('a').rep().parse(_index["default"].ofString('b'), 0).isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'expect (rep) mutiple to accepted': function expect_Rep_mutiple_to_accepted(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_index2.C["char"]('a').rep().parse(_index["default"].ofString('aaaabbb'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (rep) mutiple to return [a,a,a,a]': function expect_Rep_mutiple_to_return_AAAA(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_index2.C["char"]('a').rep().parse(_index["default"].ofString('aaaabbb'), 0).value.array(), ['a', 'a', 'a', 'a'], 'should be accepted.');
    test.done();
  },
  'expect (optrep) to accepted': function expect_Optrep_to_accepted(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_index2.C["char"]('a').optrep().parse(_index["default"].ofString('a'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (optrep) none to accepted': function expect_Optrep_none_to_accepted(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_index2.C["char"]('a').optrep().parse(_index["default"].ofString('b'), 0).isAccepted(), true, 'should be rejected.');
    test.done();
  },
  'expect (optrep) mutiple to accepted': function expect_Optrep_mutiple_to_accepted(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_index2.C["char"]('a').optrep().parse(_index["default"].ofString('aaaabbb'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (optrep) mutiple to return some [a,a,a,a]': function expect_Optrep_mutiple_to_return_some_AAAA(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_index2.C["char"]('a').optrep().parse(_index["default"].ofString('aaaabbb'), 0).value.array(), ['a', 'a', 'a', 'a'], 'should be accepted.');
    test.done();
  },
  'expect (optrep) to return none': function expect_Optrep_to_return_none(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_index2.C["char"]('a').optrep().parse(_index["default"].ofString('bbb'), 0).value.array(), [], 'should be accepted.');
    test.done();
  },
  'expect (optrep) to return [b,b,b]': function expect_Optrep_to_return_BBB(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_index2.C.notChar('a').optrep().parse(_index["default"].ofString('bbba'), 0).value.array(), ['b', 'b', 'b'], 'should be accepted.');
    test.done();
  },
  'expect two (optrep) to be merged as [b,b,b,a]]': function expect_two_Optrep_to_be_merged_as_BBBA(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_index2.C["char"]('b').optrep().then(_index2.C["char"]('a').optrep()).array().parse(_index["default"].ofString('bbba'), 0).value, ['b', 'b', 'b', 'a'], 'should be accepted.');
    test.done();
  },
  'expect two (optrep) to return [[b,b,b],[a]] using array()': function expect_two_Optrep_to_return_BBBA_using_array(test) {
    test.expect(1);
    // tests here
    test.deepEqual(_index2.C["char"]('b').optrep().array().then(_index2.C["char"]('a').optrep()).array().parse(_index["default"].ofString('bbba'), 0).value, [['b', 'b', 'b'], ['a']], 'should be accepted.');
    test.done();
  },
  'expect debug() to make side effect': function expect_debug_to_make_side_effect(test) {
    test.expect(1);
    // tests here
    var original = console.log;
    var sideEffect = false;
    console.log = function () {
      sideEffect = true;
    };

    // side effect action
    _index2.C["char"]('a').debug('found').optrep().parse(_index["default"].ofString('aaa'), 0);
    console.log = original;
    test.deepEqual(sideEffect, true, 'should make side effect.');
    test.done();
  },
  'expect debug(param, false) to make side effect': function expect_debugParam_false_to_make_side_effect(test) {
    test.expect(1);
    // tests here
    var original = console.log;
    var sideEffect = false;
    console.log = function () {
      sideEffect = true;
    };

    // side effect action : will hide the details
    _index2.C["char"]('a').debug('found', false).optrep().parse(_index["default"].ofString('aaa'), 0);
    console.log = original;
    test.deepEqual(sideEffect, true, 'should make side effect.');
    test.done();
  },
  'expect (debug) to not make side effect': function expect_Debug_to_not_make_side_effect(test) {
    test.expect(1);
    // tests here
    var original = console.log;
    var sideEffect = false;
    console.log = function () {
      sideEffect = true;
    };

    // side effect action
    _index2.C["char"]('a').debug('found').optrep().parse(_index["default"].ofString('xxxx'), 0);
    console.log = original;
    test.deepEqual(sideEffect, false, 'should make side effect.');
    test.done();
  }
};
//# sourceMappingURL=parser_core_test.js.map