Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Side by Side Diff: utils/dartdoc/test/dartdoc_tests.dart

Issue 9147058: Hook up the dartdoc tests to test.py, test.dart, and frog/presubmit.py. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase and upload. Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/dartdoc/html_renderer.dart ('k') | utils/dartdoc/test/dummy.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// Unit tests for dartdoc.
6 #library('dartdoc_tests');
7
8 #import('../dartdoc.dart');
9 #import('../markdown.dart', prefix: 'md');
10
11 // TODO(rnystrom): Better path to unittest.
12 #import('../../../client/testing/unittest/unittest_node.dart');
13 #import('../../../frog/lang.dart');
14 #import('../../../frog/file_system_node.dart');
15
16 main() {
17 var files = new NodeFileSystem();
18 parseOptions('../../frog', [], files);
19 initializeWorld(files);
20
21 group('countOccurrences', () {
22 test('empty text returns 0', () {
23 expect(countOccurrences('', 'needle')).equals(0);
24 });
25
26 test('one occurrence', () {
27 expect(countOccurrences('bananarama', 'nara')).equals(1);
28 });
29
30 test('multiple occurrences', () {
31 expect(countOccurrences('bananarama', 'a')).equals(5);
32 });
33
34 test('overlapping matches do not count', () {
35 expect(countOccurrences('bananarama', 'ana')).equals(1);
36 });
37 });
38
39 group('repeat', () {
40 test('zero times returns an empty string', () {
41 expect(repeat('ba', 0)).equals('');
42 });
43
44 test('one time returns the string', () {
45 expect(repeat('ba', 1)).equals('ba');
46 });
47
48 test('multiple times', () {
49 expect(repeat('ba', 3)).equals('bababa');
50 });
51
52 test('multiple times with a separator', () {
53 expect(repeat('ba', 3, separator: ' ')).equals('ba ba ba');
54 });
55 });
56
57 group('isAbsolute', () {
58 test('returns false if there is no scheme', () {
59 expect(isAbsolute('index.html')).isFalse();
60 expect(isAbsolute('foo/index.html')).isFalse();
61 expect(isAbsolute('foo/bar/index.html')).isFalse();
62 });
63
64 test('returns true if there is a scheme', () {
65 expect(isAbsolute('http://google.com')).isTrue();
66 expect(isAbsolute('hTtPs://google.com')).isTrue();
67 expect(isAbsolute('mailto:fake@email.com')).isTrue();
68 });
69 });
70
71 group('relativePath', () {
72 test('absolute path is unchanged', () {
73 startFile('dir/sub/file.html');
74 expect(relativePath('http://google.com')).equals('http://google.com');
75 });
76
77 test('from root to root', () {
78 startFile('root.html');
79 expect(relativePath('other.html')).equals('other.html');
80 });
81
82 test('from root to directory', () {
83 startFile('root.html');
84 expect(relativePath('dir/file.html')).equals('dir/file.html');
85 });
86
87 test('from root to nested', () {
88 startFile('root.html');
89 expect(relativePath('dir/sub/file.html')).equals('dir/sub/file.html');
90 });
91
92 test('from directory to root', () {
93 startFile('dir/file.html');
94 expect(relativePath('root.html')).equals('../root.html');
95 });
96
97 test('from nested to root', () {
98 startFile('dir/sub/file.html');
99 expect(relativePath('root.html')).equals('../../root.html');
100 });
101
102 test('from dir to dir with different path', () {
103 startFile('dir/file.html');
104 expect(relativePath('other/file.html')).equals('../other/file.html');
105 });
106
107 test('from nested to nested with different path', () {
108 startFile('dir/sub/file.html');
109 expect(relativePath('other/sub/file.html')).equals(
110 '../../other/sub/file.html');
111 });
112
113 test('from nested to directory with different path', () {
114 startFile('dir/sub/file.html');
115 expect(relativePath('other/file.html')).equals(
116 '../../other/file.html');
117 });
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', member: 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', type: 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', type: klass))).
142 equals('<a href="../../dummy/Class.html#get:getterOnly" ' +
143 'class="crossref">getterOnly</a>');
144 });
145
146 test('to a property with only a setter links to the setter', () {
147 expect(render(doc.resolveNameReference('setterOnly', type: klass))).
148 equals('<a href="../../dummy/Class.html#set:setterOnly" ' +
149 'class="crossref">setterOnly</a>');
150 });
151
152 test('to a property with a getter and setter links to the getter', () {
153 expect(render(doc.resolveNameReference('getterAndSetter', type: klass))).
154 equals('<a href="../../dummy/Class.html#get:getterAndSetter" ' +
155 'class="crossref">getterAndSetter</a>');
156 });
157
158 test('to a type in the current library', () {
159 expect(render(doc.resolveNameReference('Class', library: dummy))).
160 equals('<a href="../../dummy/Class.html" class="crossref">Class</a>');
161 });
162
163 test('to a top-level member in the current library', () {
164 expect(render(doc.resolveNameReference('topLevelMethod',
165 library: dummy))).
166 equals('<a href="../../dummy.html#topLevelMethod" class="crossref">' +
167 'topLevelMethod</a>');
168 });
169
170 test('to an unknown name', () {
171 expect(render(doc.resolveNameReference('unknownName', library: dummy,
172 type: klass, member: method))).
173 equals('<code>unknownName</code>');
174 });
175 });
176 }
OLDNEW
« no previous file with comments | « utils/dartdoc/html_renderer.dart ('k') | utils/dartdoc/test/dummy.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698