"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 }; }
/*
 ======== A Handy Little Nodeunit Reference ========
 https://github.com/caolan/nodeunit

 Test methods:
 test.expect(numAssertions)
 test.done()
 Test assertions:
 test.ok(value, [message])
 test.equal(actual, expected, [message])
 test.notEqual(actual, expected, [message])
 test.deepEqual(actual, expected, [message])
 test.notDeepEqual(actual, expected, [message])
 test.strictEqual(actual, expected, [message])
 test.notStrictEqual(actual, expected, [message])
 test.throws(block, [error], [message])
 test.doesNotThrow(block, [error], [message])
 test.ifError(value)
 */
var _default = exports["default"] = {
  setUp: function setUp(done) {
    done();
  },
  'expect (returns) to be accepted': function expect_Returns_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.ok(_index2.F.returns().parse(_index["default"].ofString(''), 0).isAccepted(), 'should be accepted.');
    test.done();
  },
  'expect (returns) to return a given value': function expect_Returns_to_return_a_given_value(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.F.returns(123).parse(_index["default"].ofString(''), 0).value, 123, '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.F.error().parse(_index["default"].ofString(''), 0).isAccepted(), false, 'should be accepted.');
    test.done();
  },
  'expect (lazy) to be accepted': function expect_Lazy_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.ok(_index2.F.lazy(function () {
      return _index2.F.returns();
    }).parse(_index["default"].ofString(''), 0).isAccepted(), 'should be accepted.');
    test.done();
  },
  'expect (lazy) to return a given value': function expect_Lazy_to_return_a_given_value(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.F.lazy(function () {
      return _index2.F.returns(123);
    }).parse(_index["default"].ofString(''), 0).value, 123, 'should be accepted.');
    test.done();
  },
  'expect (lazy with empty params) to return a given value': function expect_Lazy_with_empty_params_to_return_a_given_value(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.F.lazy(function () {
      return _index2.F.returns(123);
    }, []).parse(_index["default"].ofString(''), 0).value, 123, 'should be accepted.');
    test.done();
  },
  'expect (lazy) to be rejected': function expect_Lazy_to_be_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.F.lazy(function () {
      return _index2.F.error();
    }).parse(_index["default"].ofString(''), 0).isAccepted(), false, 'should be accepted.');
    test.done();
  },
  'expect (lazy) with a parameter to return a given value': function expect_Lazy_with_a_parameter_to_return_a_given_value(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.F.lazy(function (v) {
      return _index2.F.returns(v);
    }, [123]).parse(_index["default"].ofString(''), 0).value, 123, 'should be accepted.');
    test.done();
  },
  'expect (lazy) with multiple parameters to return a given value': function expect_Lazy_with_multiple_parameters_to_return_a_given_value(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.F.lazy(function (v1, v2) {
      return _index2.F.returns(v1 + v2);
    }, [10, 20]).parse(_index["default"].ofString(''), 0).value, 30, 'should be accepted.');
    test.done();
  },
  'expect (lazy) with unpacked parameters to fail': function expect_Lazy_with_unpacked_parameters_to_fail(test) {
    test.expect(1);
    // tests here

    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;
      }
    }
    test.ok(found, 'should have catch an error');
    test.done();
  },
  'expect (error) to be rejected': function expect_Error_to_be_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.F.error().parse(_index["default"].ofString(''), 0).isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'expect (eos) to be accepted': function expect_Eos_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.F.eos().parse(_index["default"].ofString(''), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (eos) to be rejected': function expect_Eos_to_be_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.F.eos().parse(_index["default"].ofString('a'), 0).isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'expect (satisfy) to be accepted': function expect_Satisfy_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.F.satisfy(function (v) {
      return v === 'a';
    }).parse(_index["default"].ofString('a'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (satisfy) to be return the right value': function expect_Satisfy_to_be_return_the_right_value(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.F.satisfy(function (v) {
      return v === 'a';
    }).parse(_index["default"].ofString('a'), 0).value, 'a', 'should be the right value.');
    test.done();
  },
  'expect (satisfy) to be return the right offset': function expect_Satisfy_to_be_return_the_right_offset(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.F.satisfy(function (v) {
      return v === 'a';
    }).parse(_index["default"].ofString('a'), 0).offset, 1, 'should be the right offset.');
    test.done();
  },
  'expect (satisfy) to be rejected': function expect_Satisfy_to_be_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.F.satisfy(function (v) {
      return v === 'b';
    }).parse(_index["default"].ofString('a'), 0).isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'expect (doTry satisfy) to be accepted': function expect_DoTry_satisfy_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.F["try"](_index2.F.satisfy(function (v) {
      return v === 'a';
    })).parse(_index["default"].ofString('a'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (doTry satisfy) to be rejected': function expect_DoTry_satisfy_to_be_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.F["try"](_index2.F.satisfy(function (v) {
      return v === 'b';
    })).parse(_index["default"].ofString('a'), 0).isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'expect (digit) to be accepted': function expect_Digit_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.N.digit().parse(_index["default"].ofString('1'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (digit) to be rejected': function expect_Digit_to_be_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.N.digit().parse(_index["default"].ofString('a'), 0).isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'expect (number) to be accepted': function expect_Number_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.N.number().parse(_index["default"].ofString('123'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (number) to return 123': function expect_Number_to_return_123(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.N.number().parse(_index["default"].ofString('123'), 0).value, 123, 'should be accepted.');
    test.done();
  },
  'expect negative (number) to be accepted': function expect_negative_Number_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.N.number().parse(_index["default"].ofString('-123'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect negative (number) to return -123': function expect_negative_Number_to_return_123(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.N.number().parse(_index["default"].ofString('-123'), 0).value, -123, 'should be accepted.');
    test.done();
  },
  'expect float (number) to be accepted': function expect_float_Number_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.N.number().parse(_index["default"].ofString('123.34e-34'), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect float (number) to return 123.34e-34': function expect_float_Number_to_return_12334e34(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.N.number().parse(_index["default"].ofString('123.34e-34'), 0).value, 123.34e-34, 'should be accepted.');
    test.done();
  },
  'expect (charLiteral) to be accepted': function expect_CharLiteral_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C.charLiteral().parse(_index["default"].ofString("'a'"), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (charLiteral) to return a': function expect_CharLiteral_to_return_a(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C.charLiteral().parse(_index["default"].ofString("'a'"), 0).value, 'a', 'should be accepted.');
    test.done();
  },
  'expect (charLiteral) quote to be accepted': function expect_CharLiteral_quote_to_be_accepted(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C.charLiteral().parse(_index["default"].ofString("'\\''"), 0).isAccepted(), true, 'should be accepted.');
    test.done();
  },
  'expect (charLiteral) to be rejected': function expect_CharLiteral_to_be_rejected(test) {
    test.expect(1);
    // tests here
    test.equal(_index2.C.charLiteral().parse(_index["default"].ofString("''"), 0).isAccepted(), false, 'should be rejected.');
    test.done();
  },
  'expect (stringLiteral) to be accepted': function expect_StringLiteral_to_be_accepted(test) {
    test.expect(1);
    // tests here
    try {
      test.equal(_index2.C.stringLiteral().parse(_index["default"].ofString('"a"'), 0).isAccepted(), true, 'should be accepted.');
    } catch (e) {
      console.log(e);
    }
    test.done();
  }

  /*
  'expect (stringLiteral) to return abc': function(test) {
      test.expect(1);
      // tests here
      test.equal(
          C.stringLiteral().parse(stream.ofString('"abc"'), 0).value,
          'abc',
          'should be accepted.'
      );
      test.done();
  },
   'expect (stringLiteral) empty to be accepted': function(test) {
      test.expect(1);
      // tests here
      test.equal(
          C.stringLiteral().parse(stream.ofString('""'), 0).isAccepted(),
          true,
          'should be accepted.'
      );
      test.done();
  },
    /*
  'expect (occurence 1) to be accepted': function(test) {
      test.expect(1);
      // tests here
      test.equal(
          F.any().occurrence(1).parse(stream.ofString('a'), 0).isAccepted(),
          true,
          'should be accepted.'
      );
      test.done();
  },
   'expect (occurence 1) to return [a]': function(test) {
      test.expect(1);
      // tests here
      test.deepEqual(
          F.any().occurrence(1).parse(stream.ofString('a'), 0).value.array(),
          ['a'],
          'should be accepted.'
      );
      test.done();
  },
   'expect (occurence 2) to be accepted': function(test) {
      test.expect(1);
      // tests here
      test.equal(
          F.any().occurrence(1).parse(stream.ofString('aa'), 0).isAccepted(),
          true,
          'should be accepted.'
      );
      test.done();
  },
   'expect (occurence 2) to return [a,a]': function(test) {
      test.expect(1);
      // tests here
      test.deepEqual(
          F.any().occurrence(2).parse(stream.ofString('aa'), 0).value.array(),
          ['a', 'a'],
          'should be accepted.'
      );
      test.done();
  },
  ///OK
  /*
  'expect (occurence 3) to return [a,a,a]': function(test) {
      test.expect(1);
      // tests here
      test.deepEqual(
          F.any().occurrence(3).parse(stream.ofString('aaa'), 0).value.array(),
          ['a', 'a', 'a'],
          'should be accepted.'
      );
      test.done();
  },
   'expect (occurence 0) to be accepted': function(test) {
      test.expect(1);
      // tests here
      test.equal(
          F.any().occurrence(0).parse(stream.ofString('aa'), 0).isAccepted(),
          true,
          'should be accepter.'
      );
      test.done();
  },
   'expect (occurence 0) to return []': function(test) {
      test.expect(1);
      // tests here
      test.deepEqual(
          F.any().occurrence(0).parse(stream.ofString('aa'), 0).value.array(),
          [],
          'should be accepter.'
      );
      test.done();
  },
    "expect chained then (2+2) to return [2,'+' ,2]": function(test) {
      // Main difference with sequence, is that a sequence element could be an array
      test.expect(1);
      // tests here
      const string = '2+2';
      const expected = [2, '+', 2];
       const parsing = N.number()
          .then(C.char('+'))
          .then(N.number()).array()
          .parse(stream.ofString(string), 0);
       test.deepEqual(parsing.value, expected, 'should be equal');
      test.done();
  },
   'expect chained then (2+2) to return []': function(test) {
      // Main difference with sequence, is that a sequence element could be an array
      test.expect(1);
      // tests here
      const string = '2+2';
      const expected = [];
       const parsing = N.number()
          .then(C.char('+'))
          .then(N.number())
          .returns([])
          .parse(stream.ofString(string), 0);
       test.deepEqual(parsing.value, expected, 'should be equal');
      test.done();
  },
    'export subStream(4) to return [h,e,l,l]': function(test) {
      test.expect(1);
      // tests here
      const string = 'hello';
      const expected = ['h', 'e', 'l', 'l'];
       const parsing = F.subStream(4).parse(stream.ofString(string), 0);
       test.deepEqual(parsing.value.array(), expected, 'should be equal');
      test.done();
  },
   'export subString(4) to return hell': function(test) {
      test.expect(1);
      // tests here
      const string = 'hello';
      const expected = 'hell';
       const parsing = C.subString(4).parse(stream.ofString(string), 0);
       test.deepEqual(parsing.value, expected, 'should be equal');
      test.done();
  }*/
};
//# sourceMappingURL=parser_extensions_test.js.map