Skip to content

Commit

Permalink
remove should dependency
Browse files Browse the repository at this point in the history
standard assert generates better error messages
  • Loading branch information
pirxpilot committed Apr 18, 2024
1 parent fe49a9d commit e5f49b4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ lint:
./node_modules/.bin/jshint *.js lib test

test:
node --require should --test
node --test

.PHONY: check lint test
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"uuid": "~9"
},
"devDependencies": {
"@pirxpilot/jshint": "~3",
"should": "~13"
"@pirxpilot/jshint": "~3"
},
"scripts": {
"test": "make check"
Expand Down
7 changes: 4 additions & 3 deletions test/ical.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { describe, it } = require('node:test');
const assert = require('node:assert/strict');
const ical = require('../');

const fs = require('fs');
Expand All @@ -21,16 +22,16 @@ function compareLines(actual, expected) {

actual = Array.from(actual).map(x => decoder.decode(x)).join('');

actual.should.endWith('\r\n');
assert(actual.endsWith('\r\n'), `${actual.slice(-10)} should end with \\r\\n`);

actual = actual.split('\r\n').filter(notStamp);
expected = expected.split('\r\n').filter(notStamp);

for (let i = 0; i < actual.length; i += 1) {
actual[i].should.eql(expected[i], `line: ${i}`);
assert.equal(actual[i], expected[i], `line: ${i}`);
}

actual.should.have.length(expected.length);
assert.equal(actual.length, expected.length, 'line count');
}


Expand Down
51 changes: 25 additions & 26 deletions test/property.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { describe, it } = require('node:test');
const assert = require('node:assert/strict');
const property = require('../lib/property');

/* global TextDecoder */
Expand All @@ -11,61 +12,59 @@ describe('property', function () {

const { value, done } = p.next();

done.should.equal(false);
decoder.decode(value).should.equal('abc:ąbć\r\n');

p.next().done.should.equal(true);
assert.equal(done, false, 'done should be false');
assert.equal(decoder.decode(value), 'abc:ąbć\r\n');
assert.deepEqual(p.next(), { value: undefined, done: true }, 'no more values');
});

it('long', function () {
const p = property('A', 'a'.repeat(100));

const values = Array.from(p);

values.should.have.length(2);
assert.equal(values.length, 2, 'values should have length 2');
// 75 octets + \r\n
values[0].should.have.length(75 + 2);

assert.equal(values[0].length, 75 + 2);
const strings = values.map(v => decoder.decode(v));
strings[0].should.equal(`A:${'a'.repeat(73)}\r\n`);
strings[1].should.equal(` ${'a'.repeat(27)}\r\n`);
assert.equal(strings[0], `A:${'a'.repeat(73)}\r\n`);
assert.equal(strings[1], ` ${'a'.repeat(27)}\r\n`);
});

it('very long', function () {
const p = property('A', 'a'.repeat(300));

const strings = Array.from(p).map(s => decoder.decode(s));

strings.should.have.length(5);
strings[0].should.equal(`A:${'a'.repeat(73)}\r\n`);
strings[1].should.equal(` ${'a'.repeat(74)}\r\n`);
strings[2].should.equal(` ${'a'.repeat(74)}\r\n`);
strings[3].should.equal(` ${'a'.repeat(74)}\r\n`);
strings[4].should.equal(` ${'a'.repeat(5)}\r\n`);
assert.equal(strings.length, 5, 'strings should have length 5');
assert.equal(strings[0], `A:${'a'.repeat(73)}\r\n`);
assert.equal(strings[1], ` ${'a'.repeat(74)}\r\n`);
assert.equal(strings[2], ` ${'a'.repeat(74)}\r\n`);
assert.equal(strings[3], ` ${'a'.repeat(74)}\r\n`);
assert.equal(strings[4], ` ${'a'.repeat(5)}\r\n`);
});

it('long with multibyte', function () {
const p = property('A', 'ą'.repeat(100));

const strings = Array.from(p).map(s => decoder.decode(s));

strings.should.have.length(3);
strings[0].should.equal(`A:${'ą'.repeat(36)}\r\n`);
strings[1].should.equal(` ${'ą'.repeat(37)}\r\n`);
strings[2].should.equal(` ${'ą'.repeat(100 - 37 - 36)}\r\n`);
assert.equal(strings.length, 3, 'strings should have length 3');
assert.equal(strings[0], `A:${'ą'.repeat(36)}\r\n`);
assert.equal(strings[1], ` ${'ą'.repeat(37)}\r\n`);
assert.equal(strings[2], ` ${'ą'.repeat(100 - 37 - 36)}\r\n`);
});

it('long with emoji', function () {
const p = property('A', '🌻'.repeat(100));

const strings = Array.from(p).map(s => decoder.decode(s));

strings.should.have.length(6);
strings[0].should.equal(`A:${'🌻'.repeat(18)}\r\n`);
strings[1].should.equal(` ${'🌻'.repeat(18)}\r\n`);
strings[2].should.equal(` ${'🌻'.repeat(18)}\r\n`);
strings[3].should.equal(` ${'🌻'.repeat(18)}\r\n`);
strings[4].should.equal(` ${'🌻'.repeat(18)}\r\n`);
strings[5].should.equal(` ${'🌻'.repeat(100 - 5 * 18)}\r\n`);
assert.equal(strings.length, 6, 'strings should have length 6');
assert.equal(strings[0], `A:${'🌻'.repeat(18)}\r\n`);
assert.equal(strings[1], ` ${'🌻'.repeat(18)}\r\n`);
assert.equal(strings[2], ` ${'🌻'.repeat(18)}\r\n`);
assert.equal(strings[3], ` ${'🌻'.repeat(18)}\r\n`);
assert.equal(strings[4], ` ${'🌻'.repeat(18)}\r\n`);
assert.equal(strings[5], ` ${'🌻'.repeat(100 - 5 * 18)}\r\n`);
});
});

0 comments on commit e5f49b4

Please sign in to comment.