graph-ecs/tests/assert.js
2024-11-13 13:24:29 -06:00

31 lines
672 B
JavaScript

import assert from 'node:assert'
import { curry } from '../src/fn.js'
import { parse } from 'node:path'
const isOk = curry((fn, result) => {
assert.doesNotThrow(() => {
const [[actual]] = result.unwrap()
fn(actual)
})
})
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
}