-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmaybe.test.js
More file actions
41 lines (38 loc) · 1.22 KB
/
Copy pathmaybe.test.js
File metadata and controls
41 lines (38 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { maybeImpl as maybe, catImpl as cat } from '../../lib/regex'
import map from '../../lib/spec/map'
import { conform, valid } from '../../lib/util'
import { invalid } from '../../lib/symbols'
import { expect } from 'chai'
import { define } from '../../lib/registry'
import { explainData } from '../../index'
import * as p from '../../lib/predicates'
const maybe_ingredient = maybe("ingredient", cat("quantity", p.number, "unit", p.string))
describe('maybe', () => {
describe('conform', () => {
it('works in happy case', () => {
expect(conform(maybe_ingredient), "no value").to.deep.equal({
ingredient: null
})
expect(conform(maybe_ingredient, []), "empty array").to.deep.equal({
ingredient: null
})
expect(conform(maybe_ingredient, [5, "spoons"]), "value").to.deep.equal({
ingredient: {
unit: "spoons",
quantity: 5
}
})
})
it('works in nested case', () => {
const ingredient = cat("quantity", maybe("value", p.number), "unit", maybe("value", p.string))
expect(conform(ingredient, [])).to.deep.equal({
quantity: {
value: null
},
unit: {
value: null
}
})
})
})
})