shrimp/src/tests/shrimp.test.ts

33 lines
973 B
TypeScript

import { describe } from 'bun:test'
import { expect, test } from 'bun:test'
import { Shrimp } from '..'
describe('Shrimp', () => {
test('allows running Shrimp code', async () => {
const shrimp = new Shrimp()
expect(await shrimp.run(`1 + 5`)).toEqual(6)
expect(await shrimp.run(`type 5`)).toEqual('number')
})
test('maintains state across runs', async () => {
const shrimp = new Shrimp()
await shrimp.run(`abc = true`)
expect(shrimp.get('abc')).toEqual(true)
await shrimp.run(`name = Bob`)
expect(shrimp.get('abc')).toEqual(true)
expect(shrimp.get('name')).toEqual('Bob')
await shrimp.run(`abc = false`)
expect(shrimp.get('abc')).toEqual(false)
})
test('allows setting your own globals', async () => {
const shrimp = new Shrimp({ hiya: () => 'hey there' })
await shrimp.run('abc = hiya')
expect(shrimp.get('abc')).toEqual('hey there')
expect(await shrimp.run('type abc')).toEqual('string')
})
})