Compare commits
2 Commits
3aa40ae2c2
...
19c4fb5033
| Author | SHA1 | Date | |
|---|---|---|---|
| 19c4fb5033 | |||
| f57452ece2 |
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -14,6 +14,13 @@ export const list = {
|
|||
}
|
||||
return acc
|
||||
},
|
||||
reject: async (list: any[], cb: Function) => {
|
||||
let acc: any[] = []
|
||||
for (const value of list) {
|
||||
if (!(await cb(value))) acc.push(value)
|
||||
}
|
||||
return acc
|
||||
},
|
||||
reduce: async (list: any[], cb: Function, initial: any) => {
|
||||
let acc = initial
|
||||
for (const value of list) acc = await cb(acc, value)
|
||||
|
|
|
|||
|
|
@ -77,3 +77,17 @@ describe('introspection', () => {
|
|||
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)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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 () => {
|
||||
|
|
@ -193,6 +194,15 @@ describe('collections', () => {
|
|||
`).toEvaluateTo([3, 4, 5])
|
||||
})
|
||||
|
||||
test('list.reject doesnt keep matching elements', async () => {
|
||||
await expect(`
|
||||
is-even = do x:
|
||||
(x % 2) == 0
|
||||
end
|
||||
list.reject [1 2 3 4 5] is-even
|
||||
`).toEvaluateTo([1, 3, 5])
|
||||
})
|
||||
|
||||
test('list.reduce accumulates values', async () => {
|
||||
await expect(`
|
||||
add = do acc x:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user