summaryrefslogtreecommitdiffstats
path: root/tests/zerror.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-11-20 06:01:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-11-20 06:19:39 +0000
commit56eec1de7018759c0ec251dba4455c18f73c3bbd (patch)
tree3aeb2d10356530bc2cc3f24e74f41048a13885b4 /tests/zerror.js
parentInitial commit. (diff)
downloadzmodemjs-56eec1de7018759c0ec251dba4455c18f73c3bbd.tar.xz
zmodemjs-56eec1de7018759c0ec251dba4455c18f73c3bbd.zip
Adding upstream version 0.1.10+dfsg.upstream/0.1.10+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/zerror.js')
-rw-r--r--tests/zerror.js82
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/zerror.js b/tests/zerror.js
new file mode 100644
index 0000000..f7961e6
--- /dev/null
+++ b/tests/zerror.js
@@ -0,0 +1,82 @@
+#!/usr/bin/env node
+
+"use strict";
+
+global.Zmodem = require('./lib/zmodem');
+
+const tape = require('blue-tape'),
+ TYPE_CHECKS = {
+ aborted: [ [] ],
+ peer_aborted: [],
+ already_aborted: [],
+ crc: [
+ [ [ 1, 2 ], [ 3, 4 ] ],
+ (t, err) => {
+ t.ok(
+ /1,2/.test(err.message),
+ '"got" values are in the message'
+ );
+ t.ok(
+ /3,4/.test(err.message),
+ '"expected" values are in the message'
+ );
+ t.ok(
+ /CRC/i.test(err.message),
+ '"CRC" is in the message'
+ );
+ },
+ ],
+ validation: [
+ [ "some string" ],
+ (t, err) => {
+ t.is(
+ err.message,
+ "some string",
+ 'message is given value'
+ );
+ },
+ ],
+ }
+;
+
+tape("typed", (t) => {
+ let Ctr = Zmodem.Error;
+
+ for (let type in TYPE_CHECKS) {
+ let args = [type].concat( TYPE_CHECKS[type][0] );
+
+ //https://stackoverflow.com/questions/33193310/constr-applythis-args-in-es6-classes
+ var err = new (Ctr.bind.apply(Ctr, [null].concat(args)));
+
+ t.ok(
+ (err instanceof Zmodem.Error),
+ `${type} type isa ZmodemError`
+ );
+ t.ok(
+ !!err.message.length,
+ `${type}: message has length`
+ );
+
+ if ( TYPE_CHECKS[type][1] ) {
+ TYPE_CHECKS[type][1](t, err);
+ }
+ }
+
+ t.end();
+});
+
+tape("generic", (t) => {
+ let err = new Zmodem.Error("Van Gogh was a guy.");
+
+ t.ok(
+ (err instanceof Zmodem.Error),
+ `generic isa ZmodemError`
+ );
+ t.is(
+ err.message,
+ "Van Gogh was a guy.",
+ "passthrough of string"
+ );
+
+ t.end();
+});