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.dart'); |
| 9 #import('../markdown.dart', prefix: 'md'); |
9 | 10 |
10 // TODO(rnystrom): Better path to unittest. | 11 // TODO(rnystrom): Better path to unittest. |
11 #import('../../../client/testing/unittest/unittest_node.dart'); | 12 #import('../../../client/testing/unittest/unittest_node.dart'); |
| 13 #import('../../../frog/lang.dart'); |
| 14 #import('../../../frog/file_system_node.dart'); |
12 | 15 |
13 main() { | 16 main() { |
| 17 var files = new NodeFileSystem(); |
| 18 parseOptions('../../frog', [], files); |
| 19 initializeWorld(files); |
| 20 |
14 group('countOccurrences', () { | 21 group('countOccurrences', () { |
15 test('empty text returns 0', () { | 22 test('empty text returns 0', () { |
16 expect(countOccurrences('', 'needle')).equals(0); | 23 expect(countOccurrences('', 'needle')).equals(0); |
17 }); | 24 }); |
18 | 25 |
19 test('one occurrence', () { | 26 test('one occurrence', () { |
20 expect(countOccurrences('bananarama', 'nara')).equals(1); | 27 expect(countOccurrences('bananarama', 'nara')).equals(1); |
21 }); | 28 }); |
22 | 29 |
23 test('multiple occurrences', () { | 30 test('multiple occurrences', () { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 expect(relativePath('other/sub/file.html')).equals( | 109 expect(relativePath('other/sub/file.html')).equals( |
103 '../../other/sub/file.html'); | 110 '../../other/sub/file.html'); |
104 }); | 111 }); |
105 | 112 |
106 test('from nested to directory with different path', () { | 113 test('from nested to directory with different path', () { |
107 startFile('dir/sub/file.html'); | 114 startFile('dir/sub/file.html'); |
108 expect(relativePath('other/file.html')).equals( | 115 expect(relativePath('other/file.html')).equals( |
109 '../../other/file.html'); | 116 '../../other/file.html'); |
110 }); | 117 }); |
111 }); | 118 }); |
| 119 |
| 120 group('name reference', () { |
| 121 var doc = new Dartdoc(); |
| 122 doc.document('test/dummy.dart'); |
| 123 var dummy = world.libraries['test/dummy.dart']; |
| 124 var klass = dummy.findTypeByName('Class'); |
| 125 var method = klass.getMember('method'); |
| 126 |
| 127 String render(md.Node node) => md.renderToHtml([node]); |
| 128 |
| 129 test('to a parameter of the current method', () { |
| 130 expect(render(doc.resolveNameReference('param', currentMember: method))). |
| 131 equals('<span class="param">param</span>'); |
| 132 }); |
| 133 |
| 134 test('to a member of the current type', () { |
| 135 expect(render(doc.resolveNameReference('method', currentType: klass))). |
| 136 equals('<a href="../../dummy/Class.html#method" class="crossref">' + |
| 137 'method</a>'); |
| 138 }); |
| 139 |
| 140 test('to a property with only a getter links to the getter', () { |
| 141 expect(render(doc.resolveNameReference('getterOnly', |
| 142 currentType: klass))). |
| 143 equals('<a href="../../dummy/Class.html#get:getterOnly" ' + |
| 144 'class="crossref">getterOnly</a>'); |
| 145 }); |
| 146 |
| 147 test('to a property with only a setter links to the setter', () { |
| 148 expect(render(doc.resolveNameReference('setterOnly', |
| 149 currentType: klass))). |
| 150 equals('<a href="../../dummy/Class.html#set:setterOnly" ' + |
| 151 'class="crossref">setterOnly</a>'); |
| 152 }); |
| 153 |
| 154 test('to a property with a getter and setter links to the getter', () { |
| 155 expect(render(doc.resolveNameReference('getterAndSetter', |
| 156 currentType: klass))). |
| 157 equals('<a href="../../dummy/Class.html#get:getterAndSetter" ' + |
| 158 'class="crossref">getterAndSetter</a>'); |
| 159 }); |
| 160 |
| 161 test('to a type in the current library', () { |
| 162 expect(render(doc.resolveNameReference('Class', currentLibrary: dummy))). |
| 163 equals('<a href="../../dummy/Class.html" class="crossref">Class</a>'); |
| 164 }); |
| 165 |
| 166 test('to a top-level member in the current library', () { |
| 167 expect(render(doc.resolveNameReference('topLevelMethod', |
| 168 currentLibrary: dummy))). |
| 169 equals('<a href="../../dummy.html#topLevelMethod" class="crossref">' + |
| 170 'topLevelMethod</a>'); |
| 171 }); |
| 172 |
| 173 test('to an unknown name', () { |
| 174 expect(render(doc.resolveNameReference('unknownName', |
| 175 currentLibrary: dummy, currentType: klass, |
| 176 currentMember: method))). |
| 177 equals('<code>unknownName</code>'); |
| 178 }); |
| 179 }); |
112 } | 180 } |
OLD | NEW |