blob: c6f2e4d2520ed45b65fea0a226ef186bb0ef2a3f [file] [log] [blame]
Andrew de Andrade5e0f7752015-07-29 15:43:15 -07001'use strict';
2var test = require('tape');
3var thrift = require('../lib/thrift/thrift.js');
4var InputBufferUnderrunError = require('../lib/thrift/input_buffer_underrun_error');
5
6test('TApplicationException', function t(assert) {
7 var e = new thrift.TApplicationException(1, 'foo');
8 assert.ok(e instanceof thrift.TApplicationException, 'is instanceof TApplicationException');
9 assert.ok(e instanceof thrift.TException, 'is instanceof TException');
10 assert.ok(e instanceof Error, 'is instanceof Error');
11 assert.equal(typeof e.stack, 'string', 'has stack trace');
12 assert.ok(/^TApplicationException: foo/.test(e.stack), 'Stack trace has correct error name and message');
13 assert.ok(e.stack.indexOf('test/exceptions.js:7:11') !== -1, 'stack trace starts on correct line and column');
14 assert.equal(e.name, 'TApplicationException', 'has function name TApplicationException');
15 assert.equal(e.message, 'foo', 'has error message "foo"');
16 assert.equal(e.type, 1, 'has type 1');
17 assert.end();
18});
19
20test('TException', function t(assert) {
21 var e = new thrift.TException('foo');
22 assert.ok(e instanceof thrift.TException, 'is instanceof TException');
23 assert.ok(e instanceof Error, 'is instanceof Error');
24 assert.equal(typeof e.stack, 'string', 'has stack trace');
25 assert.ok(/^TException: foo/.test(e.stack), 'Stack trace has correct error name and message');
26 assert.ok(e.stack.indexOf('test/exceptions.js:21:11') !== -1, 'stack trace starts on correct line and column');
27 assert.equal(e.name, 'TException', 'has function name TException');
28 assert.equal(e.message, 'foo', 'has error message "foo"');
29 assert.end();
30});
31
32test('TProtocolException', function t(assert) {
33 var e = new thrift.TProtocolException(1, 'foo');
34 assert.ok(e instanceof thrift.TProtocolException, 'is instanceof TProtocolException');
35 assert.ok(e instanceof Error, 'is instanceof Error');
36 assert.equal(typeof e.stack, 'string', 'has stack trace');
37 assert.ok(/^TProtocolException: foo/.test(e.stack), 'Stack trace has correct error name and message');
38 assert.ok(e.stack.indexOf('test/exceptions.js:33:11') !== -1, 'stack trace starts on correct line and column');
39 assert.equal(e.name, 'TProtocolException', 'has function name TProtocolException');
40 assert.equal(e.message, 'foo', 'has error message "foo"');
41 assert.equal(e.type, 1, 'has type 1');
42 assert.end();
43});
44
45test('InputBufferUnderrunError', function t(assert) {
46 var e = new InputBufferUnderrunError('foo');
47 assert.ok(e instanceof InputBufferUnderrunError, 'is instanceof InputBufferUnderrunError');
48 assert.ok(e instanceof Error, 'is instanceof Error');
49 assert.equal(typeof e.stack, 'string', 'has stack trace');
50 assert.ok(/^InputBufferUnderrunError: foo/.test(e.stack), 'Stack trace has correct error name and message');
51 assert.ok(e.stack.indexOf('test/exceptions.js:46:11') !== -1, 'stack trace starts on correct line and column');
52 assert.equal(e.name, 'InputBufferUnderrunError', 'has function name InputBufferUnderrunError');
53 assert.equal(e.message, 'foo', 'has error message "foo"');
54 assert.end();
55});