args and exit

This commit is contained in:
Chris Wanstrath 2025-11-08 08:22:41 -08:00
parent f57452ece2
commit 19c4fb5033
3 changed files with 19 additions and 0 deletions

View File

@ -41,6 +41,10 @@ export const globals = {
return typeof v !== 'string' || this.scope.has(v) return typeof v !== 'string' || this.scope.has(v)
}, },
// env
args: Bun.argv.slice(1),
exit: (num: number) => process.exit(num ?? 0),
// type predicates // type predicates
'string?': (v: any) => toValue(v).type === 'string', 'string?': (v: any) => toValue(v).type === 'string',
'number?': (v: any) => toValue(v).type === 'number', 'number?': (v: any) => toValue(v).type === 'number',

View File

@ -77,3 +77,17 @@ describe('introspection', () => {
await expect(`describe 'hello'`).toEvaluateTo("#<string: \u001b[32m'hello\u001b[32m'\u001b[0m>", globals) await expect(`describe 'hello'`).toEvaluateTo("#<string: \u001b[32m'hello\u001b[32m'\u001b[0m>", globals)
}) })
}) })
describe('environment', () => {
test('args is an array', async () => {
await expect(`array? args`).toEvaluateTo(true, globals)
})
test('args can be accessed', async () => {
await expect(`type args`).toEvaluateTo('array', globals)
})
test('', async () => {
await expect(`list.first args | str.ends-with? 'shrimp.test.ts'`).toEvaluateTo(true)
})
})

View File

@ -66,6 +66,7 @@ describe('string operations', () => {
test('slice extracts substring', async () => { test('slice extracts substring', async () => {
await expect(`str.slice 'hello' 1 3`).toEvaluateTo('el') await expect(`str.slice 'hello' 1 3`).toEvaluateTo('el')
await expect(`str.slice 'hello' 2 null`).toEvaluateTo('llo') await expect(`str.slice 'hello' 2 null`).toEvaluateTo('llo')
await expect(`str.slice 'hello' 2`).toEvaluateTo('llo')
}) })
test('repeat repeats string', async () => { test('repeat repeats string', async () => {