| 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:test/test.dart'; | |
| 9 import 'package:test_reflective_loader/test_reflective_loader.dart'; | |
| 10 | |
| 11 main() { | |
| 12 defineReflectiveSuite(() { | |
| 13 defineReflectiveTests(_FastUriTest); | |
| 14 }); | |
| 15 } | |
| 16 | |
| 17 @reflectiveTest | |
| 18 class _FastUriTest { | |
| 19 static final isInstanceOf<FastUri> isFastUri = new isInstanceOf<FastUri>(); | |
| 20 | |
| 21 void test_parse_absolute_dart() { | |
| 22 _compareTextWithCoreUri('dart:core'); | |
| 23 } | |
| 24 | |
| 25 void test_parse_absolute_file() { | |
| 26 _compareTextWithCoreUri('file:///Users/scheglov/util/fast_uri.dart'); | |
| 27 } | |
| 28 | |
| 29 void test_parse_absolute_folder_withSlashAtTheEnd() { | |
| 30 _compareTextWithCoreUri('file:///Users/scheglov/util/'); | |
| 31 } | |
| 32 | |
| 33 void test_parse_absolute_package() { | |
| 34 _compareTextWithCoreUri('package:analyzer/src/util/fast_uri.dart'); | |
| 35 } | |
| 36 | |
| 37 void test_parse_notFast_hasAuthority() { | |
| 38 Uri uri = FastUri.parse('http://www.google.com/pages/about.html'); | |
| 39 expect(uri, isNot(isFastUri)); | |
| 40 } | |
| 41 | |
| 42 void test_parse_notFast_hasPort() { | |
| 43 Uri uri = FastUri.parse('http://www.google.com:8080/pages/about.html'); | |
| 44 expect(uri, isNot(isFastUri)); | |
| 45 } | |
| 46 | |
| 47 void test_parse_relative_down() { | |
| 48 _compareTextWithCoreUri('util/fast_uri.dart'); | |
| 49 } | |
| 50 | |
| 51 void test_parse_relative_up() { | |
| 52 _compareTextWithCoreUri('../util/fast_uri.dart'); | |
| 53 } | |
| 54 | |
| 55 void test_resolve() { | |
| 56 Uri uri1 = FastUri.parse('package:analyzer/aaa/bbbb/c.dart'); | |
| 57 Uri uri2 = uri1.resolve('dd.dart'); | |
| 58 _compareUris(uri2, Uri.parse('package:analyzer/aaa/bbbb/dd.dart')); | |
| 59 } | |
| 60 | |
| 61 void test_resolveUri_absolute() { | |
| 62 _checkResolveUri('package:analyzer/aaa/b.dart', 'package:path/style.dart', | |
| 63 'package:path/style.dart'); | |
| 64 } | |
| 65 | |
| 66 void test_resolveUri_endWithSlash_onlyName() { | |
| 67 _checkResolveUri('package:analyzer/aaa/bbbb/', 'cc.dart', | |
| 68 'package:analyzer/aaa/bbbb/cc.dart'); | |
| 69 } | |
| 70 | |
| 71 void test_resolveUri_nameStartsWithOneDot() { | |
| 72 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', '.name.dart', | |
| 73 'package:analyzer/aaa/bbbb/.name.dart'); | |
| 74 } | |
| 75 | |
| 76 void test_resolveUri_nameStartsWithTwoDots() { | |
| 77 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', '..name.dart', | |
| 78 'package:analyzer/aaa/bbbb/..name.dart'); | |
| 79 } | |
| 80 | |
| 81 void test_resolveUri_noSlash_onlyName() { | |
| 82 _checkResolveUri('dart:core', 'int.dart', 'dart:core/int.dart'); | |
| 83 } | |
| 84 | |
| 85 void test_resolveUri_onlyName() { | |
| 86 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', 'dd.dart', | |
| 87 'package:analyzer/aaa/bbbb/dd.dart'); | |
| 88 } | |
| 89 | |
| 90 void test_resolveUri_pathHasOneDot() { | |
| 91 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', 'dd/./ee.dart', | |
| 92 'package:analyzer/aaa/bbbb/dd/ee.dart'); | |
| 93 } | |
| 94 | |
| 95 void test_resolveUri_pathHasTwoDots() { | |
| 96 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', 'dd/../ee.dart', | |
| 97 'package:analyzer/aaa/bbbb/ee.dart'); | |
| 98 } | |
| 99 | |
| 100 void test_resolveUri_pathStartsWithOneDot() { | |
| 101 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', './ddd.dart', | |
| 102 'package:analyzer/aaa/bbbb/ddd.dart'); | |
| 103 } | |
| 104 | |
| 105 void test_resolveUri_pathStartsWithTwoDots() { | |
| 106 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', '../ddd.dart', | |
| 107 'package:analyzer/aaa/ddd.dart'); | |
| 108 } | |
| 109 | |
| 110 void test_resolveUri_pathWithSubFolder() { | |
| 111 Uri uri1 = FastUri.parse('package:analyzer/aaa/bbbb/ccc.dart'); | |
| 112 Uri uri2 = FastUri.parse('dd/eeee.dart'); | |
| 113 expect(uri1, isFastUri); | |
| 114 expect(uri2, isFastUri); | |
| 115 Uri uri3 = uri1.resolveUri(uri2); | |
| 116 expect(uri3, isFastUri); | |
| 117 _compareUris(uri3, Uri.parse('package:analyzer/aaa/bbbb/dd/eeee.dart')); | |
| 118 } | |
| 119 | |
| 120 void test_resolveUri_short_absolute() { | |
| 121 // Check the case where the URI being resolved is a "short absolute" uri | |
| 122 // (starts with a "/" but doesn't start with "file://"). Such URIs are not | |
| 123 // actually valid URIs but we still want to handle them in a way that's | |
| 124 // consistent with the behavior of Uri. | |
| 125 String containing = 'file:///foo/bar'; | |
| 126 String relative = '/a.dart'; | |
| 127 String expectedResult = Uri.parse(containing).resolve(relative).toString(); | |
| 128 _checkResolveUri(containing, relative, expectedResult); | |
| 129 } | |
| 130 | |
| 131 void _checkResolveUri(String srcText, String relText, String targetText) { | |
| 132 Uri src = FastUri.parse(srcText); | |
| 133 Uri rel = FastUri.parse(relText); | |
| 134 expect(src, isFastUri); | |
| 135 expect(rel, isFastUri); | |
| 136 Uri target = src.resolveUri(rel); | |
| 137 expect(target, isFastUri); | |
| 138 _compareUris(target, Uri.parse(targetText)); | |
| 139 } | |
| 140 | |
| 141 void _compareTextWithCoreUri(String text, {bool isFast: true}) { | |
| 142 Uri fastUri = FastUri.parse(text); | |
| 143 Uri coreUri = Uri.parse(text); | |
| 144 if (isFast) { | |
| 145 expect(fastUri, isFastUri); | |
| 146 } | |
| 147 _compareUris(fastUri, coreUri); | |
| 148 } | |
| 149 | |
| 150 void _compareUris(Uri fastUri, Uri coreUri) { | |
| 151 expect(fastUri.authority, coreUri.authority); | |
| 152 expect(fastUri.data, coreUri.data); | |
| 153 expect(fastUri.fragment, coreUri.fragment); | |
| 154 expect(fastUri.hasAbsolutePath, coreUri.hasAbsolutePath); | |
| 155 expect(fastUri.hasAuthority, coreUri.hasAuthority); | |
| 156 expect(fastUri.hasEmptyPath, coreUri.hasEmptyPath); | |
| 157 expect(fastUri.hasFragment, coreUri.hasFragment); | |
| 158 expect(fastUri.hasPort, coreUri.hasPort); | |
| 159 expect(fastUri.hasQuery, coreUri.hasQuery); | |
| 160 expect(fastUri.hasScheme, coreUri.hasScheme); | |
| 161 expect(fastUri.host, coreUri.host); | |
| 162 expect(fastUri.isAbsolute, coreUri.isAbsolute); | |
| 163 if (coreUri.scheme == 'http' || coreUri.scheme == 'https') { | |
| 164 expect(fastUri.origin, coreUri.origin); | |
| 165 } | |
| 166 expect(fastUri.path, coreUri.path); | |
| 167 expect(fastUri.pathSegments, coreUri.pathSegments); | |
| 168 expect(fastUri.port, coreUri.port); | |
| 169 expect(fastUri.query, coreUri.query); | |
| 170 expect(fastUri.queryParameters, coreUri.queryParameters); | |
| 171 expect(fastUri.queryParametersAll, coreUri.queryParametersAll); | |
| 172 expect(fastUri.scheme, coreUri.scheme); | |
| 173 expect(fastUri.userInfo, coreUri.userInfo); | |
| 174 // Object | |
| 175 expect(fastUri.hashCode, coreUri.hashCode); | |
| 176 expect(fastUri == coreUri, isTrue); | |
| 177 expect(coreUri == fastUri, isTrue); | |
| 178 } | |
| 179 } | |
| OLD | NEW |