parser-combinator
Version:
Parser combinators
141 lines (118 loc) • 4.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _index = require('../../../lib/stream/index');
var _index2 = _interopRequireDefault(_index);
var _jsonparser = require('../../../lib/standard/json/jsonparser');
var _jsonparser2 = _interopRequireDefault(_jsonparser);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
======== 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)
*/
exports.default = {
setUp: function setUp(done) {
done();
},
'number accepted': function numberAccepted(test) {
test.expect(1);
// tests here
test.ok(_jsonparser2.default.parse(_index2.default.ofString('123')).isAccepted(), 'should be accepted.');
test.done();
},
'string accepted': function stringAccepted(test) {
test.expect(1);
// tests here
test.ok(_jsonparser2.default.parse(_index2.default.ofString('"123"')).isAccepted(), 'should be accepted.');
test.done();
},
'string and unrecognized item rejected': function stringAndUnrecognizedItemRejected(test) {
test.expect(1);
// tests here
test.equal(_jsonparser2.default.parse(_index2.default.ofString('"123" -')).isAccepted(), false, 'should be rejected.');
test.done();
},
'string and unrecognized item rejected with correct offset': function stringAndUnrecognizedItemRejectedWithCorrectOffset(test) {
test.expect(1);
// tests here
var result = _jsonparser2.default.parse(_index2.default.ofString('["123", -]'));
test.equal(result.offset, 7, 'should be 7.');
test.done();
},
'null accepted': function nullAccepted(test) {
test.expect(1);
// tests here
test.ok(_jsonparser2.default.parse(_index2.default.ofString('null')).isAccepted(), 'should be accepted.');
test.done();
},
'true accepted': function trueAccepted(test) {
test.expect(1);
// tests here
test.ok(_jsonparser2.default.parse(_index2.default.ofString('true')).isAccepted(), 'should be accepted.');
test.done();
},
'false accepted': function falseAccepted(test) {
test.expect(1);
// tests here
test.ok(_jsonparser2.default.parse(_index2.default.ofString('false')).isAccepted(), 'should be accepted.');
test.done();
},
'empty array accepted': function emptyArrayAccepted(test) {
test.expect(1);
// tests here
test.ok(_jsonparser2.default.parse(_index2.default.ofString('[ ]')).isAccepted(), 'should be accepted.');
test.done();
},
'singleton array accepted': function singletonArrayAccepted(test) {
test.expect(1);
// tests here
test.ok(_jsonparser2.default.parse(_index2.default.ofString('[ 123 ]')).isAccepted(), 'should be accepted.');
test.done();
},
'multi element array accepted': function multiElementArrayAccepted(test) {
test.expect(1);
// tests here
test.ok(_jsonparser2.default.parse(_index2.default.ofString('[ 123 , 234 ]')).isAccepted(), 'should be accepted.');
test.done();
},
'empty object accepted': function emptyObjectAccepted(test) {
test.expect(1);
// tests here
test.ok(_jsonparser2.default.parse(_index2.default.ofString('{ }')).isAccepted(), 'should be accepted.');
test.done();
},
'singleton object accepted': function singletonObjectAccepted(test) {
test.expect(1);
// tests here
test.ok(_jsonparser2.default.parse(_index2.default.ofString('{ "a" : "v" }')).isAccepted(), 'should be accepted.');
test.done();
},
'multi element object accepted': function multiElementObjectAccepted(test) {
test.expect(1);
// tests here
test.ok(_jsonparser2.default.parse(_index2.default.ofString('{ "a" : "v", "a" : [] }')).isAccepted(), 'should be accepted.');
test.done();
},
'multi level object accepted': function multiLevelObjectAccepted(test) {
test.expect(1);
// tests here
test.ok(_jsonparser2.default.parse(_index2.default.ofString('{ "a" : "v", "b" : {"c":{"d":12} }}')).isAccepted(), 'should be accepted.');
test.done();
}
};
//# sourceMappingURL=jsonparser_test.js.map