parser-combinator
Version:
Parser combinators
185 lines (161 loc) • 6.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _response = require('../../lib/parsec/response');
var _response2 = _interopRequireDefault(_response);
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();
},
'response accepted': function responseAccepted(test) {
test.expect(1);
// tests here
test.ok(_response2.default.accept().isAccepted(), 'should be accepted.');
test.done();
},
'response as a success': function responseAsASuccess(test) {
test.expect(1);
// tests here
test.ok(_response2.default.accept().toTry().isSuccess(), 'should be success.');
test.done();
},
'response accepted map to accepted': function responseAcceptedMapToAccepted(test) {
test.expect(1);
// tests here
test.ok(_response2.default.accept().map(function (a) {
return a;
}).isAccepted(), 'should be accepted.');
test.done();
},
'response accepted map to return the value': function responseAcceptedMapToReturnTheValue(test) {
test.expect(1);
// tests here
test.equal(_response2.default.accept('a').map(function (a) {
return a;
}).value, 'a', 'should be accepted.');
test.done();
},
'response accepted flatmap to accepted': function responseAcceptedFlatmapToAccepted(test) {
test.expect(1);
// tests here
test.ok(_response2.default.accept('a').flatmap(function (a) {
return _response2.default.accept(a);
}).isAccepted(), 'should be accepted.');
test.done();
},
'response accepted flatmap to return the value': function responseAcceptedFlatmapToReturnTheValue(test) {
test.expect(1);
// tests here
test.ok(_response2.default.accept('a').flatmap(function (a) {
return _response2.default.accept(a);
}).isAccepted(), 'a', 'should be accepted.');
test.done();
},
'response accepted flatmap to reject': function responseAcceptedFlatmapToReject(test) {
test.expect(1);
// tests here
test.equal(_response2.default.accept().flatmap(function () {
return _response2.default.reject();
}).isAccepted(), false, 'should be rejected.');
test.done();
},
'response rejected map to rejected': function responseRejectedMapToRejected(test) {
test.expect(1);
// tests here
test.equal(_response2.default.reject().map(function (t) {
return t;
}).isAccepted(), false, 'should be rejected.');
test.done();
},
'response rejected flatmap to rejected': function responseRejectedFlatmapToRejected(test) {
test.expect(1);
// tests here
test.equal(_response2.default.reject().flatmap(function () {
return _response2.default.accept();
}).isAccepted(), false, 'should be rejected.');
test.done();
},
'response accepted fold': function responseAcceptedFold(test) {
test.expect(1);
// tests here
test.equal(_response2.default.accept('a').fold(function (a) {
return a.value;
}), 'a', 'should retrieve the value.');
test.done();
},
'response filter accepted': function responseFilterAccepted(test) {
test.expect(1);
// tests here
test.ok(_response2.default.accept('a').filter(function (a) {
return a === 'a';
}).isAccepted(), 'should filter the response.');
test.done();
},
'response not filter accepted ': function responseNotFilterAccepted(test) {
test.expect(1);
// tests here
test.equal(_response2.default.accept('a').filter(function (a) {
return a !== 'a';
}).isAccepted(), false, 'should not filter the response.');
test.done();
},
'response rejected': function responseRejected(test) {
test.expect(1);
// tests here
test.equal(_response2.default.reject().isAccepted(), false, 'should be rejected.');
test.done();
},
'response as a failure': function responseAsAFailure(test) {
test.expect(1);
// tests here
test.equal(_response2.default.reject().toTry().isSuccess(), false, 'should be failure.');
test.done();
},
'response rejected fold': function responseRejectedFold(test) {
test.expect(1);
// tests here
test.equal(_response2.default.reject().fold(function (a) {
return a.value;
}, function () {
return 'b';
}), 'b', 'should generate the value.');
test.done();
},
'response filter rejected': function responseFilterRejected(test) {
test.expect(1);
// tests here
test.equal(_response2.default.reject().filter(function () {
return true;
}).isAccepted(), false, 'should not filter the response.');
test.done();
},
'response not filter rejected': function responseNotFilterRejected(test) {
test.expect(1);
// tests here
test.equal(_response2.default.reject().filter(function () {
return false;
}).isAccepted(), false, 'should not filter the response.');
test.done();
}
};
//# sourceMappingURL=response_test.js.map