pi-ext
bugabingas pi extensions
owned by bugabinga
refactor(ascii-boxes): replace Deno with Node.js, convert tests to bun:test
3edb79fa1260a1595e24e4b8334c9552a70432ac
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
Browse filesCompare with HEAD
Changed files (2)
skills/ascii-boxes/index.test.ts
Modified 3 - assertStringIncludes,
4 -}
from "https://deno.land/std@0.208.0/assert/mod.ts";
1 +import { describe, expect, test }
from "bun:test";
5 2 import { createTable, drawBox, drawNested }
from "./index.ts";
7 -Deno.
test(
"drawBox - simple box with content", ()
=> {
8 - const result
= drawBox(
"Hello", { width:
10 });
9 - const lines
= result.
split(
"\n");
12 - assertEquals(lines.
length,
3);
15 - assertStringIncludes(lines[
0],
"┌");
16 - assertStringIncludes(lines[
0],
"┐");
19 - assertStringIncludes(lines[
1],
"│");
22 - assertStringIncludes(lines[
2],
"└");
23 - assertStringIncludes(lines[
2],
"┘");
26 -Deno.
test(
"drawBox - content alignment left", ()
=> {
27 - const result
= drawBox(
"Test", { width:
20, alignment:
"left" });
28 - const lines
= result.
split(
"\n");
29 - const contentLine
= lines[
1];
32 - const testIndex
= contentLine.
indexOf(
"Test");
33 - const pipeIndex
= contentLine.
indexOf(
"│");
35 - assertEquals(contentLine[pipeIndex],
"│");
37 - assertEquals(testIndex, pipeIndex
+ 2);
40 -Deno.
test(
"drawBox - content alignment center", ()
=> {
41 - const result
= drawBox(
"Hi", { width:
20, alignment:
"center" });
42 - const lines
= result.
split(
"\n");
43 - const contentLine
= lines[
1];
45 - const hiIndex
= contentLine.
indexOf(
"Hi");
50 - assertEquals(contentLine[
0],
"│");
53 -Deno.
test(
"drawBox - content alignment right", ()
=> {
54 - const result
= drawBox(
"X", { width:
10, alignment:
"right" });
55 - const lines
= result.
split(
"\n");
56 - const contentLine
= lines[
1];
59 - const xIndex
= contentLine.
indexOf(
"X");
60 - const rightPipeIndex
= contentLine.
lastIndexOf(
"│");
63 - assertEquals(contentLine[rightPipeIndex],
"│");
66 -Deno.
test(
"drawBox - double border style", ()
=> {
67 - const result
= drawBox(
"Test", { style:
"double" });
69 - assertStringIncludes(result,
"╔");
70 - assertStringIncludes(result,
"╗");
71 - assertStringIncludes(result,
"╚");
72 - assertStringIncludes(result,
"╝");
73 - assertStringIncludes(result,
"║");
74 - assertStringIncludes(result,
"═");
77 - assertEquals(result.
indexOf(
"┌"),
-1);
78 - assertEquals(result.
indexOf(
"│"),
-1);
81 -Deno.
test(
"drawBox - bold border style", ()
=> {
82 - const result
= drawBox(
"Test", { style:
"bold" });
84 - assertStringIncludes(result,
"┏");
85 - assertStringIncludes(result,
"┓");
86 - assertStringIncludes(result,
"┗");
87 - assertStringIncludes(result,
"┛");
88 - assertStringIncludes(result,
"┃");
89 - assertStringIncludes(result,
"━");
92 -Deno.
test(
"drawBox - padding", ()
=> {
93 - const result
= drawBox(
"X", {
4 +describe(
"drawBox", ()
=> {
5 + test(
"simple box with content", ()
=> {
6 + const result
= drawBox(
"Hello", { width:
10 });
7 + const lines
= result.
split(
"\n");
8 + expect(lines.
length).
toBe(
3);
9 + expect(lines[
0]).
toInclude(
"┌");
10 + expect(lines[
0]).
toInclude(
"┐");
11 + expect(lines[
1]).
toInclude(
"│");
12 + expect(lines[
2]).
toInclude(
"└");
13 + expect(lines[
2]).
toInclude(
"┘");
100 - const lines
= result.
split(
"\n");
103 - assertEquals(lines.
length,
7);
106 - assertStringIncludes(lines[
0],
"┌");
107 - assertStringIncludes(lines[
6],
"┘");
110 - assertStringIncludes(lines[
1],
"│");
111 - assertStringIncludes(lines[
2],
"│");
114 - assertStringIncludes(lines[
3],
"X");
117 - assertStringIncludes(lines[
4],
"│");
120 -Deno.
test(
"drawBox - multi-line content", ()
=> {
121 - const result
= drawBox([
"Line 1",
"Line 2",
"Line 3"], { width:
20 });
122 - const lines
= result.
split(
"\n");
125 - assertEquals(lines.
length,
5);
128 - assertStringIncludes(result,
"Line 1");
129 - assertStringIncludes(result,
"Line 2");
130 - assertStringIncludes(result,
"Line 3");
133 -Deno.
test(
"drawBox - wrap long text", ()
=> {
134 - const result
= drawBox(
"This is a very long sentence that needs wrapping", {
16 + test(
"content alignment left", ()
=> {
17 + const result
= drawBox(
"Test", { width:
20, alignment:
"left" });
18 + const lines
= result.
split(
"\n");
19 + const contentLine
= lines[
1];
20 + const testIndex
= contentLine.
indexOf(
"Test");
21 + const pipeIndex
= contentLine.
indexOf(
"│");
22 + expect(contentLine[pipeIndex]).
toBe(
"│");
23 + expect(testIndex).
toBe(pipeIndex
+ 2);
137 - const lines
= result.
split(
"\n");
140 - assertTrue(lines.
length > 3);
142 -Deno.
test(
"createTable - simple table", ()
=> {
143 - const result
= createTable(
151 - assertStringIncludes(result,
"Name");
152 - assertStringIncludes(result,
"Age");
153 - assertStringIncludes(result,
"Alice");
154 - assertStringIncludes(result,
"Bob");
155 - assertStringIncludes(result,
"┌");
156 - assertStringIncludes(result,
"┐");
157 - assertStringIncludes(result,
"└");
158 - assertStringIncludes(result,
"┘");
161 -Deno.
test(
"createTable - separator line uses tee", ()
=> {
162 - const result
= createTable([
"H1",
"H2"], [[
"a",
"b"]]);
165 - const lines
= result.
split(
"\n");
167 - assertStringIncludes(lines[
2],
"├");
168 - assertStringIncludes(lines[
2],
"┤");
169 - assertStringIncludes(lines[
2],
"┼");
172 -Deno.
test(
"createTable - double style", ()
=> {
173 - const result
= createTable([
"H"], [[
"d"]], { style:
"double" });
175 - assertStringIncludes(result,
"╔");
176 - assertStringIncludes(result,
"╗");
177 - assertStringIncludes(result,
"╠");
178 - assertStringIncludes(result,
"╣");
179 - assertStringIncludes(result,
"║");
180 - assertStringIncludes(result,
"═");
183 -Deno.
test(
"createTable - padding", ()
=> {
184 - const result
= createTable([
"Name"], [[
"Alice"]], { padding:
3 });
187 - assertStringIncludes(result,
"│ Name");
188 - assertStringIncludes(result,
"│ Alice");
191 -Deno.
test(
"drawNested - nested boxes", ()
=> {
192 - const result
= drawNested(
"Outer",
"Inner");
194 - assertStringIncludes(result,
"Outer");
195 - assertStringIncludes(result,
"Inner");
197 - const topBorders
= (result.
match(
/┌/g)
|| []).
length;
198 - assertEquals(topBorders,
2);
201 -Deno.
test(
"drawNested - with gap", ()
=> {
202 - const result
= drawNested(
"O",
"I", { gap:
2 });
204 - assertStringIncludes(result,
"O");
205 - assertStringIncludes(result,
"I");
207 - const lines
= result.
split(
"\n");
210 - const innerLine
= lines.
findIndex((l)
=> l.
includes(
"I"));
211 - const outerLine
= lines.
findIndex((l)
=> l.
includes(
"O"));
214 - assertTrue(
Math.
abs(innerLine
- outerLine)
> 2);
220 -Deno.
test(
"drawBox - array content", ()
=> {
221 - const lines
= [
"Line 1",
"Line 2",
"Line 3"];
222 - const result
= drawBox(lines, { width:
20 });
223 - assertStringIncludes(result,
"Line 1");
224 - assertStringIncludes(result,
"Line 2");
225 - assertStringIncludes(result,
"Line 3");
226 - const outLines
= result.
split(
"\n");
227 - assertEquals(outLines.
length,
5);
230 -Deno.
test(
"drawBox - alignment right with padding", ()
=> {
231 - const result
= drawBox(
"X", {
233 - alignment:
"right",
26 + test(
"content alignment center", ()
=> {
27 + const result
= drawBox(
"Hi", { width:
20, alignment:
"center" });
28 + const lines
= result.
split(
"\n");
29 + expect(lines[
1][
0]).
toBe(
"│");
237 - const lines
= result.
split(
"\n");
238 - const contentLine
= lines[
1];
239 - const xIdx
= contentLine.
indexOf(
"X");
240 - const rightPipe
= contentLine.
lastIndexOf(
"│");
241 - const leftPipe
= contentLine.
indexOf(
"│");
242 - assertTrue(xIdx
< rightPipe);
243 - assertTrue(xIdx
> leftPipe);
246 -Deno.
test(
"drawBox - single character wide", ()
=> {
249 - const result
= drawBox(
"X", { width:
1 });
250 - assertStringIncludes(result,
"┌───┐");
251 - assertStringIncludes(result,
"│ X │");
252 - assertStringIncludes(result,
"└───┘");
255 -Deno.
test(
"drawBox - zero padding", ()
=> {
256 - const result
= drawBox(
"AB", {
32 + test(
"content alignment right", ()
=> {
33 + const result
= drawBox(
"X", { width:
10, alignment:
"right" });
34 + const lines
= result.
split(
"\n");
35 + const contentLine
= lines[
1];
36 + const rightPipeIndex
= contentLine.
lastIndexOf(
"│");
37 + expect(contentLine[rightPipeIndex]).
toBe(
"│");
263 - const lines
= result.
split(
"\n");
264 - assertEquals(lines.
length,
3);
267 - assertStringIncludes(lines[
0],
"┌────┐");
268 - assertStringIncludes(lines[
1],
"│AB │");
269 - assertStringIncludes(lines[
2],
"└────┘");
272 -Deno.
test(
"drawBox - long text forces wrap", ()
=> {
275 - const result
= drawBox(
"This is a very long line of text", { width:
10 });
276 - const lines
= result.
split(
"\n");
277 - assertTrue(lines.
length > 3);
279 - const contentLines
= lines.
slice(
1,
-1);
280 - for (
const cl
of contentLines) {
281 - const firstPipe
= cl.
indexOf(
"│");
282 - const lastPipe
= cl.
lastIndexOf(
"│");
283 - const betweenPipes
= cl.
slice(firstPipe
+ 1, lastPipe);
284 - assertTrue(betweenPipes.
length <= 12);
288 -Deno.
test(
"createTable - empty rows", ()
=> {
289 - const result
= createTable([
"A",
"B"], [], { style:
"single" });
290 - assertStringIncludes(result,
"A");
291 - assertStringIncludes(result,
"B");
292 - assertTrue(result.
includes(
"├")
&& result.
includes(
"┤"));
295 -Deno.
test(
"createTable - single column", ()
=> {
296 - const result
= createTable([
"Name"], [[
"Alice"], [
"Bob"]]);
297 - assertStringIncludes(result,
"Name");
298 - assertStringIncludes(result,
"Alice");
299 - assertStringIncludes(result,
"Bob");
302 -Deno.
test(
"drawNested - zero width content", ()
=> {
303 - const result
= drawNested(
"",
"", { gap:
0 });
304 - assertStringIncludes(result,
"┌");
305 - assertStringIncludes(result,
"└");
308 -Deno.
test(
"drawNested - different styles", ()
=> {
309 - const result
= drawNested(
"O",
"I", {
310 - styleOuter:
"double",
311 - styleInner:
"bold",
40 + test(
"double border style", ()
=> {
41 + const result
= drawBox(
"Test", { style:
"double" });
42 + expect(result).
toInclude(
"╔");
43 + expect(result).
toInclude(
"╗");
44 + expect(result).
toInclude(
"╚");
45 + expect(result).
toInclude(
"╝");
46 + expect(result).
toInclude(
"║");
47 + expect(result).
toInclude(
"═");
48 + expect(result).not.
toInclude(
"┌");
49 + expect(result).not.
toInclude(
"│");
314 - assertTrue(result.
includes(
"╔")
|| result.
includes(
"╗"));
315 - assertTrue(result.
includes(
"┏")
|| result.
includes(
"┓"));
318 -Deno.
test(
"drawNested - gap creates space", ()
=> {
319 - const r1
= drawNested(
"O",
"I", { gap:
0 });
320 - const r2
= drawNested(
"O",
"I", { gap:
2 });
321 - assertTrue(r2.
split(
"\n").
length >= r1.
split(
"\n").
length + 2);
324 -Deno.
test(
"border styles are consistent", ()
=> {
325 - const single
= drawBox(
"T", { style:
"single" });
326 - const double
= drawBox(
"T", { style:
"double" });
327 - const bold
= drawBox(
"T", { style:
"bold" });
329 - single.
includes(
"┌")
&& single.
includes(
"─")
&& single.
includes(
"│"),
332 - double.
includes(
"╔")
&& double.
includes(
"═")
&& double.
includes(
"║"),
334 - assertTrue(bold.
includes(
"┏")
&& bold.
includes(
"━")
&& bold.
includes(
"┃"));
335 - assertEquals(single.
includes(
"╔"),
false);
336 - assertEquals(double.
includes(
"┌"),
false);
342 -Deno.
test(
"demo - system status panel", ()
=> {
343 - const box
= drawBox(
" System Status ", {
346 - alignment:
"center",
52 + test(
"bold border style", ()
=> {
53 + const result
= drawBox(
"Test", { style:
"bold" });
54 + expect(result).
toInclude(
"┏");
55 + expect(result).
toInclude(
"┓");
56 + expect(result).
toInclude(
"┗");
57 + expect(result).
toInclude(
"┛");
58 + expect(result).
toInclude(
"┃");
59 + expect(result).
toInclude(
"━");
62 + test(
"padding", ()
=> {
63 + const result
= drawBox(
"X", {
70 + const lines
= result.
split(
"\n");
71 + expect(lines.
length).
toBe(
7);
72 + expect(lines[
0]).
toInclude(
"┌");
73 + expect(lines[
6]).
toInclude(
"┘");
74 + expect(lines[
1]).
toInclude(
"│");
75 + expect(lines[
2]).
toInclude(
"│");
76 + expect(lines[
3]).
toInclude(
"X");
77 + expect(lines[
4]).
toInclude(
"│");
80 + test(
"multi-line content", ()
=> {
81 + const result
= drawBox([
"Line 1",
"Line 2",
"Line 3"], { width:
20 });
82 + const lines
= result.
split(
"\n");
83 + expect(lines.
length).
toBe(
5);
84 + expect(result).
toInclude(
"Line 1");
85 + expect(result).
toInclude(
"Line 2");
86 + expect(result).
toInclude(
"Line 3");
89 + test(
"wrap long text", ()
=> {
90 + const result
= drawBox(
"This is a very long sentence that needs wrapping", {
93 + const lines
= result.
split(
"\n");
94 + expect(lines.
length).
toBeGreaterThan(
3);
97 + test(
"array content", ()
=> {
98 + const lines
= [
"Line 1",
"Line 2",
"Line 3"];
99 + const result
= drawBox(lines, { width:
20 });
100 + expect(result).
toInclude(
"Line 1");
101 + expect(result).
toInclude(
"Line 2");
102 + expect(result).
toInclude(
"Line 3");
103 + expect(result.
split(
"\n").
length).
toBe(
5);
106 + test(
"alignment right with padding", ()
=> {
107 + const result
= drawBox(
"X", {
109 + alignment:
"right",
113 + const lines
= result.
split(
"\n");
114 + const contentLine
= lines[
1];
115 + const xIdx
= contentLine.
indexOf(
"X");
116 + const rightPipe
= contentLine.
lastIndexOf(
"│");
117 + const leftPipe
= contentLine.
indexOf(
"│");
118 + expect(xIdx).
toBeLessThan(rightPipe);
119 + expect(xIdx).
toBeGreaterThan(leftPipe);
122 + test(
"single character wide", ()
=> {
123 + const result
= drawBox(
"X", { width:
1 });
124 + expect(result).
toInclude(
"┌───┐");
125 + expect(result).
toInclude(
"│ X │");
126 + expect(result).
toInclude(
"└───┘");
129 + test(
"zero padding", ()
=> {
130 + const result
= drawBox(
"AB", {
137 + const lines
= result.
split(
"\n");
138 + expect(lines.
length).
toBe(
3);
139 + expect(lines[
0]).
toInclude(
"┌────┐");
140 + expect(lines[
1]).
toInclude(
"│AB │");
141 + expect(lines[
2]).
toInclude(
"└────┘");
144 + test(
"long text forces wrap", ()
=> {
145 + const result
= drawBox(
"This is a very long line of text", { width:
10 });
146 + const lines
= result.
split(
"\n");
147 + expect(lines.
length).
toBeGreaterThan(
3);
148 + const contentLines
= lines.
slice(
1,
-1);
149 + for (
const cl
of contentLines) {
150 + const firstPipe
= cl.
indexOf(
"│");
151 + const lastPipe
= cl.
lastIndexOf(
"│");
152 + const betweenPipes
= cl.
slice(firstPipe
+ 1, lastPipe);
153 + expect(betweenPipes.
length).
toBeLessThanOrEqual(
12);
350 - const table
= createTable(
351 - [
"Module",
"Status"],
353 - [
"Agent Core",
"✅"],
360 - assertTrue(box.
length > 0);
361 - assertTrue(table.
length > 0);
363 - assertTrue(box.
includes(
"┏"));
364 - assertTrue(box.
includes(
"┛"));
367 -function assertTrue(cond
: boolean, msg
?: string) {
368 - if (
!cond)
throw new Error(msg
|| "Assertion failed");
158 +describe(
"createTable", ()
=> {
159 + test(
"simple table", ()
=> {
160 + const result
= createTable(
167 + expect(result).
toInclude(
"Name");
168 + expect(result).
toInclude(
"Age");
169 + expect(result).
toInclude(
"Alice");
170 + expect(result).
toInclude(
"Bob");
171 + expect(result).
toInclude(
"┌");
172 + expect(result).
toInclude(
"┐");
173 + expect(result).
toInclude(
"└");
174 + expect(result).
toInclude(
"┘");
177 + test(
"separator line uses tee", ()
=> {
178 + const result
= createTable([
"H1",
"H2"], [[
"a",
"b"]]);
179 + const lines
= result.
split(
"\n");
180 + expect(lines[
2]).
toInclude(
"├");
181 + expect(lines[
2]).
toInclude(
"┤");
182 + expect(lines[
2]).
toInclude(
"┼");
185 + test(
"double style", ()
=> {
186 + const result
= createTable([
"H"], [[
"d"]], { style:
"double" });
187 + expect(result).
toInclude(
"╔");
188 + expect(result).
toInclude(
"╗");
189 + expect(result).
toInclude(
"╠");
190 + expect(result).
toInclude(
"╣");
191 + expect(result).
toInclude(
"║");
192 + expect(result).
toInclude(
"═");
195 + test(
"padding", ()
=> {
196 + const result
= createTable([
"Name"], [[
"Alice"]], { padding:
3 });
197 + expect(result).
toInclude(
"│ Name");
198 + expect(result).
toInclude(
"│ Alice");
201 + test(
"empty rows", ()
=> {
202 + const result
= createTable([
"A",
"B"], [], { style:
"single" });
203 + expect(result).
toInclude(
"A");
204 + expect(result).
toInclude(
"B");
205 + expect(result).
toInclude(
"├");
206 + expect(result).
toInclude(
"┤");
209 + test(
"single column", ()
=> {
210 + const result
= createTable([
"Name"], [[
"Alice"], [
"Bob"]]);
211 + expect(result).
toInclude(
"Name");
212 + expect(result).
toInclude(
"Alice");
213 + expect(result).
toInclude(
"Bob");
217 +describe(
"drawNested", ()
=> {
218 + test(
"nested boxes", ()
=> {
219 + const result
= drawNested(
"Outer",
"Inner");
220 + expect(result).
toInclude(
"Outer");
221 + expect(result).
toInclude(
"Inner");
222 + expect((result.
match(
/┌/g)
|| []).
length).
toBe(
2);
225 + test(
"with gap", ()
=> {
226 + const result
= drawNested(
"O",
"I", { gap:
2 });
227 + expect(result).
toInclude(
"O");
228 + expect(result).
toInclude(
"I");
229 + const innerLine
= result.
split(
"\n").
findIndex((l)
=> l.
includes(
"I"));
230 + const outerLine
= result.
split(
"\n").
findIndex((l)
=> l.
includes(
"O"));
231 + expect(
Math.
abs(innerLine
- outerLine)).
toBeGreaterThan(
2);
234 + test(
"zero width content", ()
=> {
235 + const result
= drawNested(
"",
"", { gap:
0 });
236 + expect(result).
toInclude(
"┌");
237 + expect(result).
toInclude(
"└");
240 + test(
"different styles", ()
=> {
241 + const result
= drawNested(
"O",
"I", {
242 + styleOuter:
"double",
243 + styleInner:
"bold",
246 + expect(result.
includes(
"╔")
|| result.
includes(
"╗")).
toBe(
true);
247 + expect(result.
includes(
"┏")
|| result.
includes(
"┓")).
toBe(
true);
250 + test(
"gap creates space", ()
=> {
251 + const r1
= drawNested(
"O",
"I", { gap:
0 });
252 + const r2
= drawNested(
"O",
"I", { gap:
2 });
253 + expect(r2.
split(
"\n").
length).
toBeGreaterThanOrEqual(
254 + r1.
split(
"\n").
length + 2,
259 +describe(
"border styles", ()
=> {
260 + test(
"are consistent", ()
=> {
261 + const single
= drawBox(
"T", { style:
"single" });
262 + const double
= drawBox(
"T", { style:
"double" });
263 + const bold
= drawBox(
"T", { style:
"bold" });
264 + expect(single.
includes(
"┌")
&& single.
includes(
"─")
&& single.
includes(
"│")).
toBe(
true);
265 + expect(double.
includes(
"╔")
&& double.
includes(
"═")
&& double.
includes(
"║")).
toBe(
true);
266 + expect(bold.
includes(
"┏")
&& bold.
includes(
"━")
&& bold.
includes(
"┃")).
toBe(
true);
267 + expect(single).not.
toInclude(
"╔");
268 + expect(double).not.
toInclude(
"┌");
272 +describe(
"demo - system status panel", ()
=> {
273 + test(
"renders without errors", ()
=> {
274 + const box
= drawBox(
" System Status ", {
277 + alignment:
"center",
281 + const table
= createTable(
282 + [
"Module",
"Status"],
284 + [
"Agent Core",
"✅"],
290 + expect(box.
length).
toBeGreaterThan(
0);
291 + expect(table.
length).
toBeGreaterThan(
0);
292 + expect(box).
toInclude(
"┏");
293 + expect(box).
toInclude(
"┛");
skills/ascii-boxes/index.ts
Modified 4 3 const SPACES
= " ".
repeat(
128);
263 262 if (
import.
meta.main) {
264 - const args
= Deno.args;
263 + const args
= process.
argv.
slice(
2);
265 264 const cmd
= args[
0];
351 350 console.
error(
"Error:", e
instanceof Error ? e.message
: e);