UNPKG

parser-combinator

Version:
119 lines (101 loc) 5.17 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _tokenBundle = require('../../lib/standard/token-bundle'); var _tokenBundle2 = _interopRequireDefault(_tokenBundle); var _index = require('../../lib/stream/index'); var _index2 = _interopRequireDefault(_index); var _index3 = require('../../lib/parsec/index'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var value = undefined; var accepted = undefined; function testParser(parser, string) { var myStream = _index2.default.ofString(string); var parsing = parser.parse(myStream); value = parsing.value; accepted = parsing.isAccepted(); } exports.default = { setUp: function setUp(done) { done(); }, 'test bad email should fail': function testBadEmailShouldFail(test) { testParser(_tokenBundle2.default.email(), 'random text'); test.ok(!accepted, 'random text should not be recognise as email'); test.done(); }, 'test classic email should be accepted': function testClassicEmailShouldBeAccepted(test) { testParser(_tokenBundle2.default.email(), 'simon.zozol@gmail.com'); var expected = { email: 'simon.zozol@gmail.com' }; test.deepEqual(value, expected, 'error parsing email'); test.done(); }, 'test greek email should be accepted': function testGreekEmailShouldBeAccepted(test) { testParser(_tokenBundle2.default.email(), 'δοκιμή@παράδειγμα.δοκιμή'); var expected = { email: 'δοκιμή@παράδειγμα.δοκιμή' }; test.deepEqual(value, expected, 'error parsing email in greek'); test.done(); }, 'test bad email with 2 @ should be rejected': function testBadEmailWith2ShouldBeRejected(test) { testParser(_tokenBundle2.default.email(), 'simon@zozol@gmail.com'); test.ok(!accepted, 'email adress should reject 2 @ (unless in double quote)'); test.done(); }, 'test email with one quote should be rejected': function testEmailWithOneQuoteShouldBeRejected(test) { testParser(_tokenBundle2.default.email(), 'simon"zozol@gmail.com'); test.ok(!accepted, 'email adress should reject unbalanced double quote'); test.done(); }, 'test email with two quotes should be accepted': function testEmailWithTwoQuotesShouldBeAccepted(test) { testParser(_tokenBundle2.default.email(), 'simon"le gr@nd"@holy-python.com'); var expected = { email: 'simon"le gr@nd"@holy-python.com' }; test.deepEqual(value, expected, 'error parsing email with quote'); test.done(); }, 'test two emails integration should be accepted': function testTwoEmailsIntegrationShouldBeAccepted(test) { var testString = 'simon@holy-python.com δοκιμή@παράδειγμα.δοκιμή'; testParser(_tokenBundle2.default.email().thenLeft(_index3.C.char(' ')).then(_tokenBundle2.default.email()), testString); var expected = [{ email: 'simon@holy-python.com' }, { email: 'δοκιμή@παράδειγμα.δοκιμή' }]; test.deepEqual(value, expected, 'error parsing email chain'); test.done(); }, 'test eol should be found': function testEolShouldBeFound(test) { var testString = 'Hello\nWorld'; testParser(_index3.C.string('Hello').then(_tokenBundle2.default.eol).then(_index3.C.string('World')).then(_index3.F.eos), testString); test.ok(accepted); test.done(); }, 'test eol with Windows \r\n should be found': function testEolWithWindowsShouldBeFound(test) { var testString = 'Hello\r\nWorld'; testParser(_index3.C.string('Hello').then(_tokenBundle2.default.eol).then(_index3.C.string('World')).then(_index3.F.eos), testString); test.ok(accepted); test.done(); }, 'test blanks': function testBlanks(test) { var testString = 'Hello\t World'; testParser(_index3.C.string('Hello').then(_tokenBundle2.default.blank()).then(_index3.C.string('World')).then(_index3.F.eos), testString); test.ok(accepted); test.done(); }, 'test more blanks': function testMoreBlanks(test) { var testString = 'Hello\t\n World'; testParser(_index3.C.string('Hello').then(_tokenBundle2.default.blank(' \t\n')).then(_index3.C.string('World')).then(_index3.F.eos), testString); test.ok(accepted); test.done(); }, 'test blanks with Acceptor': function testBlanksWithAcceptor(test) { var testString = 'Hello\t\r\n World'; var blankAcceptor = _index3.C.charIn(' \t').or(_tokenBundle2.default.eol); testParser(_index3.C.string('Hello').then(_tokenBundle2.default.blank(blankAcceptor)).then(_index3.C.string('World')).then(_index3.F.eos), testString); test.ok(accepted); test.done(); }, 'test date': function testDate(test) { var testString = '2012-10-12'; testParser(_tokenBundle2.default.date().then(_index3.F.eos), testString); test.ok(accepted); test.done(); } }; //# sourceMappingURL=token-test.js.map