Skip to content

Commit

Permalink
applied deno fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
seriousme committed Oct 22, 2024
1 parent a469799 commit c2794f1
Show file tree
Hide file tree
Showing 19 changed files with 102 additions and 41 deletions.
1 change: 0 additions & 1 deletion deno/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import assert from "node:assert/strict";
import { test } from "node:test";
import { TcpServer } from "./server.ts";


test("testServer", () => {
const server = new TcpServer({ port: 0 }, {});
server.start();
Expand Down
7 changes: 5 additions & 2 deletions mqttPacket/connect.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PacketType } from "./PacketType.ts";
import assert from "node:assert/strict";
import { test } from "node:test";
;

import { type ConnectPacket, decode, encode } from "./mod.ts";

test("encode Connect with ClientId", () => {
Expand Down Expand Up @@ -171,7 +171,10 @@ test("encode Connect with username and password", () => {
});

test("decode Connect with username and password", () => {
assert.deepStrictEqual(decode(Uint8Array.from(encodedConnect)), decodedConnect);
assert.deepStrictEqual(
decode(Uint8Array.from(encodedConnect)),
decodedConnect,
);
});

const decodedConnectWithWill = Object.assign({}, decodedConnect);
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/decoder.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from "node:assert/strict";
import { test } from "node:test";
;

import { Decoder } from "./decoder.ts";

const utf8encoder = new TextEncoder();
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/disconnect.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PacketType } from "./PacketType.ts";
import assert from "node:assert/strict";
import { test } from "node:test";
;

import { decode, encode } from "./mod.ts";

test("encode Disconnect", () => {
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/length.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from "node:assert/strict";
import { test } from "node:test";
;

import { decodeLength as decode, encodeLength as encode } from "./length.ts";

test("encodeLength", function encodeLength() {
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/pingreq.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PacketType } from "./PacketType.ts";
import assert from "node:assert/strict";
import { test } from "node:test";
;

import { decode, encode } from "./mod.ts";

test("encode Pingreq", () => {
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/pingres.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PacketType } from "./PacketType.ts";
import assert from "node:assert/strict";
import { test } from "node:test";
;

import { decode, encode } from "./mod.ts";

test("encode Pingres", () => {
Expand Down
8 changes: 6 additions & 2 deletions mqttPacket/puback.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PacketType } from "./PacketType.ts";
import assert from "node:assert/strict";
import { test } from "node:test";
;

import { decode, encode } from "./mod.ts";

test("encode Puback", () => {
Expand Down Expand Up @@ -41,7 +41,11 @@ test("decode Puback ", () => {
});

test("decodeShortPubackPackets", () => {
assert.throws(() => decode(Uint8Array.from([0x40])), Error, "decoding failed");
assert.throws(
() => decode(Uint8Array.from([0x40])),
Error,
"decoding failed",
);
assert.throws(() => decode(Uint8Array.from([0x40, 2])), Error, "too short");
assert.throws(
() => decode(Uint8Array.from([0x40, 3, 0, 0, 0])),
Expand Down
8 changes: 6 additions & 2 deletions mqttPacket/pubcomp.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PacketType } from "./PacketType.ts";
import assert from "node:assert/strict";
import { test } from "node:test";
;

import { decode, encode } from "./mod.ts";

test("encode Pubcomp", () => {
Expand Down Expand Up @@ -41,7 +41,11 @@ test("decode Pubcomp ", () => {
});

test("decodeShortPubcompPackets", () => {
assert.throws(() => decode(Uint8Array.from([0x70])), Error, "decoding failed");
assert.throws(
() => decode(Uint8Array.from([0x70])),
Error,
"decoding failed",
);
assert.throws(() => decode(Uint8Array.from([0x70, 2])), Error, "too short");
assert.throws(
() => decode(Uint8Array.from([0x70, 3, 0, 0, 0])),
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/publish.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PacketType } from "./PacketType.ts";
import assert from "node:assert/strict";
import { test } from "node:test";
;

import { decode, encode } from "./mod.ts";

// const utf8Decoder = new TextDecoder();
Expand Down
8 changes: 6 additions & 2 deletions mqttPacket/pubrec.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PacketType } from "./PacketType.ts";
import assert from "node:assert/strict";
import { test } from "node:test";
;

import { decode, encode } from "./mod.ts";

test("encode Pubrec", () => {
Expand Down Expand Up @@ -41,7 +41,11 @@ test("decode Pubrec ", () => {
});

test("decodeShortPubrecPackets", () => {
assert.throws(() => decode(Uint8Array.from([0x50])), Error, "decoding failed");
assert.throws(
() => decode(Uint8Array.from([0x50])),
Error,
"decoding failed",
);
assert.throws(() => decode(Uint8Array.from([0x50, 2])), Error, "too short");
assert.throws(
() => decode(Uint8Array.from([0x50, 3, 0, 0, 0])),
Expand Down
8 changes: 6 additions & 2 deletions mqttPacket/pubrel.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PacketType } from "./PacketType.ts";
import assert from "node:assert/strict";
import { test } from "node:test";
;

import { decode, encode } from "./mod.ts";

test("encode Pubrel", () => {
Expand Down Expand Up @@ -41,7 +41,11 @@ test("decode Pubrel ", () => {
});

test("decodeShortPubrelPackets", () => {
assert.throws(() => decode(Uint8Array.from([0x60])), Error, "decoding failed");
assert.throws(
() => decode(Uint8Array.from([0x60])),
Error,
"decoding failed",
);
assert.throws(() => decode(Uint8Array.from([0x60, 2])), Error, "too short");
assert.throws(
() => decode(Uint8Array.from([0x60, 3, 0, 0, 0])),
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/subscribe.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PacketType } from "./PacketType.ts";
import assert from "node:assert/strict";
import { test } from "node:test";
;

import { decode, encode } from "./mod.ts";

test("encode Subscribe", () => {
Expand Down
8 changes: 6 additions & 2 deletions mqttPacket/unsuback.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PacketType } from "./PacketType.ts";
import assert from "node:assert/strict";
import { test } from "node:test";
;

import { decode, encode } from "./mod.ts";

test("encode Puback", () => {
Expand Down Expand Up @@ -41,7 +41,11 @@ test("decode Puback ", () => {
});

test("decodeShortPubackPackets", () => {
assert.throws(() => decode(Uint8Array.from([0xb0])), Error, "decoding failed");
assert.throws(
() => decode(Uint8Array.from([0xb0])),
Error,
"decoding failed",
);
assert.throws(() => decode(Uint8Array.from([0xb0, 2])), Error, "too short");
assert.throws(
() => decode(Uint8Array.from([0xb0, 3, 0, 0, 0])),
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/unsubscribe.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PacketType } from "./PacketType.ts";
import assert from "node:assert/strict";
import { test } from "node:test";
;

import { decode, encode } from "./mod.ts";

test("encode Unsubscribe", () => {
Expand Down
18 changes: 15 additions & 3 deletions persistence/memory/memoryPersistence.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ test("many packets should work", async () => {
const seen = new Set();

function handler(packet: PublishPacket): void {
assert.deepStrictEqual(seen.has(packet.id), false, `Not seen ${packet.id} before`);
assert.deepStrictEqual(
seen.has(packet.id),
false,
`Not seen ${packet.id} before`,
);
seen.add(packet.id);
}

Expand All @@ -105,7 +109,11 @@ test("many packets should work", async () => {
persistence.publish(topic, makePacket(i));
}
await delay(10);
assert.deepStrictEqual(seen.size, numMessages, `received all ${numMessages} messages`);
assert.deepStrictEqual(
seen.size,
numMessages,
`received all ${numMessages} messages`,
);
});

test("unsubscribe should work", () => {
Expand All @@ -121,7 +129,11 @@ test("unsubscribe should work", () => {

const seen = new Set();
function handler(packet: PublishPacket): void {
assert.deepStrictEqual(seen.has(packet.id), false, `Not seen ${packet.id} before`);
assert.deepStrictEqual(
seen.has(packet.id),
false,
`Not seen ${packet.id} before`,
);
seen.add(packet.id);
}

Expand Down
42 changes: 35 additions & 7 deletions server/test/handleConnect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,25 @@ test("Authentication with valid username and password works", async () => {
const { reader, mqttConn } = startServer();
mqttConn.send(connectPacket);
const { value: connack } = await reader.next();
assert.deepStrictEqual(connack.type, PacketType.connack, "Expect Connack packet");
assert.deepStrictEqual(
connack.type,
PacketType.connack,
"Expect Connack packet",
);
if (connack.type === PacketType.connack) {
assert.deepStrictEqual(connack.returnCode, AuthenticationResult.ok, "Expected OK");
assert.deepStrictEqual(
connack.returnCode,
AuthenticationResult.ok,
"Expected OK",
);
}
mqttConn.send(disconnectPacket);
await nextTick();
assert.deepStrictEqual(mqttConn.isClosed, true, "Expected connection to be closed");
assert.deepStrictEqual(
mqttConn.isClosed,
true,
"Expected connection to be closed",
);
});

test("Authentication with invalid username fails", async () => {
Expand All @@ -67,7 +79,11 @@ test("Authentication with invalid username fails", async () => {
const { reader, mqttConn } = startServer();
mqttConn.send(newPacket);
const { value: connack } = await reader.next();
assert.deepStrictEqual(connack.type, PacketType.connack, "Expected Connack packet");
assert.deepStrictEqual(
connack.type,
PacketType.connack,
"Expected Connack packet",
);
if (connack.type === PacketType.connack) {
assert.deepStrictEqual(
connack.returnCode,
Expand All @@ -76,7 +92,11 @@ test("Authentication with invalid username fails", async () => {
);
}
await nextTick();
assert.deepStrictEqual(mqttConn.isClosed, true, "Expected connection to be closed");
assert.deepStrictEqual(
mqttConn.isClosed,
true,
"Expected connection to be closed",
);
});

test("Authentication with invalid password fails", async () => {
Expand All @@ -85,7 +105,11 @@ test("Authentication with invalid password fails", async () => {
const { reader, mqttConn } = startServer();
mqttConn.send(newPacket);
const { value: connack } = await reader.next();
assert.deepStrictEqual(connack.type, PacketType.connack, "Expected Connack packet");
assert.deepStrictEqual(
connack.type,
PacketType.connack,
"Expected Connack packet",
);
if (connack.type === PacketType.connack) {
assert.deepStrictEqual(
connack.returnCode,
Expand All @@ -94,5 +118,9 @@ test("Authentication with invalid password fails", async () => {
);
}
await nextTick();
assert.deepStrictEqual(mqttConn.isClosed, true, "Expected connection to be closed");
assert.deepStrictEqual(
mqttConn.isClosed,
true,
"Expected connection to be closed",
);
});
1 change: 0 additions & 1 deletion timer/timer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Timer } from "./timer.ts";
import assert from "node:assert/strict";
import { test } from "node:test";


function delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
Expand Down
18 changes: 9 additions & 9 deletions trie/trie.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { Trie } from "./trie.ts";

type Data = Array<[string, number]>;
type Matches = Array<[string, number[]]>;
type MatchResult = Array<number|object>;

const includesAll = (arr:MatchResult, values:MatchResult) => values.every(v => arr.includes(v));
type MatchResult = Array<number | object>;

const includesAll = (arr: MatchResult, values: MatchResult) =>
values.every((v) => arr.includes(v));

function doTest(data: Data, matches: Matches) {
const root = new Trie<number>();
Expand All @@ -16,7 +16,7 @@ function doTest(data: Data, matches: Matches) {
}

for (const [match, result] of matches) {
assert.ok(includesAll(root.match(match),result), `${match} found`)
assert.ok(includesAll(root.match(match), result), `${match} found`);
}
}

Expand Down Expand Up @@ -123,9 +123,9 @@ test("Removal works", () => {
const root = new Trie<number>();
root.add("foo/bar", 1);
root.add("foo/bar", 2);
assert.ok(includesAll(root.match("foo/bar"), [1, 2]), 'two items found');
assert.ok(includesAll(root.match("foo/bar"), [1, 2]), "two items found");
root.remove("foo/bar", 2);
assert.ok(includesAll(root.match("foo/bar"), [1]), 'one item found');
assert.ok(includesAll(root.match("foo/bar"), [1]), "one item found");
root.remove("foo/bar", 1);
assert.deepStrictEqual(root.match("foo/bar").length, 0, "no items left");
});
Expand All @@ -138,10 +138,10 @@ test("Removal of object values works", () => {
const c2: ComplexValue = { a: 2, b: 4, c: 6 };
root.add("foo/bar", c1);
root.add("foo/bar", c2);
assert.ok(includesAll(root.match("foo/bar"), [c1, c2]), 'two items found');
assert.ok(includesAll(root.match("foo/bar"), [c1, c2]), "two items found");
root.remove("foo/bar", c2);
assert.ok(includesAll(root.match("foo/bar"), [c1]), 'one item found');
assert.ok(includesAll(root.match("foo/bar"), [c1]), "one item found");
root.remove("foo/bar", { a: 1, b: 2, c: 3 });
assert.ok(includesAll(root.match("foo/bar"), []), 'empty array');
assert.ok(includesAll(root.match("foo/bar"), []), "empty array");
assert.deepStrictEqual(root.match("foo/bar").length, 0, "matches left");
});

0 comments on commit c2794f1

Please sign in to comment.