describe?

This commit is contained in:
Chris Wanstrath 2025-10-29 12:21:11 -07:00
parent df3d483de5
commit a21ba54ad7
2 changed files with 23 additions and 13 deletions

View File

@ -11,19 +11,6 @@ import { list } from './list'
import { math } from './math' import { math } from './math'
import { str } from './str' 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 = { export const globals = {
dict, dict,
load, load,
@ -43,6 +30,10 @@ export const globals = {
// info // info
type: (v: any) => toValue(v).type, type: (v: any) => toValue(v).type,
inspect: (v: any) => formatValue(toValue(v)), inspect: (v: any) => formatValue(toValue(v)),
describe: (v: any) => {
const val = toValue(v)
return { [val.type]: formatValue(toValue(v)) }
},
length: (v: any) => { length: (v: any) => {
const value = toValue(v) const value = toValue(v)
switch (value.type) { 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 { export function formatValue(value: Value, inner = false): string {
switch (value.type) { switch (value.type) {
case 'string': case 'string':

View File

@ -186,6 +186,12 @@ describe('introspection', () => {
// (we'd need more complex assertion to check the actual format) // (we'd need more complex assertion to check the actual format)
await expect(`type (inspect 'hello')`).toEvaluateTo('string', globals) 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', () => { describe('collections', () => {