-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
140 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@cross/kv", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"exports": { | ||
".": "./mod.ts" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { assertEquals, assertThrows } from "@std/assert"; | ||
import { test } from "@cross/test"; | ||
import { KVKey /* ... */ } from "./key.ts"; | ||
|
||
test("KVKey: constructs with valid string key", () => { | ||
const key = new KVKey(["users", "user123"]); | ||
assertEquals(key.get(), ["users", "user123"]); | ||
}); | ||
|
||
test("KVKey: throws with invalid string key (colon)", () => { | ||
assertThrows( | ||
() => new KVKey(["users", ":lol"]), | ||
TypeError, | ||
"String elements in the key can only contain", | ||
); | ||
}); | ||
|
||
test("KVKey: throws with invalid string key (space)", () => { | ||
assertThrows( | ||
() => new KVKey(["users", "l ol"]), | ||
TypeError, | ||
"String elements in the key can only contain", | ||
); | ||
}); | ||
|
||
test("KVKey: constructs with valid number key", () => { | ||
const key = new KVKey(["data", 42]); | ||
assertEquals(key.get(), ["data", 42]); | ||
}); | ||
|
||
test("KVKey: returns correct string representation", () => { | ||
const key = new KVKey(["users", "data", "user123"]); | ||
assertEquals(key.getKeyRepresentation(), "users.data.user123"); | ||
}); | ||
|
||
test("KVKey: constructs with valid range", async () => { | ||
const key = new KVKey(["users", { from: "user001", to: "user999" }], true); | ||
assertEquals(key.get(), ["users", { from: "user001", to: "user999" }]); | ||
}); | ||
|
||
test("KVKey: constructs with valid range (only from)", () => { | ||
const key = new KVKey(["users", { from: "user001" }], true); | ||
assertEquals(key.get(), ["users", { from: "user001" }]); | ||
}); | ||
|
||
test("KVKey: constructs with valid range (only to)", () => { | ||
const key = new KVKey(["users", { to: "user001" }], true); | ||
assertEquals(key.get(), ["users", { to: "user001" }]); | ||
}); | ||
|
||
test("KVKey: constructs with valid range (all)", () => { | ||
const key = new KVKey(["users", {}], true); | ||
assertEquals(key.get(), ["users", {}]); | ||
}); | ||
|
||
test("KVKey: constructs with invalid range (extra property)", () => { | ||
assertThrows( | ||
// @ts-expect-error test unknown property | ||
() => new KVKey(["users", { test: 1 }], true), | ||
TypeError, | ||
"Ranges must have only", | ||
); | ||
}); | ||
|
||
test("KVKey: throws on empty key", () => { | ||
assertThrows(() => new KVKey([]), TypeError, "Key cannot be empty"); | ||
}); | ||
|
||
test("KVKey: only allows string keys as first entry", () => { | ||
assertThrows( | ||
() => new KVKey([123121]), | ||
TypeError, | ||
"First index of the key must be a string", | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters