-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbridge_test.mjs
More file actions
96 lines (82 loc) · 2.52 KB
/
Copy pathbridge_test.mjs
File metadata and controls
96 lines (82 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// SPDX-License-Identifier: PMPL-1.0-or-later OR PMPL-1.0-or-later
// SPDX-FileCopyrightText: 2024 Hyperpolymath
/**
* Bridge module tests - verifies input → output transformations
*/
import { test, describe } from "node:test";
import { strictEqual, deepStrictEqual } from "node:assert";
import {
defaultConfig,
transform,
transformSafe,
compose,
identity,
uppercase,
prefix,
suffix,
info,
} from "../lib/es6/src/Bridge.mjs";
describe("Bridge", () => {
describe("transform", () => {
test("adds bridge prefix to input", () => {
strictEqual(transform("hello"), "[bridge] hello");
});
test("handles empty string", () => {
strictEqual(transform(""), "[bridge] ");
});
});
describe("transformSafe", () => {
test("returns Ok for valid input", () => {
const result = transformSafe("hello");
deepStrictEqual(result, { TAG: "Ok", _0: "[bridge] hello" });
});
test("returns Error for empty input", () => {
const result = transformSafe("");
deepStrictEqual(result, { TAG: "Error", _0: "Input cannot be empty" });
});
});
describe("compose", () => {
test("composes two functions left-to-right", () => {
const prefixHello = prefix("hello-");
const suffixWorld = suffix("-world");
const composed = compose(prefixHello, suffixWorld);
strictEqual(composed("test"), "hello-test-world");
});
});
describe("identity", () => {
test("returns input unchanged", () => {
strictEqual(identity("test"), "test");
});
});
describe("uppercase", () => {
test("converts string to uppercase", () => {
strictEqual(uppercase("hello"), "HELLO");
});
});
describe("prefix", () => {
test("creates a function that adds prefix", () => {
const addPrefix = prefix("pre-");
strictEqual(addPrefix("test"), "pre-test");
});
});
describe("suffix", () => {
test("creates a function that adds suffix", () => {
const addSuffix = suffix("-suf");
strictEqual(addSuffix("test"), "test-suf");
});
});
describe("info", () => {
test("returns formatted config info", () => {
strictEqual(info(defaultConfig), "bridge v0.1.0");
});
test("works with custom config", () => {
const customConfig = { name: "custom", version: "1.0.0" };
strictEqual(info(customConfig), "custom v1.0.0");
});
});
describe("defaultConfig", () => {
test("has correct default values", () => {
deepStrictEqual(defaultConfig, { name: "bridge", version: "0.1.0" });
});
});
});