Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016, 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 library analyzer.test.src.util.fast_uri_test; | |
| 6 | |
| 7 import 'package:analyzer/src/util/fast_uri.dart'; | |
| 8 import 'package:unittest/unittest.dart'; | |
| 9 | |
| 10 import '../../reflective_tests.dart'; | |
| 11 import '../../utils.dart'; | |
| 12 | |
| 13 main() { | |
| 14 initializeTestEnvironment(); | |
| 15 runReflectiveTests(_FastUriTest); | |
| 16 } | |
| 17 | |
| 18 @reflectiveTest | |
| 19 class _FastUriTest { | |
|
Paul Berry
2016/05/20 16:18:11
Include test cases for:
- URI ending in '/'
- URI
scheglov
2016/05/20 16:47:23
Done.
| |
| 20 static final isInstanceOf<FastUri> isFastUri = new isInstanceOf<FastUri>(); | |
| 21 | |
| 22 void test_parse_absolute_dart() { | |
| 23 _compareTextWithCoreUri('dart:core'); | |
| 24 } | |
| 25 | |
| 26 void test_parse_absolute_file() { | |
| 27 _compareTextWithCoreUri('file:///Users/scheglov/util/fast_uri.dart'); | |
| 28 } | |
| 29 | |
| 30 void test_parse_absolute_package() { | |
| 31 _compareTextWithCoreUri('package:analyzer/src/util/fast_uri.dart'); | |
| 32 } | |
| 33 | |
| 34 void test_parse_notFast() { | |
| 35 Uri uri = FastUri.parse('http://www.google.com:8080/pages/about.html'); | |
| 36 expect(uri, isNot(isFastUri)); | |
| 37 } | |
| 38 | |
| 39 void test_parse_relative_down() { | |
| 40 _compareTextWithCoreUri('util/fast_uri.dart'); | |
| 41 } | |
| 42 | |
| 43 void test_parse_relative_up() { | |
| 44 _compareTextWithCoreUri('../util/fast_uri.dart'); | |
| 45 } | |
| 46 | |
| 47 void test_resolve() { | |
| 48 Uri uri1 = FastUri.parse('package:analyzer/aaa/bbbb/c.dart'); | |
| 49 Uri uri2 = uri1.resolve('dd.dart'); | |
| 50 _compareUris(uri2, Uri.parse('package:analyzer/aaa/bbbb/dd.dart')); | |
| 51 } | |
| 52 | |
| 53 void test_resolveUri_nameStartsWithOneDot() { | |
| 54 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', '.name.dart', | |
| 55 'package:analyzer/aaa/bbbb/.name.dart'); | |
| 56 } | |
| 57 | |
| 58 void test_resolveUri_nameStartsWithTwoDots() { | |
| 59 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', '..name.dart', | |
| 60 'package:analyzer/aaa/bbbb/..name.dart'); | |
| 61 } | |
| 62 | |
| 63 void test_resolveUri_onlyName() { | |
| 64 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', 'dd.dart', | |
| 65 'package:analyzer/aaa/bbbb/dd.dart'); | |
| 66 } | |
| 67 | |
| 68 void test_resolveUri_pathHasOneDot() { | |
| 69 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', 'dd/./ee.dart', | |
| 70 'package:analyzer/aaa/bbbb/dd/ee.dart'); | |
| 71 } | |
| 72 | |
| 73 void test_resolveUri_pathHasTwoDots() { | |
| 74 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', 'dd/../ee.dart', | |
| 75 'package:analyzer/aaa/bbbb/ee.dart'); | |
| 76 } | |
| 77 | |
| 78 void test_resolveUri_pathStartsWithOneDot() { | |
| 79 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', './ddd.dart', | |
| 80 'package:analyzer/aaa/bbbb/ddd.dart'); | |
| 81 } | |
| 82 | |
| 83 void test_resolveUri_pathStartsWithTwoDots() { | |
| 84 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', '../ddd.dart', | |
| 85 'package:analyzer/aaa/ddd.dart'); | |
| 86 } | |
| 87 | |
| 88 void test_resolveUri_pathWithSubFolder() { | |
| 89 Uri uri1 = FastUri.parse('package:analyzer/aaa/bbbb/ccc.dart'); | |
| 90 Uri uri2 = FastUri.parse('dd/eeee.dart'); | |
| 91 expect(uri1, isFastUri); | |
| 92 expect(uri2, isFastUri); | |
| 93 Uri uri3 = uri1.resolveUri(uri2); | |
| 94 expect(uri3, isFastUri); | |
| 95 _compareUris(uri3, Uri.parse('package:analyzer/aaa/bbbb/dd/eeee.dart')); | |
| 96 } | |
| 97 | |
| 98 void _checkResolveUri(String srcText, String relText, String targetText) { | |
| 99 Uri src = FastUri.parse(srcText); | |
| 100 Uri rel = FastUri.parse(relText); | |
| 101 expect(src, isFastUri); | |
| 102 expect(rel, isFastUri); | |
| 103 Uri target = src.resolveUri(rel); | |
| 104 expect(target, isFastUri); | |
| 105 _compareUris(target, Uri.parse(targetText)); | |
| 106 } | |
| 107 | |
| 108 void _compareTextWithCoreUri(String text, {bool isFast: true}) { | |
| 109 Uri fastUri = FastUri.parse(text); | |
| 110 Uri coreUri = Uri.parse(text); | |
| 111 if (isFast) { | |
| 112 expect(fastUri, isFastUri); | |
| 113 } | |
| 114 _compareUris(fastUri, coreUri); | |
| 115 } | |
| 116 | |
| 117 void _compareUris(Uri fastUri, Uri coreUri) { | |
| 118 expect(fastUri.authority, coreUri.authority); | |
| 119 expect(fastUri.data, coreUri.data); | |
| 120 expect(fastUri.fragment, coreUri.fragment); | |
| 121 expect(fastUri.hasAbsolutePath, coreUri.hasAbsolutePath); | |
| 122 expect(fastUri.hasAuthority, coreUri.hasEmptyPath); | |
| 123 expect(fastUri.hasFragment, coreUri.hasFragment); | |
| 124 expect(fastUri.hasPort, coreUri.hasPort); | |
| 125 expect(fastUri.hasQuery, coreUri.hasQuery); | |
| 126 expect(fastUri.hasScheme, coreUri.hasScheme); | |
| 127 expect(fastUri.host, coreUri.host); | |
| 128 expect(fastUri.isAbsolute, coreUri.isAbsolute); | |
| 129 if (coreUri.scheme == 'http' || coreUri.scheme == 'https') { | |
| 130 expect(fastUri.origin, coreUri.origin); | |
| 131 } | |
| 132 expect(fastUri.path, coreUri.path); | |
| 133 expect(fastUri.pathSegments, coreUri.pathSegments); | |
| 134 expect(fastUri.port, coreUri.port); | |
| 135 expect(fastUri.query, coreUri.query); | |
| 136 expect(fastUri.queryParameters, coreUri.queryParameters); | |
| 137 expect(fastUri.queryParametersAll, coreUri.queryParametersAll); | |
| 138 expect(fastUri.scheme, coreUri.scheme); | |
| 139 expect(fastUri.userInfo, coreUri.userInfo); | |
| 140 } | |
| 141 } | |
| OLD | NEW |