| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 /// Unit tests for doc. |
| 6 #library('dartdoc_tests'); |
| 7 |
| 8 // TODO(rnystrom): Use "package:" URL (#4968). |
| 9 #import('../lib/dartdoc.dart', prefix: 'dd'); |
| 10 #import('../lib/markdown.dart', prefix: 'md'); |
| 11 |
| 12 // TODO(rnystrom): Better path to unittest. |
| 13 #import('../../unittest/unittest.dart'); |
| 14 |
| 15 main() { |
| 16 group('countOccurrences', () { |
| 17 test('empty text returns 0', () { |
| 18 expect(dd.countOccurrences('', 'needle'), equals(0)); |
| 19 }); |
| 20 |
| 21 test('one occurrence', () { |
| 22 expect(dd.countOccurrences('bananarama', 'nara'), equals(1)); |
| 23 }); |
| 24 |
| 25 test('multiple occurrences', () { |
| 26 expect(dd.countOccurrences('bananarama', 'a'), equals(5)); |
| 27 }); |
| 28 |
| 29 test('overlapping matches do not count', () { |
| 30 expect(dd.countOccurrences('bananarama', 'ana'), equals(1)); |
| 31 }); |
| 32 }); |
| 33 |
| 34 group('repeat', () { |
| 35 test('zero times returns an empty string', () { |
| 36 expect(dd.repeat('ba', 0), isEmpty); |
| 37 }); |
| 38 |
| 39 test('one time returns the string', () { |
| 40 expect(dd.repeat('ba', 1), equals('ba')); |
| 41 }); |
| 42 |
| 43 test('multiple times', () { |
| 44 expect(dd.repeat('ba', 3), equals('bababa')); |
| 45 }); |
| 46 |
| 47 test('multiple times with a separator', () { |
| 48 expect(dd.repeat('ba', 3, separator: ' '), equals('ba ba ba')); |
| 49 }); |
| 50 }); |
| 51 |
| 52 group('isAbsolute', () { |
| 53 final doc = new dd.Dartdoc(); |
| 54 |
| 55 test('returns false if there is no scheme', () { |
| 56 expect(doc.isAbsolute('index.html'), isFalse); |
| 57 expect(doc.isAbsolute('foo/index.html'), isFalse); |
| 58 expect(doc.isAbsolute('foo/bar/index.html'), isFalse); |
| 59 }); |
| 60 |
| 61 test('returns true if there is a scheme', () { |
| 62 expect(doc.isAbsolute('http://google.com'), isTrue); |
| 63 expect(doc.isAbsolute('hTtPs://google.com'), isTrue); |
| 64 expect(doc.isAbsolute('mailto:fake@email.com'), isTrue); |
| 65 }); |
| 66 }); |
| 67 |
| 68 group('relativePath', () { |
| 69 final doc = new dd.Dartdoc(); |
| 70 |
| 71 test('absolute path is unchanged', () { |
| 72 doc.startFile('dir/sub/file.html'); |
| 73 expect(doc.relativePath('http://foo.com'), equals('http://foo.com')); |
| 74 }); |
| 75 |
| 76 test('from root to root', () { |
| 77 doc.startFile('root.html'); |
| 78 expect(doc.relativePath('other.html'), equals('other.html')); |
| 79 }); |
| 80 |
| 81 test('from root to directory', () { |
| 82 doc.startFile('root.html'); |
| 83 expect(doc.relativePath('dir/file.html'), equals('dir/file.html')); |
| 84 }); |
| 85 |
| 86 test('from root to nested', () { |
| 87 doc.startFile('root.html'); |
| 88 expect(doc.relativePath('dir/sub/file.html'), equals( |
| 89 'dir/sub/file.html')); |
| 90 }); |
| 91 |
| 92 test('from directory to root', () { |
| 93 doc.startFile('dir/file.html'); |
| 94 expect(doc.relativePath('root.html'), equals('../root.html')); |
| 95 }); |
| 96 |
| 97 test('from nested to root', () { |
| 98 doc.startFile('dir/sub/file.html'); |
| 99 expect(doc.relativePath('root.html'), equals('../../root.html')); |
| 100 }); |
| 101 |
| 102 test('from dir to dir with different path', () { |
| 103 doc.startFile('dir/file.html'); |
| 104 expect(doc.relativePath('other/file.html'), equals('../other/file.html')); |
| 105 }); |
| 106 |
| 107 test('from nested to nested with different path', () { |
| 108 doc.startFile('dir/sub/file.html'); |
| 109 expect(doc.relativePath('other/sub/file.html'), equals( |
| 110 '../../other/sub/file.html')); |
| 111 }); |
| 112 |
| 113 test('from nested to directory with different path', () { |
| 114 doc.startFile('dir/sub/file.html'); |
| 115 expect(doc.relativePath('other/file.html'), equals( |
| 116 '../../other/file.html')); |
| 117 }); |
| 118 }); |
| 119 } |
| OLD | NEW |