| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 dartdoc. |
| 6 #library('dartdoc_tests'); | 6 #library('dartdoc_tests'); |
| 7 | 7 |
| 8 #import('../dartdoc.dart'); | 8 #import('../../../dartdoc/dartdoc.dart'); |
| 9 #import('../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 |
| 16 main() { | 16 main() { |
| 17 var files = new NodeFileSystem(); | 17 var files = new NodeFileSystem(); |
| 18 parseOptions('../../frog', [], files); | 18 parseOptions('../../frog', [], files); |
| 19 initializeWorld(files); | 19 initializeWorld(files); |
| 20 | 20 |
| 21 group('countOccurrences', () { | 21 group('countOccurrences', () { |
| 22 test('empty text returns 0', () { | 22 test('empty text returns 0', () { |
| 23 expect(countOccurrences('', 'needle')).equals(0); | 23 expect(countOccurrences('', 'needle')).equals(0); |
| 24 }); | 24 }); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 }); | 111 }); |
| 112 | 112 |
| 113 test('from nested to directory with different path', () { | 113 test('from nested to directory with different path', () { |
| 114 startFile('dir/sub/file.html'); | 114 startFile('dir/sub/file.html'); |
| 115 expect(relativePath('other/file.html')).equals( | 115 expect(relativePath('other/file.html')).equals( |
| 116 '../../other/file.html'); | 116 '../../other/file.html'); |
| 117 }); | 117 }); |
| 118 }); | 118 }); |
| 119 | 119 |
| 120 group('name reference', () { | 120 group('name reference', () { |
| 121 // TODO(rnystrom): The paths here are a bit strange. They're relative to |
| 122 // where test.dart happens to be invoked from. |
| 123 final dummyPath = 'utils/tests/dartdoc/src/dummy.dart'; |
| 124 |
| 125 // 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 |
| 127 // *invoked* from and not relative to *this* file like we'd like. That |
| 128 // means these tests only run correctly from one place. Unfortunately, |
| 129 // test.py/test.dart runs this from one directory and frog/presubmit.py |
| 130 // runs it from another. |
| 131 // See Bug 1145. |
| 132 var fileSystem = new NodeFileSystem(); |
| 133 if (!fileSystem.fileExists(dummyPath)) { |
| 134 print("Can't run dartdoc name reference tests because dummy.dart " + |
| 135 "could not be found."); |
| 136 return; |
| 137 } |
| 138 |
| 121 var doc = new Dartdoc(); | 139 var doc = new Dartdoc(); |
| 122 doc.document('test/dummy.dart'); | 140 world.processDartScript(dummyPath); |
| 123 var dummy = world.libraries['test/dummy.dart']; | 141 world.resolveAll(); |
| 142 var dummy = world.libraries[dummyPath]; |
| 124 var klass = dummy.findTypeByName('Class'); | 143 var klass = dummy.findTypeByName('Class'); |
| 125 var method = klass.getMember('method'); | 144 var method = klass.getMember('method'); |
| 126 | 145 |
| 127 String render(md.Node node) => md.renderToHtml([node]); | 146 String render(md.Node node) => md.renderToHtml([node]); |
| 128 | 147 |
| 129 test('to a parameter of the current method', () { | 148 test('to a parameter of the current method', () { |
| 130 expect(render(doc.resolveNameReference('param', member: method))). | 149 expect(render(doc.resolveNameReference('param', member: method))). |
| 131 equals('<span class="param">param</span>'); | 150 equals('<span class="param">param</span>'); |
| 132 }); | 151 }); |
| 133 | 152 |
| 134 test('to a member of the current type', () { | 153 test('to a member of the current type', () { |
| 135 expect(render(doc.resolveNameReference('method', type: klass))). | 154 expect(render(doc.resolveNameReference('method', type: klass))). |
| 136 equals('<a href="../../dummy/Class.html#method" class="crossref">' + | 155 equals('<a class="crossref" href="../../dummy/Class.html#method">' + |
| 137 'method</a>'); | 156 'method</a>'); |
| 138 }); | 157 }); |
| 139 | 158 |
| 140 test('to a property with only a getter links to the getter', () { | 159 test('to a property with only a getter links to the getter', () { |
| 141 expect(render(doc.resolveNameReference('getterOnly', type: klass))). | 160 expect(render(doc.resolveNameReference('getterOnly', type: klass))). |
| 142 equals('<a href="../../dummy/Class.html#get:getterOnly" ' + | 161 equals('<a class="crossref" ' + |
| 143 'class="crossref">getterOnly</a>'); | 162 'href="../../dummy/Class.html#get:getterOnly">getterOnly</a>'); |
| 144 }); | 163 }); |
| 145 | 164 |
| 146 test('to a property with only a setter links to the setter', () { | 165 test('to a property with only a setter links to the setter', () { |
| 147 expect(render(doc.resolveNameReference('setterOnly', type: klass))). | 166 expect(render(doc.resolveNameReference('setterOnly', type: klass))). |
| 148 equals('<a href="../../dummy/Class.html#set:setterOnly" ' + | 167 equals('<a class="crossref" ' + |
| 149 'class="crossref">setterOnly</a>'); | 168 'href="../../dummy/Class.html#set:setterOnly">setterOnly</a>'); |
| 150 }); | 169 }); |
| 151 | 170 |
| 152 test('to a property with a getter and setter links to the getter', () { | 171 test('to a property with a getter and setter links to the getter', () { |
| 153 expect(render(doc.resolveNameReference('getterAndSetter', type: klass))). | 172 expect(render(doc.resolveNameReference('getterAndSetter', type: klass))). |
| 154 equals('<a href="../../dummy/Class.html#get:getterAndSetter" ' + | 173 equals('<a class="crossref" ' + |
| 155 'class="crossref">getterAndSetter</a>'); | 174 'href="../../dummy/Class.html#get:getterAndSetter">' + |
| 175 'getterAndSetter</a>'); |
| 156 }); | 176 }); |
| 157 | 177 |
| 158 test('to a type in the current library', () { | 178 test('to a type in the current library', () { |
| 159 expect(render(doc.resolveNameReference('Class', library: dummy))). | 179 expect(render(doc.resolveNameReference('Class', library: dummy))). |
| 160 equals('<a href="../../dummy/Class.html" class="crossref">Class</a>'); | 180 equals('<a class="crossref" href="../../dummy/Class.html">Class</a>'); |
| 161 }); | 181 }); |
| 162 | 182 |
| 163 test('to a top-level member in the current library', () { | 183 test('to a top-level member in the current library', () { |
| 164 expect(render(doc.resolveNameReference('topLevelMethod', | 184 expect(render(doc.resolveNameReference('topLevelMethod', |
| 165 library: dummy))). | 185 library: dummy))). |
| 166 equals('<a href="../../dummy.html#topLevelMethod" class="crossref">' + | 186 equals('<a class="crossref" href="../../dummy.html#topLevelMethod">' + |
| 167 'topLevelMethod</a>'); | 187 'topLevelMethod</a>'); |
| 168 }); | 188 }); |
| 169 | 189 |
| 170 test('to an unknown name', () { | 190 test('to an unknown name', () { |
| 171 expect(render(doc.resolveNameReference('unknownName', library: dummy, | 191 expect(render(doc.resolveNameReference('unknownName', library: dummy, |
| 172 type: klass, member: method))). | 192 type: klass, member: method))). |
| 173 equals('<code>unknownName</code>'); | 193 equals('<code>unknownName</code>'); |
| 174 }); | 194 }); |
| 175 }); | 195 }); |
| 176 } | 196 } |
| OLD | NEW |