[Pkg-javascript-commits] [node-asn1.js] 15/22: test: use let/const in tests
Bastien Roucariès
rouca at moszumanska.debian.org
Thu Nov 9 11:07:34 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch upstream
in repository node-asn1.js.
commit 64d16bcc409cf1a8d100e590c0cc7d28413e1c3b
Author: Fedor Indutny <fedor at indutny.com>
Date: Tue Oct 31 15:56:24 2017 +0100
test: use let/const in tests
---
package.json | 2 +-
test/der-decode-test.js | 46 ++++++++++++++++++------------------
test/der-encode-test.js | 38 +++++++++++++++---------------
test/error-test.js | 32 ++++++++++++-------------
test/fixtures.js | 2 +-
test/pem-test.js | 20 ++++++++--------
test/ping-pong-test.js | 18 +++++++-------
test/tracking-test.js | 20 ++++++++--------
test/use-test.js | 62 ++++++++++++++++++++++++-------------------------
9 files changed, 120 insertions(+), 120 deletions(-)
diff --git a/package.json b/package.json
index 9056382..6b91fb5 100644
--- a/package.json
+++ b/package.json
@@ -7,7 +7,7 @@
"lint-2560": "eslint --fix rfc/2560/*.js rfc/2560/test/*.js",
"lint-5280": "eslint --fix rfc/5280/*.js rfc/5280/test/*.js",
"lint": "eslint --fix lib/*.js lib/**/*.js lib/**/**/*.js && npm run lint-2560 && npm run lint-5280",
- "test": "mocha --reporter spec test/*-test.js && cd rfc/2560 && npm i && npm test && cd ../../rfc/5280 && npm i && npm test"
+ "test": "mocha --reporter spec test/*-test.js && cd rfc/2560 && npm i && npm test && cd ../../rfc/5280 && npm i && npm test && cd ../../ && npm run lint"
},
"repository": {
"type": "git",
diff --git a/test/der-decode-test.js b/test/der-decode-test.js
index 87e5cdd..9d28754 100644
--- a/test/der-decode-test.js
+++ b/test/der-decode-test.js
@@ -1,55 +1,55 @@
'use strict';
/* global describe it */
-var assert = require('assert');
-var asn1 = require('..');
+const assert = require('assert');
+const asn1 = require('..');
-var Buffer = require('buffer').Buffer;
+const Buffer = require('buffer').Buffer;
describe('asn1.js DER decoder', function() {
it('should propagate implicit tag', function() {
- var B = asn1.define('B', function() {
+ const B = asn1.define('B', function() {
this.seq().obj(
this.key('b').octstr()
);
});
- var A = asn1.define('Bug', function() {
+ const A = asn1.define('Bug', function() {
this.seq().obj(
this.key('a').implicit(0).use(B)
);
});
- var out = A.decode(new Buffer('300720050403313233', 'hex'), 'der');
+ const out = A.decode(new Buffer('300720050403313233', 'hex'), 'der');
assert.equal(out.a.b.toString(), '123');
});
it('should decode optional tag to undefined key', function() {
- var A = asn1.define('A', function() {
+ const A = asn1.define('A', function() {
this.seq().obj(
this.key('key').bool(),
this.optional().key('opt').bool()
);
});
- var out = A.decode(new Buffer('30030101ff', 'hex'), 'der');
+ const out = A.decode(new Buffer('30030101ff', 'hex'), 'der');
assert.deepEqual(out, { 'key': true });
});
it('should decode optional tag to default value', function() {
- var A = asn1.define('A', function() {
+ const A = asn1.define('A', function() {
this.seq().obj(
this.key('key').bool(),
this.optional().key('opt').octstr().def('default')
);
});
- var out = A.decode(new Buffer('30030101ff', 'hex'), 'der');
+ const out = A.decode(new Buffer('30030101ff', 'hex'), 'der');
assert.deepEqual(out, { 'key': true, 'opt': 'default' });
});
function test(name, model, inputHex, expected) {
it(name, function() {
- var M = asn1.define('Model', model);
- var decoded = M.decode(new Buffer(inputHex,'hex'), 'der');
+ const M = asn1.define('Model', model);
+ const decoded = M.decode(new Buffer(inputHex,'hex'), 'der');
assert.deepEqual(decoded, expected);
});
}
@@ -61,15 +61,15 @@ describe('asn1.js DER decoder', function() {
}, '0101ff', { 'type': 'apple', 'value': true });
it('should decode optional and use', function() {
- var B = asn1.define('B', function() {
+ const B = asn1.define('B', function() {
this.int();
});
- var A = asn1.define('A', function() {
+ const A = asn1.define('A', function() {
this.optional().use(B);
});
- var out = A.decode(new Buffer('020101', 'hex'), 'der');
+ const out = A.decode(new Buffer('020101', 'hex'), 'der');
assert.equal(out.toString(10), '1');
});
@@ -99,16 +99,16 @@ describe('asn1.js DER decoder', function() {
}, '060a2a830e030a0101010202', 'yes');
it('should decode encapsulated models', function() {
- var B = asn1.define('B', function() {
+ const B = asn1.define('B', function() {
this.seq().obj(
this.key('nested').int()
);
});
- var A = asn1.define('A', function() {
+ const A = asn1.define('A', function() {
this.octstr().contains(B);
});
- var out = A.decode(new Buffer('04053003020105', 'hex'), 'der');
+ const out = A.decode(new Buffer('04053003020105', 'hex'), 'der');
assert.equal(out.nested.toString(10), '5');
});
@@ -129,19 +129,19 @@ describe('asn1.js DER decoder', function() {
}, '1A0B7365707469632074616E6B', 'septic tank');
it('should decode optional seqof', function() {
- var B = asn1.define('B', function() {
+ const B = asn1.define('B', function() {
this.seq().obj(
this.key('num').int()
);
});
- var A = asn1.define('A', function() {
+ const A = asn1.define('A', function() {
this.seq().obj(
this.key('test1').seqof(B),
this.key('test2').optional().seqof(B)
);
});
- var out = A.decode(new Buffer(
+ let out = A.decode(new Buffer(
'3018300A30030201013003020102300A30030201033003020104', 'hex'), 'der');
assert.equal(out.test1[0].num.toString(10), 1);
assert.equal(out.test1[1].num.toString(10), 2);
@@ -155,13 +155,13 @@ describe('asn1.js DER decoder', function() {
});
it('should not require decoder param', function() {
- var M = asn1.define('Model', function() {
+ const M = asn1.define('Model', function() {
this.choice({
apple: this.bool(),
});
});
// Note no decoder specified, defaults to 'der'
- var decoded = M.decode(new Buffer('0101ff', 'hex'));
+ const decoded = M.decode(new Buffer('0101ff', 'hex'));
assert.deepEqual(decoded, { 'type': 'apple', 'value': true });
});
});
diff --git a/test/der-encode-test.js b/test/der-encode-test.js
index 9130d50..b94174c 100644
--- a/test/der-encode-test.js
+++ b/test/der-encode-test.js
@@ -1,11 +1,11 @@
'use strict';
/* global describe it */
-var assert = require('assert');
-var asn1 = require('..');
-var BN = require('bn.js');
+const assert = require('assert');
+const asn1 = require('..');
+const BN = require('bn.js');
-var Buffer = require('buffer').Buffer;
+const Buffer = require('buffer').Buffer;
describe('asn1.js DER encoder', function() {
/*
@@ -13,11 +13,11 @@ describe('asn1.js DER encoder', function() {
* this adds two more bytes to resulting buffer.
* */
it('should code explicit tag as 0xA2', function() {
- var E = asn1.define('E', function() {
+ const E = asn1.define('E', function() {
this.explicit(2).octstr()
});
- var encoded = E.encode('X', 'der');
+ const encoded = E.encode('X', 'der');
// <Explicit tag> <wrapped len> <str tag> <len> <payload>
assert.equal(encoded.toString('hex'), 'a203040158');
@@ -26,10 +26,10 @@ describe('asn1.js DER encoder', function() {
function test(name, model_definition, model_value, der_expected) {
it(name, function() {
- var Model, der_actual;
+ let Model, derActual;
Model = asn1.define('Model', model_definition);
- der_actual = Model.encode(model_value, 'der');
- assert.deepEqual(der_actual, new Buffer(der_expected,'hex'));
+ derActual = Model.encode(model_value, 'der');
+ assert.deepEqual(derActual, new Buffer(der_expected,'hex'));
});
}
@@ -44,14 +44,14 @@ describe('asn1.js DER encoder', function() {
}, { type: 'apple', value: true }, '0101ff');
test('should encode implicit seqof', function() {
- var Int = asn1.define('Int', function() {
+ const Int = asn1.define('Int', function() {
this.int();
});
this.implicit(0).seqof(Int);
}, [ 1 ], 'A003020101' );
test('should encode explicit seqof', function() {
- var Int = asn1.define('Int', function() {
+ const Int = asn1.define('Int', function() {
this.int();
});
this.explicit(0).seqof(Int);
@@ -77,15 +77,15 @@ describe('asn1.js DER encoder', function() {
}, {required: false, value: 1}, '3003020101');
it('should encode optional and use', function() {
- var B = asn1.define('B', function() {
+ const B = asn1.define('B', function() {
this.int();
});
- var A = asn1.define('A', function() {
+ const A = asn1.define('A', function() {
this.optional().use(B);
});
- var out = A.encode(1, 'der');
+ const out = A.encode(1, 'der');
assert.equal(out.toString('hex'), '020101');
});
@@ -109,16 +109,16 @@ describe('asn1.js DER encoder', function() {
}, 'Привет', '1e0c041f04400438043204350442');
it('should encode encapsulated models', function() {
- var B = asn1.define('B', function() {
+ const B = asn1.define('B', function() {
this.seq().obj(
this.key('nested').int()
);
});
- var A = asn1.define('A', function() {
+ const A = asn1.define('A', function() {
this.octstr().contains(B);
});
- var out = A.encode({ nested: 5 }, 'der')
+ const out = A.encode({ nested: 5 }, 'der')
assert.equal(out.toString('hex'), '04053003020105');
});
@@ -139,13 +139,13 @@ describe('asn1.js DER encoder', function() {
}, 'septic tank', '1A0B7365707469632074616E6B');
it('should not require encoder param', function() {
- var M = asn1.define('Model', function() {
+ const M = asn1.define('Model', function() {
this.choice({
apple: this.bool(),
});
});
// Note no encoder specified, defaults to 'der'
- var encoded = M.encode({ 'type': 'apple', 'value': true });
+ const encoded = M.encode({ 'type': 'apple', 'value': true });
assert.deepEqual(encoded, new Buffer('0101ff', 'hex'));
});
});
diff --git a/test/error-test.js b/test/error-test.js
index 2584478..eb6bc22 100644
--- a/test/error-test.js
+++ b/test/error-test.js
@@ -1,24 +1,24 @@
'use strict';
/* global describe it */
-var assert = require('assert');
-var asn1 = require('..');
-var bn = asn1.bignum;
-var fixtures = require('./fixtures');
-var jsonEqual = fixtures.jsonEqual;
+const assert = require('assert');
+const asn1 = require('..');
+const bn = asn1.bignum;
+const fixtures = require('./fixtures');
+const jsonEqual = fixtures.jsonEqual;
-var Buffer = require('buffer').Buffer;
+const Buffer = require('buffer').Buffer;
describe('asn1.js error', function() {
describe('encoder', function() {
function test(name, model, input, expected) {
it('should support ' + name, function() {
- var M = asn1.define('TestModel', model);
+ const M = asn1.define('TestModel', model);
- var error;
+ let error;
assert.throws(function() {
try {
- var encoded = M.encode(input, 'der');
+ const encoded = M.encode(input, 'der');
} catch (e) {
error = e;
throw e;
@@ -81,7 +81,7 @@ describe('asn1.js error', function() {
}, { a: { b: { c: 'hello' } } } , /map at: \["a"\]\["b"\]\["c"\]/i);
test('use', function() {
- var S = asn1.define('S', function() {
+ const S = asn1.define('S', function() {
this.seq().obj(
this.key('x').int()
);
@@ -99,18 +99,18 @@ describe('asn1.js error', function() {
describe('decoder', function() {
function test(name, model, input, expected) {
it('should support ' + name, function() {
- var M = asn1.define('TestModel', model);
+ const M = asn1.define('TestModel', model);
- var error;
+ let error;
assert.throws(function() {
try {
- var decoded = M.decode(new Buffer(input, 'hex'), 'der');
+ const decoded = M.decode(new Buffer(input, 'hex'), 'der');
} catch (e) {
error = e;
throw e;
}
});
- var partial = M.decode(new Buffer(input, 'hex'), 'der', {
+ const partial = M.decode(new Buffer(input, 'hex'), 'der', {
partial: true
});
@@ -179,9 +179,9 @@ describe('asn1.js error', function() {
describe('partial decoder', function() {
function test(name, model, input, expectedObj, expectedErrs) {
it('should support ' + name, function() {
- var M = asn1.define('TestModel', model);
+ const M = asn1.define('TestModel', model);
- var decoded = M.decode(new Buffer(input, 'hex'), 'der', {
+ const decoded = M.decode(new Buffer(input, 'hex'), 'der', {
partial: true
});
diff --git a/test/fixtures.js b/test/fixtures.js
index ea3a024..a01571b 100644
--- a/test/fixtures.js
+++ b/test/fixtures.js
@@ -1,7 +1,7 @@
'use strict';
/* global describe it */
-var assert = require('assert');
+const assert = require('assert');
function jsonEqual(a, b) {
assert.deepEqual(JSON.parse(JSON.stringify(a)),
diff --git a/test/pem-test.js b/test/pem-test.js
index f98ae40..4bbec9b 100644
--- a/test/pem-test.js
+++ b/test/pem-test.js
@@ -1,14 +1,14 @@
'use strict';
/* global describe it */
-var assert = require('assert');
-var asn1 = require('..');
-var BN = require('bn.js');
+const assert = require('assert');
+const asn1 = require('..');
+const BN = require('bn.js');
-var Buffer = require('buffer').Buffer;
+const Buffer = require('buffer').Buffer;
describe('asn1.js PEM encoder/decoder', function() {
- var model = asn1.define('Model', function() {
+ const model = asn1.define('Model', function() {
this.seq().obj(
this.key('a').int(),
this.key('b').bitstr(),
@@ -16,12 +16,12 @@ describe('asn1.js PEM encoder/decoder', function() {
);
});
- var hundred = new Buffer(100);
+ const hundred = new Buffer(100);
hundred.fill('A');
it('should encode PEM', function() {
- var out = model.encode({
+ const out = model.encode({
a: new BN(123),
b: {
data: hundred,
@@ -32,7 +32,7 @@ describe('asn1.js PEM encoder/decoder', function() {
label: 'MODEL'
});
- var expected =
+ const expected =
'-----BEGIN MODEL-----\n' +
'MG4CAXsDZQBBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFB\n' +
'QUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFB\n' +
@@ -42,14 +42,14 @@ describe('asn1.js PEM encoder/decoder', function() {
});
it('should decode PEM', function() {
- var expected =
+ const expected =
'-----BEGIN MODEL-----\n' +
'MG4CAXsDZQBBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFB\n' +
'QUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFB\n' +
'QUFBQUFBQUFBQUFBAgIByA==\n' +
'-----END MODEL-----';
- var out = model.decode(expected, 'pem', { label: 'MODEL' });
+ const out = model.decode(expected, 'pem', { label: 'MODEL' });
assert.equal(out.a.toString(), '123');
assert.equal(out.b.data.toString(), hundred.toString());
assert.equal(out.c.toString(), '456');
diff --git a/test/ping-pong-test.js b/test/ping-pong-test.js
index 2ee66fc..8e727d6 100644
--- a/test/ping-pong-test.js
+++ b/test/ping-pong-test.js
@@ -1,20 +1,20 @@
'use strict';
/* global describe it */
-var assert = require('assert');
-var asn1 = require('..');
-var fixtures = require('./fixtures');
-var jsonEqual = fixtures.jsonEqual;
+const assert = require('assert');
+const asn1 = require('..');
+const fixtures = require('./fixtures');
+const jsonEqual = fixtures.jsonEqual;
-var Buffer = require('buffer').Buffer;
+const Buffer = require('buffer').Buffer;
describe('asn1.js ping/pong', function() {
function test(name, model, input, expected) {
it('should support ' + name, function() {
- var M = asn1.define('TestModel', model);
+ const M = asn1.define('TestModel', model);
- var encoded = M.encode(input, 'der');
- var decoded = M.decode(encoded, 'der');
+ const encoded = M.encode(input, 'der');
+ const decoded = M.decode(encoded, 'der');
jsonEqual(decoded, expected !== undefined ? expected : input);
});
}
@@ -159,7 +159,7 @@ describe('asn1.js ping/pong', function() {
}, { content: new Buffer('0500', 'hex') });
test('seqof', function() {
- var S = asn1.define('S', function() {
+ const S = asn1.define('S', function() {
this.seq().obj(
this.key('a').def('b').int({ 0: 'a', 1: 'b' }),
this.key('c').def('d').int({ 2: 'c', 3: 'd' })
diff --git a/test/tracking-test.js b/test/tracking-test.js
index 0d693f1..eab0d97 100644
--- a/test/tracking-test.js
+++ b/test/tracking-test.js
@@ -1,36 +1,36 @@
'use strict';
/* global describe it */
-var assert = require('assert');
-var asn1 = require('..');
-var fixtures = require('./fixtures');
-var jsonEqual = fixtures.jsonEqual;
+const assert = require('assert');
+const asn1 = require('..');
+const fixtures = require('./fixtures');
+const jsonEqual = fixtures.jsonEqual;
describe('asn1.js tracking', function() {
it('should track nested offsets', () => {
- var B = asn1.define('B', function() {
+ const B = asn1.define('B', function() {
this.seq().obj(
this.key('x').int(),
this.key('y').int()
);
});
- var A = asn1.define('A', function() {
+ const A = asn1.define('A', function() {
this.seq().obj(
this.key('a').explicit(0).use(B),
this.key('b').use(B)
);
});
- var input = {
+ const input = {
a: { x: 1, y: 2 },
b: { x: 3, y: 4 }
};
- var tracked = [];
+ const tracked = [];
- var encoded = A.encode(input, 'der');
- var decoded = A.decode(encoded, 'der', {
+ const encoded = A.encode(input, 'der');
+ const decoded = A.decode(encoded, 'der', {
track: function(path, start, end, type) {
tracked.push([ type, path, start, end ]);
}
diff --git a/test/use-test.js b/test/use-test.js
index 35f3283..03bab57 100644
--- a/test/use-test.js
+++ b/test/use-test.js
@@ -1,84 +1,84 @@
'use strict';
/* global describe it */
-var assert = require('assert');
-var asn1 = require('..');
-var bn = asn1.bignum;
-var fixtures = require('./fixtures');
-var jsonEqual = fixtures.jsonEqual;
+const assert = require('assert');
+const asn1 = require('..');
+const bn = asn1.bignum;
+const fixtures = require('./fixtures');
+const jsonEqual = fixtures.jsonEqual;
-var Buffer = require('buffer').Buffer;
+const Buffer = require('buffer').Buffer;
describe('asn1.js models', function() {
describe('plain use', function() {
it('should encode submodel', function() {
- var SubModel = asn1.define('SubModel', function() {
+ const SubModel = asn1.define('SubModel', function() {
this.seq().obj(
this.key('b').octstr()
);
});
- var Model = asn1.define('Model', function() {
+ const Model = asn1.define('Model', function() {
this.seq().obj(
this.key('a').int(),
this.key('sub').use(SubModel)
);
});
- var data = {a: new bn(1), sub: {b: new Buffer("XXX")}};
- var wire = Model.encode(data, 'der');
+ const data = {a: new bn(1), sub: {b: new Buffer("XXX")}};
+ const wire = Model.encode(data, 'der');
assert.equal(wire.toString('hex'), '300a02010130050403585858');
- var back = Model.decode(wire, 'der');
+ const back = Model.decode(wire, 'der');
jsonEqual(back, data);
});
it('should honour implicit tag from parent', function() {
- var SubModel = asn1.define('SubModel', function() {
+ const SubModel = asn1.define('SubModel', function() {
this.seq().obj(
this.key('x').octstr()
)
});
- var Model = asn1.define('Model', function() {
+ const Model = asn1.define('Model', function() {
this.seq().obj(
this.key('a').int(),
this.key('sub').use(SubModel).implicit(0)
);
});
- var data = {a: new bn(1), sub: {x: new Buffer("123")}};
- var wire = Model.encode(data, 'der');
+ const data = {a: new bn(1), sub: {x: new Buffer("123")}};
+ const wire = Model.encode(data, 'der');
assert.equal(wire.toString('hex'), '300a020101a0050403313233');
- var back = Model.decode(wire, 'der');
+ const back = Model.decode(wire, 'der');
jsonEqual(back, data);
});
it('should honour explicit tag from parent', function() {
- var SubModel = asn1.define('SubModel', function() {
+ const SubModel = asn1.define('SubModel', function() {
this.seq().obj(
this.key('x').octstr()
)
});
- var Model = asn1.define('Model', function() {
+ const Model = asn1.define('Model', function() {
this.seq().obj(
this.key('a').int(),
this.key('sub').use(SubModel).explicit(0)
);
});
- var data = {a: new bn(1), sub: {x: new Buffer("123")}};
- var wire = Model.encode(data, 'der');
+ const data = {a: new bn(1), sub: {x: new Buffer("123")}};
+ const wire = Model.encode(data, 'der');
assert.equal(wire.toString('hex'), '300c020101a00730050403313233');
- var back = Model.decode(wire, 'der');
+ const back = Model.decode(wire, 'der');
jsonEqual(back, data);
});
it('should get model with function call', function() {
- var SubModel = asn1.define('SubModel', function() {
+ const SubModel = asn1.define('SubModel', function() {
this.seq().obj(
this.key('x').octstr()
)
});
- var Model = asn1.define('Model', function() {
+ const Model = asn1.define('Model', function() {
this.seq().obj(
this.key('a').int(),
this.key('sub').use(function(obj) {
@@ -88,19 +88,19 @@ describe('asn1.js models', function() {
);
});
- var data = {a: new bn(1), sub: {x: new Buffer("123")}};
- var wire = Model.encode(data, 'der');
+ const data = {a: new bn(1), sub: {x: new Buffer("123")}};
+ const wire = Model.encode(data, 'der');
assert.equal(wire.toString('hex'), '300a02010130050403313233');
- var back = Model.decode(wire, 'der');
+ const back = Model.decode(wire, 'der');
jsonEqual(back, data);
});
it('should support recursive submodels', function() {
- var PlainSubModel = asn1.define('PlainSubModel', function() {
+ const PlainSubModel = asn1.define('PlainSubModel', function() {
this.int();
});
- var RecursiveModel = asn1.define('RecursiveModel', function() {
+ const RecursiveModel = asn1.define('RecursiveModel', function() {
this.seq().obj(
this.key('plain').bool(),
this.key('content').use(function(obj) {
@@ -113,16 +113,16 @@ describe('asn1.js models', function() {
);
});
- var data = {
+ const data = {
'plain': false,
'content': {
'plain': true,
'content': new bn(1)
}
};
- var wire = RecursiveModel.encode(data, 'der');
+ const wire = RecursiveModel.encode(data, 'der');
assert.equal(wire.toString('hex'), '300b01010030060101ff020101');
- var back = RecursiveModel.decode(wire, 'der');
+ const back = RecursiveModel.decode(wire, 'der');
jsonEqual(back, data);
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-asn1.js.git
More information about the Pkg-javascript-commits
mailing list