-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
153 lines (148 loc) · 4.33 KB
/
test.js
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
var assert = require("assert");
var WUD = require("./whatsupdoc");
[
{
name: "first line comment",
input: " /**/ foo",
check: function (output) {
assert.equal(output.length, 1);
assert.equal(output[0].lineNo, 1);
assert.equal(output[0].comment, "");
assert.equal(output[0].code, " foo");
}
},
{
name: "second line comment",
input: "\n /**/ foo",
check: function (output) {
assert.equal(output.length, 1);
assert.equal(output[0].lineNo, 2);
assert.equal(output[0].comment, "");
assert.equal(output[0].code, " foo");
}
}
].forEach(function (test, index) {
exports['test ' + (test.name || index)] = function () {
test.check(WUD.comments(test.input));
};
});
[
{
name: "empty module",
input: "",
check: function (output) {
assert.equal(output.children.length, 0);
}
},
{
name: "name argument respected",
input: "",
id: "foo",
check: function (output) {
assert.equal(output.id, "foo");
assert.equal(output.name, "foo");
}
},
{
name: "non-doc comment ignored",
input: "/**/",
check: function (output) {
assert.equal(output.children.length, 0);
}
},
{
name: "empty code comment",
input: "/** */",
check: function (output) {
assert.equal(output.children.length, 1);
var child = output.children[0];
assert.equal(child.doc, "");
}
},
{
name: "explicit @name accepted",
input: "/** @name blah */",
check: function (output) {
assert.equal(output.children[0].name, "blah");
}
},
{
name: "content of single doc with line feed",
input: " /** hi \n*/",
check: function (output) {
assert.equal(output.children.length, 1);
assert.equal(output.children[0].doc, "hi");
}
},
{
name: "multi-line doc in asterisk box style",
input: "/**\n" +
" * hi\n" +
" */",
check: function (output) {
assert.equal(output.children.length, 1);
assert.equal(output.children[0].doc, "hi");
}
},
{
name: "multi-line doc in indent style",
input: "/**\n" +
" hi\n" +
"*/",
check: function (output) {
assert.equal(output.children.length, 1);
assert.equal(output.children[0].doc, "hi");
}
},
{
name: "multi-line doc preserving initial space on second line",
input: "/** leader\n" +
" - hi\n" +
"*/",
check: function (output) {
assert.equal(output.children.length, 1);
assert.equal(output.children[0].doc, "leader\n - hi");
}
},
{
name: "indented multi-line doc preserving initial space on second line",
input: " /** leader\n" +
" - hi\n" +
" */",
check: function (output) {
assert.equal(output.children.length, 1);
assert.equal(output.children[0].doc, "leader\n - hi");
}
},
{
name: "mixed tab indented multi-line doc preserving initial space on second line",
input: " /** leader\n" +
"\t - hi\n" +
" */",
check: function (output) {
assert.equal(output.children.length, 1);
assert.equal(output.children[0].doc, "leader\n - hi");
}
},
{
name: "name inferred from first assignment in code",
input: "/***/\nvar blah = {};",
check: function (output) {
assert.equal(output.children[0].name, "blah");
}
},
{
name: "name inferred from export assignment in code",
input: "/***/\nexports.blah = {};",
check: function (output) {
assert.equal(output.children[0].name, "blah");
}
}
].forEach(function (test, index) {
exports['test ' + (test.name || index)] = function () {
test.check(WUD.parseModule(test.input, test.id));
};
});
if (require.main == module) {
require("test").run(exports);
}