OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// Unit tests for dartdoc. | 5 /// Unit tests for doc. |
6 #library('dartdoc_tests'); | 6 #library('dartdoc_tests'); |
7 | 7 |
8 #import('../../../dartdoc/dartdoc.dart', prefix: 'dd'); | 8 #import('../../../dartdoc/dartdoc.dart', prefix: 'dd'); |
9 #import('../../../dartdoc/markdown.dart', prefix: 'md'); | 9 #import('../../../dartdoc/markdown.dart', prefix: 'md'); |
10 | 10 |
11 // TODO(rnystrom): Better path to unittest. | 11 // TODO(rnystrom): Better path to unittest. |
12 #import('../../../../client/testing/unittest/unittest_node.dart'); | 12 #import('../../../../client/testing/unittest/unittest_node.dart'); |
13 #import('../../../../frog/lang.dart'); | 13 #import('../../../../frog/lang.dart'); |
14 #import('../../../../frog/file_system_node.dart'); | 14 #import('../../../../frog/file_system_node.dart'); |
15 | 15 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 test('multiple times', () { | 48 test('multiple times', () { |
49 expect(dd.repeat('ba', 3)).equals('bababa'); | 49 expect(dd.repeat('ba', 3)).equals('bababa'); |
50 }); | 50 }); |
51 | 51 |
52 test('multiple times with a separator', () { | 52 test('multiple times with a separator', () { |
53 expect(dd.repeat('ba', 3, separator: ' ')).equals('ba ba ba'); | 53 expect(dd.repeat('ba', 3, separator: ' ')).equals('ba ba ba'); |
54 }); | 54 }); |
55 }); | 55 }); |
56 | 56 |
57 group('isAbsolute', () { | 57 group('isAbsolute', () { |
| 58 final doc = new dd.Dartdoc(); |
| 59 |
58 test('returns false if there is no scheme', () { | 60 test('returns false if there is no scheme', () { |
59 expect(dd.isAbsolute('index.html')).isFalse(); | 61 expect(doc.isAbsolute('index.html')).isFalse(); |
60 expect(dd.isAbsolute('foo/index.html')).isFalse(); | 62 expect(doc.isAbsolute('foo/index.html')).isFalse(); |
61 expect(dd.isAbsolute('foo/bar/index.html')).isFalse(); | 63 expect(doc.isAbsolute('foo/bar/index.html')).isFalse(); |
62 }); | 64 }); |
63 | 65 |
64 test('returns true if there is a scheme', () { | 66 test('returns true if there is a scheme', () { |
65 expect(dd.isAbsolute('http://google.com')).isTrue(); | 67 expect(doc.isAbsolute('http://google.com')).isTrue(); |
66 expect(dd.isAbsolute('hTtPs://google.com')).isTrue(); | 68 expect(doc.isAbsolute('hTtPs://google.com')).isTrue(); |
67 expect(dd.isAbsolute('mailto:fake@email.com')).isTrue(); | 69 expect(doc.isAbsolute('mailto:fake@email.com')).isTrue(); |
68 }); | 70 }); |
69 }); | 71 }); |
70 | 72 |
71 group('relativePath', () { | 73 group('relativePath', () { |
| 74 final doc = new dd.Dartdoc(); |
| 75 |
72 test('absolute path is unchanged', () { | 76 test('absolute path is unchanged', () { |
73 dd.startFile('dir/sub/file.html'); | 77 doc.startFile('dir/sub/file.html'); |
74 expect(dd.relativePath('http://google.com')).equals('http://google.com'); | 78 expect(doc.relativePath('http://foo.com')).equals('http://foo.com'); |
75 }); | 79 }); |
76 | 80 |
77 test('from root to root', () { | 81 test('from root to root', () { |
78 dd.startFile('root.html'); | 82 doc.startFile('root.html'); |
79 expect(dd.relativePath('other.html')).equals('other.html'); | 83 expect(doc.relativePath('other.html')).equals('other.html'); |
80 }); | 84 }); |
81 | 85 |
82 test('from root to directory', () { | 86 test('from root to directory', () { |
83 dd.startFile('root.html'); | 87 doc.startFile('root.html'); |
84 expect(dd.relativePath('dir/file.html')).equals('dir/file.html'); | 88 expect(doc.relativePath('dir/file.html')).equals('dir/file.html'); |
85 }); | 89 }); |
86 | 90 |
87 test('from root to nested', () { | 91 test('from root to nested', () { |
88 dd.startFile('root.html'); | 92 doc.startFile('root.html'); |
89 expect(dd.relativePath('dir/sub/file.html')).equals('dir/sub/file.html'); | 93 expect(doc.relativePath('dir/sub/file.html')).equals( |
| 94 'dir/sub/file.html'); |
90 }); | 95 }); |
91 | 96 |
92 test('from directory to root', () { | 97 test('from directory to root', () { |
93 dd.startFile('dir/file.html'); | 98 doc.startFile('dir/file.html'); |
94 expect(dd.relativePath('root.html')).equals('../root.html'); | 99 expect(doc.relativePath('root.html')).equals('../root.html'); |
95 }); | 100 }); |
96 | 101 |
97 test('from nested to root', () { | 102 test('from nested to root', () { |
98 dd.startFile('dir/sub/file.html'); | 103 doc.startFile('dir/sub/file.html'); |
99 expect(dd.relativePath('root.html')).equals('../../root.html'); | 104 expect(doc.relativePath('root.html')).equals('../../root.html'); |
100 }); | 105 }); |
101 | 106 |
102 test('from dir to dir with different path', () { | 107 test('from dir to dir with different path', () { |
103 dd.startFile('dir/file.html'); | 108 doc.startFile('dir/file.html'); |
104 expect(dd.relativePath('other/file.html')).equals('../other/file.html'); | 109 expect(doc.relativePath('other/file.html')).equals( |
| 110 '../other/file.html'); |
105 }); | 111 }); |
106 | 112 |
107 test('from nested to nested with different path', () { | 113 test('from nested to nested with different path', () { |
108 dd.startFile('dir/sub/file.html'); | 114 doc.startFile('dir/sub/file.html'); |
109 expect(dd.relativePath('other/sub/file.html')).equals( | 115 expect(doc.relativePath('other/sub/file.html')).equals( |
110 '../../other/sub/file.html'); | 116 '../../other/sub/file.html'); |
111 }); | 117 }); |
112 | 118 |
113 test('from nested to directory with different path', () { | 119 test('from nested to directory with different path', () { |
114 dd.startFile('dir/sub/file.html'); | 120 doc.startFile('dir/sub/file.html'); |
115 expect(dd.relativePath('other/file.html')).equals( | 121 expect(doc.relativePath('other/file.html')).equals( |
116 '../../other/file.html'); | 122 '../../other/file.html'); |
117 }); | 123 }); |
118 }); | 124 }); |
119 | 125 |
120 group('name reference', () { | 126 group('name reference', () { |
121 // TODO(rnystrom): The paths here are a bit strange. They're relative to | 127 // TODO(rnystrom): The paths here are a bit strange. They're relative to |
122 // where test.dart happens to be invoked from. | 128 // where test.dart happens to be invoked from. |
123 final dummyPath = 'utils/tests/dartdoc/src/dummy.dart'; | 129 final dummyPath = 'utils/tests/dartdoc/src/dummy.dart'; |
124 | 130 |
125 // TODO(rnystrom): Bail if we couldn't find the test file. The problem is | 131 // TODO(rnystrom): Bail if we couldn't find the test file. The problem is |
126 // that loading dummy.dart is sensitive to the location that dart was | 132 // that loading dummy.dart is sensitive to the location that dart was |
127 // *invoked* from and not relative to *this* file like we'd like. That | 133 // *invoked* from and not relative to *this* file like we'd like. That |
128 // means these tests only run correctly from one place. Unfortunately, | 134 // means these tests only run correctly from one place. Unfortunately, |
129 // test.py/test.dart runs this from one directory and frog/presubmit.py | 135 // test.py/test.dart runs this from one directory and frog/presubmit.py |
130 // runs it from another. | 136 // runs it from another. |
131 // See Bug 1145. | 137 // See Bug 1145. |
132 var fileSystem = new NodeFileSystem(); | 138 var fileSystem = new NodeFileSystem(); |
133 if (!fileSystem.fileExists(dummyPath)) { | 139 if (!fileSystem.fileExists(dummyPath)) { |
134 print("Can't run dartdoc name reference tests because dummy.dart " + | 140 print("Can't run dartdoc name reference tests because dummy.dart " + |
135 "could not be found."); | 141 "could not be found."); |
136 return; | 142 return; |
137 } | 143 } |
138 | 144 |
139 var doc = new dd.Dartdoc(); | 145 var doc = new dd.Dartdoc(); |
| 146 doc.startFile('someLib/someType.html'); |
| 147 |
140 world.processDartScript(dummyPath); | 148 world.processDartScript(dummyPath); |
141 world.resolveAll(); | 149 world.resolveAll(); |
142 var dummy = world.libraries[dummyPath]; | 150 var dummy = world.libraries[dummyPath]; |
143 var klass = dummy.findTypeByName('Class'); | 151 var klass = dummy.findTypeByName('Class'); |
144 var method = klass.getMember('method'); | 152 var method = klass.getMember('method'); |
145 | 153 |
146 String render(md.Node node) => md.renderToHtml([node]); | 154 String render(md.Node node) => md.renderToHtml([node]); |
147 | 155 |
148 test('to a parameter of the current method', () { | 156 test('to a parameter of the current method', () { |
149 expect(render(doc.resolveNameReference('param', member: method))). | 157 expect(render(doc.resolveNameReference('param', member: method))). |
150 equals('<span class="param">param</span>'); | 158 equals('<span class="param">param</span>'); |
151 }); | 159 }); |
152 | 160 |
153 test('to a member of the current type', () { | 161 test('to a member of the current type', () { |
154 expect(render(doc.resolveNameReference('method', type: klass))). | 162 expect(render(doc.resolveNameReference('method', type: klass))). |
155 equals('<a class="crossref" href="../../dummy/Class.html#method">' + | 163 equals('<a class="crossref" href="../dummy/Class.html#method">' + |
156 'method</a>'); | 164 'method</a>'); |
157 }); | 165 }); |
158 | 166 |
159 test('to a property with only a getter links to the getter', () { | 167 test('to a property with only a getter links to the getter', () { |
160 expect(render(doc.resolveNameReference('getterOnly', type: klass))). | 168 expect(render(doc.resolveNameReference('getterOnly', type: klass))). |
161 equals('<a class="crossref" ' + | 169 equals('<a class="crossref" ' + |
162 'href="../../dummy/Class.html#get:getterOnly">getterOnly</a>'); | 170 'href="../dummy/Class.html#get:getterOnly">getterOnly</a>'); |
163 }); | 171 }); |
164 | 172 |
165 test('to a property with only a setter links to the setter', () { | 173 test('to a property with only a setter links to the setter', () { |
166 expect(render(doc.resolveNameReference('setterOnly', type: klass))). | 174 expect(render(doc.resolveNameReference('setterOnly', type: klass))). |
167 equals('<a class="crossref" ' + | 175 equals('<a class="crossref" ' + |
168 'href="../../dummy/Class.html#set:setterOnly">setterOnly</a>'); | 176 'href="../dummy/Class.html#set:setterOnly">setterOnly</a>'); |
169 }); | 177 }); |
170 | 178 |
171 test('to a property with a getter and setter links to the getter', () { | 179 test('to a property with a getter and setter links to the getter', () { |
172 expect(render(doc.resolveNameReference('getterAndSetter', type: klass))). | 180 expect(render(doc.resolveNameReference('getterAndSetter', type: klass))). |
173 equals('<a class="crossref" ' + | 181 equals('<a class="crossref" ' + |
174 'href="../../dummy/Class.html#get:getterAndSetter">' + | 182 'href="../dummy/Class.html#get:getterAndSetter">' + |
175 'getterAndSetter</a>'); | 183 'getterAndSetter</a>'); |
176 }); | 184 }); |
177 | 185 |
178 test('to a type in the current library', () { | 186 test('to a type in the current library', () { |
179 expect(render(doc.resolveNameReference('Class', library: dummy))). | 187 expect(render(doc.resolveNameReference('Class', library: dummy))). |
180 equals('<a class="crossref" href="../../dummy/Class.html">Class</a>'); | 188 equals('<a class="crossref" href="../dummy/Class.html">Class</a>'); |
181 }); | 189 }); |
182 | 190 |
183 test('to a top-level member in the current library', () { | 191 test('to a top-level member in the current library', () { |
184 expect(render(doc.resolveNameReference('topLevelMethod', | 192 expect(render(doc.resolveNameReference('topLevelMethod', |
185 library: dummy))). | 193 library: dummy))). |
186 equals('<a class="crossref" href="../../dummy.html#topLevelMethod">' + | 194 equals('<a class="crossref" href="../dummy.html#topLevelMethod">' + |
187 'topLevelMethod</a>'); | 195 'topLevelMethod</a>'); |
188 }); | 196 }); |
189 | 197 |
190 test('to an unknown name', () { | 198 test('to an unknown name', () { |
191 expect(render(doc.resolveNameReference('unknownName', library: dummy, | 199 expect(render(doc.resolveNameReference('unknownName', library: dummy, |
192 type: klass, member: method))). | 200 type: klass, member: method))). |
193 equals('<code>unknownName</code>'); | 201 equals('<code>unknownName</code>'); |
194 }); | 202 }); |
195 | 203 |
196 test('to a member of another class', () { | 204 test('to a member of another class', () { |
197 expect(render(doc.resolveNameReference('Class.method', library: dummy))). | 205 expect(render(doc.resolveNameReference('Class.method', library: dummy))). |
198 equals('<a class="crossref" href="../../dummy/Class.html#method">' + | 206 equals('<a class="crossref" href="../dummy/Class.html#method">' + |
199 'Class.method</a>'); | 207 'Class.method</a>'); |
200 }); | 208 }); |
201 | 209 |
202 test('to a constructor', () { | 210 test('to a constructor', () { |
203 expect(render(doc.resolveNameReference('new Class', library: dummy))). | 211 expect(render(doc.resolveNameReference('new Class', library: dummy))). |
204 equals('<a class="crossref" href="../../dummy/Class.html#new:Class">' + | 212 equals('<a class="crossref" href="../dummy/Class.html#new:Class">' + |
205 'new Class</a>'); | 213 'new Class</a>'); |
206 }); | 214 }); |
207 | 215 |
208 test('to a named constructor', () { | 216 test('to a named constructor', () { |
209 expect(render(doc.resolveNameReference('new Class.namedConstructor', | 217 expect(render(doc.resolveNameReference('new Class.namedConstructor', |
210 library: dummy))). | 218 library: dummy))). |
211 equals('<a class="crossref" ' + | 219 equals('<a class="crossref" ' + |
212 'href="../../dummy/Class.html#new:Class.namedConstructor">new ' + | 220 'href="../dummy/Class.html#new:Class.namedConstructor">new ' + |
213 'Class.namedConstructor</a>'); | 221 'Class.namedConstructor</a>'); |
214 }); | 222 }); |
215 }); | 223 }); |
216 } | 224 } |
OLD | NEW |