39 lines
975 B
JavaScript
39 lines
975 B
JavaScript
import { it, assert, assertEq } from 'folktest'
|
|
import { Union } from '../../src/union.js'
|
|
|
|
export const Tests = [
|
|
it('should create a valid tagged union', () => {
|
|
const union = Union(['Nothing', 'Void'])
|
|
|
|
assert(Object.hasOwn(union, 'Nothing'))
|
|
assert(Object.hasOwn(union, 'Void'))
|
|
}),
|
|
|
|
it('can be matched', () => {
|
|
const union = Union(['Adrift', 'Nonextant', 'Dream'])
|
|
const dreaming = union.Dream('mercury')
|
|
const drifting = union.Adrift('19589')
|
|
const gone = union.Nonextant('rowan', Infinity)
|
|
|
|
dreaming.fold({
|
|
Dream(name) {
|
|
assertEq(name, 'mercury')
|
|
}
|
|
})
|
|
|
|
drifting.fold({
|
|
Adrift(name) {
|
|
assertEq(name, '19589')
|
|
}
|
|
})
|
|
|
|
gone.fold({
|
|
Nonextant(name, when) {
|
|
assertEq(name, 'rowan')
|
|
assertEq(when, Infinity)
|
|
}
|
|
})
|
|
})
|
|
]
|
|
|
|
|