diff --git a/src/prelude/index.ts b/src/prelude/index.ts index 6834b8c..facf4b8 100644 --- a/src/prelude/index.ts +++ b/src/prelude/index.ts @@ -32,7 +32,7 @@ export const globals = { inspect: (v: any) => formatValue(toValue(v)), describe: (v: any) => { const val = toValue(v) - return { [val.type]: formatValue(toValue(v)) } + return `#<${val.type}: ${formatValue(val)}>` }, length: (v: any) => { const value = toValue(v) @@ -122,13 +122,15 @@ export function formatValue(value: Value, inner = false): string { return `${colors.dim}null${colors.reset}` case 'array': { const items = value.value.map(x => formatValue(x, true)).join(' ') - return `${inner ? '(' : ''}${colors.blue}list${colors.reset} ${items}${inner ? ')' : ''}` + return `${colors.blue}[${colors.reset}${items}${colors.blue}]${colors.reset}` } case 'dict': { const entries = Array.from(value.value.entries()) - .map(([k, v]) => `${k}=${formatValue(v, true)}`) + .map(([k, v]) => `${k}${colors.blue}=${colors.reset}${formatValue(v, true)}`) .join(' ') - return `${inner ? '(' : ''}${colors.magenta}dict${colors.reset} ${entries}${inner ? ')' : ''}` + if (entries.length === 0) + return `${colors.blue}[=]${colors.reset}` + return `${colors.blue}[${colors.reset}${entries}${colors.blue}]${colors.reset}` } case 'function': { const params = value.params.length ? '(' + value.params.join(' ') + ')' : '' diff --git a/src/prelude/tests/prelude.test.ts b/src/prelude/tests/prelude.test.ts index b7eb8ed..90ea2c6 100644 --- a/src/prelude/tests/prelude.test.ts +++ b/src/prelude/tests/prelude.test.ts @@ -190,7 +190,7 @@ describe('introspection', () => { 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) + await expect(`describe 'hello'`).toEvaluateTo("#", globals) }) })