forked from sashin/sashinexists
run npm install to generate a package lock
This commit is contained in:
46
node_modules/@weborigami/async-tree/test/drivers/FunctionTree.test.js
generated
vendored
Normal file
46
node_modules/@weborigami/async-tree/test/drivers/FunctionTree.test.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
import assert from "node:assert";
|
||||
import { describe, test } from "node:test";
|
||||
import FunctionTree from "../../src/drivers/FunctionTree.js";
|
||||
|
||||
describe("FunctionTree", async () => {
|
||||
test("can get the keys of the tree", async () => {
|
||||
const fixture = createFixture();
|
||||
assert.deepEqual(Array.from(await fixture.keys()), [
|
||||
"Alice.md",
|
||||
"Bob.md",
|
||||
"Carol.md",
|
||||
]);
|
||||
});
|
||||
|
||||
test("can get the value for a key", async () => {
|
||||
const fixture = createFixture();
|
||||
const alice = await fixture.get("Alice.md");
|
||||
assert.equal(alice, "Hello, **Alice**.");
|
||||
});
|
||||
|
||||
test("getting a value from function with multiple arguments curries the function", async () => {
|
||||
const fixture = new FunctionTree((a, b, c) => a + b + c);
|
||||
const fnA = await fixture.get(1);
|
||||
const fnAB = await fnA.get(2);
|
||||
const result = await fnAB.get(3);
|
||||
assert.equal(result, 6);
|
||||
});
|
||||
|
||||
test("getting an unsupported key returns undefined", async () => {
|
||||
const fixture = createFixture();
|
||||
assert.equal(await fixture.get("xyz"), undefined);
|
||||
});
|
||||
});
|
||||
|
||||
function createFixture() {
|
||||
return new FunctionTree(
|
||||
(key) => {
|
||||
if (key?.endsWith?.(".md")) {
|
||||
const name = key.slice(0, -3);
|
||||
return `Hello, **${name}**.`;
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
["Alice.md", "Bob.md", "Carol.md"]
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user