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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
"use strict"
var test = require("tap").test
var validate = require("../index.js")
function thrown (t, code, msg, todo) {
validate("OSSF", arguments)
try {
todo()
t.fail(msg)
}
catch (e) {
t.is(e.code, code, msg + e.message)
}
}
function notThrown (t, msg, todo) {
validate("OSF", arguments)
try {
todo()
t.pass(msg)
}
catch (e) {
t.fail(msg+"\n"+e.stack)
}
}
test("general", function (t) {
t.plan(69)
var values = {
"A": [],
"S": "test",
"N": 123,
"F": function () {},
"O": {},
"B": false,
"E": new Error()
}
Object.keys(values).forEach(function (type) {
Object.keys(values).forEach(function (contraType) {
if (type === contraType) {
notThrown(t, type + " matches " + contraType, function () {
validate(type, [values[contraType]])
})
}
else {
thrown(t, "EINVALIDTYPE", type + " does not match " + contraType, function () {
validate(type, [values[contraType]])
})
}
})
if (type === "E") {
notThrown(t, "null is ok for E", function () {
validate(type, [null])
})
}
else {
thrown(t, "EMISSINGARG", "null not ok for "+type, function () {
validate(type, [null])
})
}
})
Object.keys(values).forEach(function (contraType) {
notThrown(t, "* matches " + contraType, function () {
validate("*", [values[contraType]])
})
})
thrown(t, "EMISSINGARG", "not enough args", function () {
validate("SNF", ["abc", 123])
})
thrown(t, "ETOOMANYARGS", "too many args", function () {
validate("SNF", ["abc", 123, function () {}, true])
})
notThrown(t, "E matches null", function () {
validate("E", [null])
})
notThrown(t, "E matches undefined", function () {
validate("E", [undefined])
})
notThrown(t, "E w/ error requires nothing else", function () {
validate("ESN", [new Error(), "foo"])
})
thrown(t, "EMISSINGARG", "E w/o error works as usual", function () {
validate("ESN", [null, "foo"])
})
})
|