From a21ba54ad7280c6b65be1288376ec79d7c4f8ebd Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Wed, 29 Oct 2025 12:21:11 -0700 Subject: [PATCH] describe? --- src/prelude/index.ts | 30 +++++++++++++++++------------- src/prelude/tests/prelude.test.ts | 6 ++++++ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/prelude/index.ts b/src/prelude/index.ts index 50e45e4..6834b8c 100644 --- a/src/prelude/index.ts +++ b/src/prelude/index.ts @@ -11,19 +11,6 @@ import { list } from './list' import { math } from './math' import { str } from './str' -export const colors = { - reset: '\x1b[0m', - bright: '\x1b[1m', - dim: '\x1b[2m', - cyan: '\x1b[36m', - yellow: '\x1b[33m', - green: '\x1b[32m', - red: '\x1b[31m', - blue: '\x1b[34m', - magenta: '\x1b[35m', - pink: '\x1b[38;2;255;105;180m' -} - export const globals = { dict, load, @@ -43,6 +30,10 @@ export const globals = { // info type: (v: any) => toValue(v).type, inspect: (v: any) => formatValue(toValue(v)), + describe: (v: any) => { + const val = toValue(v) + return { [val.type]: formatValue(toValue(v)) } + }, length: (v: any) => { const value = toValue(v) switch (value.type) { @@ -106,6 +97,19 @@ export const globals = { } +export const colors = { + reset: '\x1b[0m', + bright: '\x1b[1m', + dim: '\x1b[2m', + cyan: '\x1b[36m', + yellow: '\x1b[33m', + green: '\x1b[32m', + red: '\x1b[31m', + blue: '\x1b[34m', + magenta: '\x1b[35m', + pink: '\x1b[38;2;255;105;180m' +} + export function formatValue(value: Value, inner = false): string { switch (value.type) { case 'string': diff --git a/src/prelude/tests/prelude.test.ts b/src/prelude/tests/prelude.test.ts index fc19e0d..b7eb8ed 100644 --- a/src/prelude/tests/prelude.test.ts +++ b/src/prelude/tests/prelude.test.ts @@ -186,6 +186,12 @@ describe('introspection', () => { // (we'd need more complex assertion to check the actual format) await expect(`type (inspect 'hello')`).toEvaluateTo('string', globals) }) + + test('describe describes values', async () => { + // Just test that inspect returns something for now + // (we'd need more complex assertion to check the actual format) + await expect(`describe 'hello'`).toEvaluateTo({ string: "\u001b[32m'hello\u001b[32m'\u001b[0m" }, globals) + }) }) describe('collections', () => {