diff --git a/src/prelude/index.ts b/src/prelude/index.ts index 488414b..6ec11d9 100644 --- a/src/prelude/index.ts +++ b/src/prelude/index.ts @@ -41,6 +41,10 @@ export const globals = { return typeof v !== 'string' || this.scope.has(v) }, + // env + args: Bun.argv.slice(1), + exit: (num: number) => process.exit(num ?? 0), + // type predicates 'string?': (v: any) => toValue(v).type === 'string', 'number?': (v: any) => toValue(v).type === 'number', diff --git a/src/prelude/tests/info.test.ts b/src/prelude/tests/info.test.ts index 9c24a8a..1fa5e3b 100644 --- a/src/prelude/tests/info.test.ts +++ b/src/prelude/tests/info.test.ts @@ -77,3 +77,17 @@ describe('introspection', () => { await expect(`describe 'hello'`).toEvaluateTo("#", 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) + }) +}) diff --git a/src/prelude/tests/prelude.test.ts b/src/prelude/tests/prelude.test.ts index 069b174..86341d3 100644 --- a/src/prelude/tests/prelude.test.ts +++ b/src/prelude/tests/prelude.test.ts @@ -66,6 +66,7 @@ describe('string operations', () => { test('slice extracts substring', async () => { await expect(`str.slice 'hello' 1 3`).toEvaluateTo('el') await expect(`str.slice 'hello' 2 null`).toEvaluateTo('llo') + await expect(`str.slice 'hello' 2`).toEvaluateTo('llo') }) test('repeat repeats string', async () => {