Newer
Older
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
153
154
155
156
157
158
159
160
161
require "jsduck/aggregator"
require "jsduck/source_file"
require "jsduck/class"
require "jsduck/relations"
require "jsduck/chainable"
describe JsDuck::Aggregator do
def parse(string)
agr = JsDuck::Aggregator.new
agr.aggregate(JsDuck::SourceFile.new(string))
relations = JsDuck::Relations.new(agr.result.map {|doc| JsDuck::Class.new(doc) })
JsDuck::Chainable.auto_detect(relations)
relations
end
describe "both @return this and @chainable in method doc" do
let(:cls) do
parse(<<-EOS)["MyClass"]
/** */
Ext.define("MyClass", {
/**
* @return {MyClass} this The instance itself.
* @chainable
*/
bar: function() {}
});
EOS
end
it "detects method as chainable" do
cls[:members][0][:meta][:chainable].should == true
end
it "keeps the original @return docs" do
cls[:members][0][:return][:doc].should == "this The instance itself."
end
end
describe "simple @chainable in method doc" do
let(:cls) do
parse(<<-EOS)["MyClass"]
/** */
Ext.define("MyClass", {
/**
* @chainable
*/
bar: function() {}
});
EOS
end
it "detects method as chainable" do
cls[:members][0][:meta][:chainable].should == true
end
it "adds @return {MyClass} this" do
cls[:members][0][:return][:type].should == "MyClass"
cls[:members][0][:return][:doc].should == "this"
end
end
describe "an @return {MyClass} this in method doc" do
let(:cls) do
parse(<<-EOS)["MyClass"]
/** */
Ext.define("MyClass", {
/**
* @return {MyClass} this
*/
bar: function() {}
});
EOS
end
it "detects @return {MyClass} this" do
cls[:members][0][:return][:type].should == "MyClass"
cls[:members][0][:return][:doc].should == "this"
end
it "adds @chainable tag" do
cls[:members][0][:meta][:chainable].should == true
end
end
describe "an @return {MyClass} this and other docs in method doc" do
let(:cls) do
parse(<<-EOS)["MyClass"]
/** */
Ext.define("MyClass", {
/**
* @return {MyClass} this and some more...
*/
bar: function() {}
});
EOS
end
it "detects @return {MyClass} this" do
cls[:members][0][:return][:type].should == "MyClass"
cls[:members][0][:return][:doc].should == "this and some more..."
end
it "adds @chainable tag" do
cls[:members][0][:meta][:chainable].should == true
end
end
describe "an @return {MyClass} thisBlah in method doc" do
let(:cls) do
parse(<<-EOS)["MyClass"]
/** */
Ext.define("MyClass", {
/**
* @return {MyClass} thisBlah
*/
bar: function() {}
});
EOS
end
it "doesn't add @chainable tag" do
cls[:members][0][:meta][:chainable].should_not == true
end
end
describe "an @return {OtherClass} this in method doc" do
let(:cls) do
parse(<<-EOS)["MyClass"]
/** */
Ext.define("MyClass", {
/**
* @return {OtherClass} this
*/
bar: function() {}
});
EOS
end
it "doesn't add @chainable tag" do
cls[:members][0][:meta][:chainable].should_not == true
end
end
describe "an @return {MyClass} no-this in method doc" do
let(:cls) do
parse(<<-EOS)["MyClass"]
/** */
Ext.define("MyClass", {
/**
* @return {MyClass}
*/
bar: function() {}
});
EOS
end
it "doesn't add @chainable tag" do
cls[:members][0][:meta][:chainable].should_not == true
end
end
describe "function with 'return this;' in code" do
let(:cls) do
parse(<<-EOS)["MyClass"]
/** */
Ext.define("MyClass", {
/** */
bar: function() { return this; }
});
EOS
end
it "adds @chainable tag" do
cls[:members][0][:meta][:chainable].should == true
end
it "adds @return {MyClass} this" do
cls[:members][0][:return][:type].should == "MyClass"
cls[:members][0][:return][:doc].should == "this"
end
end