forked from senchalabs/jsduck
/
doc_parser_spec.rb
103 lines (92 loc) · 2.05 KB
/
doc_parser_spec.rb
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
require "jsduck/doc_parser"
describe JsDuck::DocParser do
def parse_single(doc)
return JsDuck::DocParser.new.parse(doc)
end
describe "simple method doc-comment" do
before do
@doc = parse_single(<<-EOS.strip)
/**
* @method foo
* Some docs.
* @param {Number} x doc for x
* @return {String} resulting value
*/
EOS
end
it "produces 3 @tags" do
@doc.length.should == 3
end
describe "@method" do
before do
@tag = @doc[0]
end
it "detects tagname" do
@tag[:tagname].should == :method
end
it "detects name" do
@tag[:name].should == "foo"
end
it "detects doc" do
@tag[:doc].should == "Some docs."
end
end
describe "@param" do
before do
@tag = @doc[1]
end
it "detects tagname" do
@tag[:tagname].should == :param
end
it "detects name" do
@tag[:name].should == "x"
end
it "detects type" do
@tag[:type].should == "Number"
end
it "detects doc" do
@tag[:doc].should == "doc for x"
end
end
describe "@return" do
before do
@tag = @doc[2]
end
it "detects tagname" do
@tag[:tagname].should == :return
end
it "detects type" do
@tag[:type].should == "String"
end
it "detects doc" do
@tag[:doc].should == "resulting value"
end
end
end
describe "@type without curlies" do
before do
@tag = parse_single(<<-EOS.strip)[0]
/**
* @type Boolean|String
*/
EOS
end
it "detects tagname" do
@tag[:tagname].should == :type
end
it "detects tagname" do
@tag[:type].should == "Boolean|String"
end
end
describe "single-line doc-comment" do
before do
@tag = parse_single("/** @event blah */")[0]
end
it "detects tagname" do
@tag[:tagname].should == :event
end
it "detects name" do
@tag[:name].should == "blah"
end
end
end