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 doc. | 5 /// Unit tests for doc. |
6 library dartdocTests; | 6 library dartdocTests; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 | 10 |
11 import 'package:pathos/path.dart' as path; | 11 import 'package:pathos/path.dart' as path; |
12 import 'package:unittest/unittest.dart'; | 12 import 'package:unittest/unittest.dart'; |
13 | 13 |
14 // TODO(rnystrom): Use "package:" URL (#4968). | 14 // TODO(rnystrom): Use "package:" URL (#4968). |
15 import '../lib/dartdoc.dart' as dd; | 15 import '../lib/dartdoc.dart' as dd; |
16 import '../lib/markdown.dart'; | 16 import '../lib/markdown.dart'; |
17 import 'markdown_test.dart'; | 17 import 'markdown_test.dart'; |
18 | 18 |
19 main() { | 19 main() { |
| 20 group('countOccurrences', () { |
| 21 test('empty text returns 0', () { |
| 22 expect(dd.countOccurrences('', 'needle'), equals(0)); |
| 23 }); |
| 24 |
| 25 test('one occurrence', () { |
| 26 expect(dd.countOccurrences('bananarama', 'nara'), equals(1)); |
| 27 }); |
| 28 |
| 29 test('multiple occurrences', () { |
| 30 expect(dd.countOccurrences('bananarama', 'a'), equals(5)); |
| 31 }); |
| 32 |
| 33 test('overlapping matches do not count', () { |
| 34 expect(dd.countOccurrences('bananarama', 'ana'), equals(1)); |
| 35 }); |
| 36 }); |
| 37 |
| 38 group('repeat', () { |
| 39 test('zero times returns an empty string', () { |
| 40 expect(dd.repeat('ba', 0), isEmpty); |
| 41 }); |
| 42 |
| 43 test('one time returns the string', () { |
| 44 expect(dd.repeat('ba', 1), equals('ba')); |
| 45 }); |
| 46 |
| 47 test('multiple times', () { |
| 48 expect(dd.repeat('ba', 3), equals('bababa')); |
| 49 }); |
| 50 |
| 51 test('multiple times with a separator', () { |
| 52 expect(dd.repeat('ba', 3, separator: ' '), equals('ba ba ba')); |
| 53 }); |
| 54 }); |
| 55 |
20 group('isAbsolute', () { | 56 group('isAbsolute', () { |
21 final doc = new dd.Dartdoc(); | 57 final doc = new dd.Dartdoc(); |
22 | 58 |
23 test('returns false if there is no scheme', () { | 59 test('returns false if there is no scheme', () { |
24 expect(doc.isAbsolute('index.html'), isFalse); | 60 expect(doc.isAbsolute('index.html'), isFalse); |
25 expect(doc.isAbsolute('foo/index.html'), isFalse); | 61 expect(doc.isAbsolute('foo/index.html'), isFalse); |
26 expect(doc.isAbsolute('foo/bar/index.html'), isFalse); | 62 expect(doc.isAbsolute('foo/bar/index.html'), isFalse); |
27 }); | 63 }); |
28 | 64 |
29 test('returns true if there is a scheme', () { | 65 test('returns true if there is a scheme', () { |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 } | 309 } |
274 } | 310 } |
275 | 311 |
276 | 312 |
277 validateDartdocMarkdown(String description, String markdown, | 313 validateDartdocMarkdown(String description, String markdown, |
278 String html) { | 314 String html) { |
279 var dartdoc = new dd.Dartdoc(); | 315 var dartdoc = new dd.Dartdoc(); |
280 validate(description, markdown, html, linkResolver: dartdoc.dartdocResolver, | 316 validate(description, markdown, html, linkResolver: dartdoc.dartdocResolver, |
281 inlineSyntaxes: dartdoc.dartdocSyntaxes); | 317 inlineSyntaxes: dartdoc.dartdocSyntaxes); |
282 } | 318 } |
OLD | NEW |