split out prelude info tests
This commit is contained in:
parent
e0e5e82869
commit
d93ce85178
72
src/prelude/tests/info.test.ts
Normal file
72
src/prelude/tests/info.test.ts
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import { expect, describe, test } from 'bun:test'
|
||||
import { globals, colors } from '#prelude'
|
||||
|
||||
describe('type predicates', () => {
|
||||
test('string? checks for string type', async () => {
|
||||
await expect(`string? 'hello'`).toEvaluateTo(true, globals)
|
||||
await expect(`string? 42`).toEvaluateTo(false, globals)
|
||||
})
|
||||
|
||||
test('number? checks for number type', async () => {
|
||||
await expect(`number? 42`).toEvaluateTo(true, globals)
|
||||
await expect(`number? 'hello'`).toEvaluateTo(false, globals)
|
||||
})
|
||||
|
||||
test('boolean? checks for boolean type', async () => {
|
||||
await expect(`boolean? true`).toEvaluateTo(true, globals)
|
||||
await expect(`boolean? 42`).toEvaluateTo(false, globals)
|
||||
})
|
||||
|
||||
test('array? checks for array type', async () => {
|
||||
await expect(`array? [1 2 3]`).toEvaluateTo(true, globals)
|
||||
await expect(`array? 42`).toEvaluateTo(false, globals)
|
||||
})
|
||||
|
||||
test('dict? checks for dict type', async () => {
|
||||
await expect(`dict? [a=1]`).toEvaluateTo(true, globals)
|
||||
await expect(`dict? []`).toEvaluateTo(false, globals)
|
||||
})
|
||||
|
||||
test('null? checks for null type', async () => {
|
||||
await expect(`null? null`).toEvaluateTo(true, globals)
|
||||
await expect(`null? 42`).toEvaluateTo(false, globals)
|
||||
})
|
||||
|
||||
test('some? checks for non-null', async () => {
|
||||
await expect(`some? 42`).toEvaluateTo(true, globals)
|
||||
await expect(`some? null`).toEvaluateTo(false, globals)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
describe('introspection', () => {
|
||||
test('type returns proper types', async () => {
|
||||
await expect(`type 'hello'`).toEvaluateTo('string', globals)
|
||||
await expect(`type 42`).toEvaluateTo('number', globals)
|
||||
await expect(`type true`).toEvaluateTo('boolean', globals)
|
||||
await expect(`type false`).toEvaluateTo('boolean', globals)
|
||||
await expect(`type null`).toEvaluateTo('null', globals)
|
||||
await expect(`type [1 2 3]`).toEvaluateTo('array', globals)
|
||||
await expect(`type [a=1 b=2]`).toEvaluateTo('dict', globals)
|
||||
})
|
||||
|
||||
test('length', async () => {
|
||||
await expect(`length 'hello'`).toEvaluateTo(5, globals)
|
||||
await expect(`length [1 2 3]`).toEvaluateTo(3, globals)
|
||||
await expect(`length [a=1 b=2]`).toEvaluateTo(2, globals)
|
||||
})
|
||||
|
||||
test('length throws on invalid types', async () => {
|
||||
await expect(`try: length 42 catch e: 'error' end`).toEvaluateTo('error', globals)
|
||||
await expect(`try: length true catch e: 'error' end`).toEvaluateTo('error', globals)
|
||||
await expect(`try: length null catch e: 'error' end`).toEvaluateTo('error', globals)
|
||||
})
|
||||
|
||||
test('inspect formats values', async () => {
|
||||
await expect(`inspect 'hello'`).toEvaluateTo("\u001b[32m'hello\u001b[32m'\u001b[0m", globals)
|
||||
})
|
||||
|
||||
test('describe describes values', async () => {
|
||||
await expect(`describe 'hello'`).toEvaluateTo("#<string: \u001b[32m'hello\u001b[32m'\u001b[0m>", globals)
|
||||
})
|
||||
})
|
||||
|
|
@ -98,43 +98,6 @@ describe('string operations', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('type predicates', () => {
|
||||
test('string? checks for string type', async () => {
|
||||
await expect(`string? 'hello'`).toEvaluateTo(true, globals)
|
||||
await expect(`string? 42`).toEvaluateTo(false, globals)
|
||||
})
|
||||
|
||||
test('number? checks for number type', async () => {
|
||||
await expect(`number? 42`).toEvaluateTo(true, globals)
|
||||
await expect(`number? 'hello'`).toEvaluateTo(false, globals)
|
||||
})
|
||||
|
||||
test('boolean? checks for boolean type', async () => {
|
||||
await expect(`boolean? true`).toEvaluateTo(true, globals)
|
||||
await expect(`boolean? 42`).toEvaluateTo(false, globals)
|
||||
})
|
||||
|
||||
test('array? checks for array type', async () => {
|
||||
await expect(`array? [1 2 3]`).toEvaluateTo(true, globals)
|
||||
await expect(`array? 42`).toEvaluateTo(false, globals)
|
||||
})
|
||||
|
||||
test('dict? checks for dict type', async () => {
|
||||
await expect(`dict? [a=1]`).toEvaluateTo(true, globals)
|
||||
await expect(`dict? []`).toEvaluateTo(false, globals)
|
||||
})
|
||||
|
||||
test('null? checks for null type', async () => {
|
||||
await expect(`null? null`).toEvaluateTo(true, globals)
|
||||
await expect(`null? 42`).toEvaluateTo(false, globals)
|
||||
})
|
||||
|
||||
test('some? checks for non-null', async () => {
|
||||
await expect(`some? 42`).toEvaluateTo(true, globals)
|
||||
await expect(`some? null`).toEvaluateTo(false, globals)
|
||||
})
|
||||
})
|
||||
|
||||
describe('boolean logic', () => {
|
||||
test('not negates value', async () => {
|
||||
await expect(`not true`).toEvaluateTo(false, globals)
|
||||
|
|
@ -161,42 +124,6 @@ describe('utilities', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('introspection', () => {
|
||||
test('type returns proper types', async () => {
|
||||
await expect(`type 'hello'`).toEvaluateTo('string', globals)
|
||||
await expect(`type 42`).toEvaluateTo('number', globals)
|
||||
await expect(`type true`).toEvaluateTo('boolean', globals)
|
||||
await expect(`type false`).toEvaluateTo('boolean', globals)
|
||||
await expect(`type null`).toEvaluateTo('null', globals)
|
||||
await expect(`type [1 2 3]`).toEvaluateTo('array', globals)
|
||||
await expect(`type [a=1 b=2]`).toEvaluateTo('dict', globals)
|
||||
})
|
||||
|
||||
test('length', async () => {
|
||||
await expect(`length 'hello'`).toEvaluateTo(5, globals)
|
||||
await expect(`length [1 2 3]`).toEvaluateTo(3, globals)
|
||||
await expect(`length [a=1 b=2]`).toEvaluateTo(2, globals)
|
||||
})
|
||||
|
||||
test('length throws on invalid types', async () => {
|
||||
await expect(`try: length 42 catch e: 'error' end`).toEvaluateTo('error', globals)
|
||||
await expect(`try: length true catch e: 'error' end`).toEvaluateTo('error', globals)
|
||||
await expect(`try: length null catch e: 'error' end`).toEvaluateTo('error', globals)
|
||||
})
|
||||
|
||||
test('inspect formats values', async () => {
|
||||
// Just test that inspect returns something for now
|
||||
// (we'd need more complex assertion to check the actual format)
|
||||
await expect(`type (inspect 'hello')`).toEvaluateTo('string', globals)
|
||||
})
|
||||
|
||||
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)
|
||||
})
|
||||
})
|
||||
|
||||
describe('collections', () => {
|
||||
test('literal array creates array from arguments', async () => {
|
||||
await expect(`[ 1 2 3 ]`).toEvaluateTo([1, 2, 3], globals)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user