31 lines
672 B
JavaScript
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
|
|
}
|
|
|