Andrew de Andrade | 5e0f775 | 2015-07-29 15:43:15 -0700 | [diff] [blame] | 1 | 'use strict'; |
| 2 | var test = require('tape'); |
| 3 | var thrift = require('../lib/thrift/thrift.js'); |
| 4 | var InputBufferUnderrunError = require('../lib/thrift/input_buffer_underrun_error'); |
| 5 | |
| 6 | test('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 | |
| 20 | test('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 | |
| 32 | test('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 | |
| 45 | test('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 | }); |