Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
iuioiua committed Apr 13, 2024
1 parent 1376c94 commit 0b838af
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
8 changes: 4 additions & 4 deletions x.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ export async function readReply(
return value;
case SIMPLE_ERROR_PREFIX:
throw new RedisError(value);
case BULK_ERROR_PREFIX: {
const error = await readReply(reader) as string;
throw new RedisError(error);
}
case INTEGER_PREFIX:
return Number(value);
case BULK_STRING_PREFIX:
Expand All @@ -107,6 +103,10 @@ export async function readReply(
}
case BIG_NUMBER_PREFIX:
return BigInt(value);
case BULK_ERROR_PREFIX: {
const error = await readReply(reader) as string;
throw new RedisError(error);
}
case VERBATIM_STRING_PREFIX:
return await readReply(reader);
case MAP_PREFIX: {
Expand Down
52 changes: 26 additions & 26 deletions x_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,53 @@ Deno.test("RedisLineStream", async () => {
assertEquals(result, ["hello", "world", ""]);
});

Deno.test("RedisDecoderStream simple string", async () => {
Deno.test("readReply() simple string", async () => {
await assertReplyEquals(["+OK"], "OK");
});

Deno.test("RedisDecoderStream simple error", async () => {
Deno.test("readReply() simple error", async () => {
await assertReplyRejects(["-Error message"], "Error message");
});

Deno.test("RedisDecoderStream integer", async () => {
Deno.test("readReply() integer", async () => {
await assertReplyEquals([":1000\r\n"], 1000);
});

Deno.test("RedisDecoderStream bulk string", async () => {
Deno.test("readReply() bulk string", async () => {
await assertReplyEquals(["$0", ""], "");
await assertReplyEquals(["$5", "hello"], "hello");
await assertReplyEquals(["$-1"], null);
});

Deno.test("RedisDecoderStream null", async () => {
Deno.test("readReply() array", async () => {
await assertReplyEquals(["*0"], []);
await assertReplyEquals(["*2", "$5", "hello", "$5", "world"], [
"hello",
"world",
]);
await assertReplyEquals(["*3", ":1", ":2", ":3"], [1, 2, 3]);
await assertReplyEquals(
["*5", ":1", ":2", ":3", ":4", "$5", "hello"],
[1, 2, 3, 4, "hello"],
);
});

Deno.test("readReply() null", async () => {
await assertReplyEquals(["_"], null);
});

Deno.test("RedisDecoderStream boolean", async () => {
Deno.test("readReply() boolean", async () => {
await assertReplyEquals(["#t"], true);
await assertReplyEquals(["#f"], false);
});

Deno.test("RedisDecoderStream double", async () => {
Deno.test("readReply() double", async () => {
await assertReplyEquals([",1.23"], 1.23);
await assertReplyEquals([",inf"], Infinity);
await assertReplyEquals([",-inf"], -Infinity);
});

Deno.test("RedisDecoderStream big number", async () => {
Deno.test("readReply() big number", async () => {
await assertReplyEquals(
["(3492890328409238509324850943850943825024385"],
3492890328409238509324850943850943825024385n,
Expand All @@ -81,45 +94,32 @@ Deno.test("RedisDecoderStream big number", async () => {
);
});

Deno.test("RedisDecoderStream bulk error", async () => {
Deno.test("readReply() bulk error", async () => {
await assertReplyRejects(
["!21", "SYNTAX invalid syntax"],
"SYNTAX invalid syntax",
);
});

Deno.test("RedisDecoderStream array", async () => {
await assertReplyEquals(["*0"], []);
await assertReplyEquals(["*2", "$5", "hello", "$5", "world"], [
"hello",
"world",
]);
await assertReplyEquals(["*3", ":1", ":2", ":3"], [1, 2, 3]);
await assertReplyEquals(
["*5", ":1", ":2", ":3", ":4", "$5", "hello"],
[1, 2, 3, 4, "hello"],
);
});

Deno.test("RedisDecoderStream verbatim string", async () => {
Deno.test("readReply() verbatim string", async () => {
await assertReplyEquals(["=15", "txt:Some string"], "txt:Some string");
});

Deno.test("RedisDecoderStream map", async () => {
Deno.test("readReply() map", async () => {
await assertReplyEquals(["%2", "key1", "$5", "hello", "key2", ":1"], {
key1: "hello",
key2: 1,
});
});

Deno.test("RedisDecoderStream set", async () => {
Deno.test("readReply() set", async () => {
await assertReplyEquals(
["~5", "+orange", "+apple", "#t", ":100", ":999"],
new Set(["orange", "apple", true, 100, 999]),
);
});

Deno.test("RedisDecoderStream push", async () => {
Deno.test("readReply() push", async () => {
await assertReplyEquals([">0"], []);
await assertReplyEquals([">2", "$5", "hello", "$5", "world"], [
"hello",
Expand Down

0 comments on commit 0b838af

Please sign in to comment.