graph-ecs/tests/assert.js

31 lines
648 B
JavaScript
Raw Normal View History

2024-11-13 20:24:29 +01:00
import assert from 'node:assert'
import { curry } from '../src/fn.js'
2024-11-14 00:32:46 +01:00
import { parse } from '../src/parser.js'
2024-11-13 20:24:29 +01:00
const isOk = curry((fn, result) => {
assert.doesNotThrow(() => {
2024-11-14 00:32:46 +01:00
fn(result.unwrap()[0])
2024-11-13 20:24:29 +01:00
})
})
const isErr = (result, error, msg) => {
if (error == null) {
assert(result.isErr())
} else {
assert.throws(result.unwrap(), error, msg)
}
}
export default {
...assert,
parseOk: curry((parser, input, fn) => {
isOk(fn, parse(parser, input))
}),
parseErr: (parser, input, error, message) => {
isErr(parse(parser, input), error, message)
},
isOk,
isErr
}