index.js
1.45 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var test = require("tape")
var Result = require("rust-result")
var safeParse = require("../callback")
var safeParseTuple = require("../tuple")
var safeParseResult = require("../result")
test("safeParse is a function", function (assert) {
assert.equal(typeof safeParse, "function")
assert.end()
})
test("safeParse valid json", function (assert) {
safeParse("{ \"foo\": true }", function (err, json) {
assert.ifError(err)
assert.equal(json.foo, true)
assert.end()
})
})
test("safeParse faulty", function (assert) {
safeParse("WRONG", function (err) {
assert.ok(err)
assert.equal(err.message, "Unexpected token W")
assert.end()
})
})
test("safeParseTuple valid json", function (assert) {
var t = safeParseTuple("{ \"foo\": true }")
assert.ifError(t[0])
assert.equal(t[1].foo, true)
assert.end()
})
test("safeParseTuple faulty", function (assert) {
var t = safeParseTuple("WRONG")
assert.ok(t[0])
assert.equal(t[0].message, "Unexpected token W")
assert.end()
})
test("safeParseResult valid json", function (assert) {
var t = safeParseResult("{ \"foo\": true }")
assert.ifError(Result.isErr(t))
assert.equal(Result.Ok(t).foo, true)
assert.end()
})
test("safeParseResult faulty", function (assert) {
var t = safeParseResult("WRONG")
assert.ok(Result.Err(t))
assert.equal(Result.Err(t).message, "Unexpected token W")
assert.end()
})