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

Side by Side Diff: pkg/analyzer/test/generated/all_the_rest_test.dart

Issue 2242883003: Fix resolveRelativeUri() to handle correctly empty contained Uri(s). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library analyzer.test.generated.all_the_rest_test; 5 library analyzer.test.generated.all_the_rest_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/token.dart'; 8 import 'package:analyzer/dart/ast/token.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
(...skipping 4384 matching lines...) Expand 10 before | Expand all | Expand 10 after
4395 new FileBasedSource(file, parseUriWithException("dart:core")); 4395 new FileBasedSource(file, parseUriWithException("dart:core"));
4396 expect(source, isNotNull); 4396 expect(source, isNotNull);
4397 expect(source.fullName, file.getAbsolutePath()); 4397 expect(source.fullName, file.getAbsolutePath());
4398 expect(source.isInSystemLibrary, isTrue); 4398 expect(source.isInSystemLibrary, isTrue);
4399 } 4399 }
4400 } 4400 }
4401 4401
4402 @reflectiveTest 4402 @reflectiveTest
4403 class ResolveRelativeUriTest { 4403 class ResolveRelativeUriTest {
4404 void test_resolveRelative_dart_dartUri() { 4404 void test_resolveRelative_dart_dartUri() {
4405 Uri uri = parseUriWithException('dart:foo'); 4405 _assertResolve('dart:foo', 'dart:bar', 'dart:bar');
4406 Uri relative = resolveRelativeUri(uri, parseUriWithException('dart:bar'));
4407 expect(relative, isNotNull);
4408 expect(relative.toString(), 'dart:bar');
4409 } 4406 }
4410 4407
4411 void test_resolveRelative_dart_fileName() { 4408 void test_resolveRelative_dart_fileName() {
4412 Uri uri = parseUriWithException("dart:test"); 4409 _assertResolve('dart:test', 'lib.dart', 'dart:test/lib.dart');
4413 Uri relative = resolveRelativeUri(uri, parseUriWithException("lib.dart"));
4414 expect(relative, isNotNull);
4415 expect(relative.toString(), "dart:test/lib.dart");
4416 } 4410 }
4417 4411
4418 void test_resolveRelative_dart_filePath() { 4412 void test_resolveRelative_dart_filePath() {
4419 Uri uri = parseUriWithException("dart:test"); 4413 _assertResolve('dart:test', 'c/lib.dart', 'dart:test/c/lib.dart');
4420 Uri relative = resolveRelativeUri(uri, parseUriWithException("c/lib.dart"));
4421 expect(relative, isNotNull);
4422 expect(relative.toString(), "dart:test/c/lib.dart");
4423 } 4414 }
4424 4415
4425 void test_resolveRelative_dart_filePathWithParent() { 4416 void test_resolveRelative_dart_filePathWithParent() {
4426 Uri uri = parseUriWithException("dart:test/b/test.dart"); 4417 _assertResolve(
4427 Uri relative = 4418 'dart:test/b/test.dart', '../c/lib.dart', 'dart:test/c/lib.dart');
4428 resolveRelativeUri(uri, parseUriWithException("../c/lib.dart"));
4429 expect(relative, isNotNull);
4430 expect(relative.toString(), "dart:test/c/lib.dart");
4431 } 4419 }
4432 4420
4433 void test_resolveRelative_package_dartUri() { 4421 void test_resolveRelative_package_dartUri() {
4434 Uri uri = parseUriWithException('package:foo/bar.dart'); 4422 _assertResolve('package:foo/bar.dart', 'dart:test', 'dart:test');
4435 Uri relative = resolveRelativeUri(uri, parseUriWithException('dart:test')); 4423 }
4436 expect(relative, isNotNull); 4424
4437 expect(relative.toString(), 'dart:test'); 4425 void test_resolveRelative_package_emptyPath() {
4426 _assertResolve('package:foo/bar.dart', '', 'package:foo/bar.dart');
4438 } 4427 }
4439 4428
4440 void test_resolveRelative_package_fileName() { 4429 void test_resolveRelative_package_fileName() {
4441 Uri uri = parseUriWithException("package:b/test.dart"); 4430 _assertResolve('package:b/test.dart', 'lib.dart', 'package:b/lib.dart');
4442 Uri relative = resolveRelativeUri(uri, parseUriWithException("lib.dart"));
4443 expect(relative, isNotNull);
4444 expect(relative.toString(), "package:b/lib.dart");
4445 } 4431 }
4446 4432
4447 void test_resolveRelative_package_fileNameWithoutPackageName() { 4433 void test_resolveRelative_package_fileNameWithoutPackageName() {
4448 Uri uri = parseUriWithException("package:test.dart"); 4434 _assertResolve('package:test.dart', 'lib.dart', 'package:lib.dart');
4449 Uri relative = resolveRelativeUri(uri, parseUriWithException("lib.dart"));
4450 expect(relative, isNotNull);
4451 expect(relative.toString(), "package:lib.dart");
4452 } 4435 }
4453 4436
4454 void test_resolveRelative_package_filePath() { 4437 void test_resolveRelative_package_filePath() {
4455 Uri uri = parseUriWithException("package:b/test.dart"); 4438 _assertResolve('package:b/test.dart', 'c/lib.dart', 'package:b/c/lib.dart');
4456 Uri relative = resolveRelativeUri(uri, parseUriWithException("c/lib.dart"));
4457 expect(relative, isNotNull);
4458 expect(relative.toString(), "package:b/c/lib.dart");
4459 } 4439 }
4460 4440
4461 void test_resolveRelative_package_filePathWithParent() { 4441 void test_resolveRelative_package_filePathWithParent() {
4462 Uri uri = parseUriWithException("package:a/b/test.dart"); 4442 _assertResolve(
4463 Uri relative = 4443 'package:a/b/test.dart', '../c/lib.dart', 'package:a/c/lib.dart');
4464 resolveRelativeUri(uri, parseUriWithException("../c/lib.dart")); 4444 }
4465 expect(relative, isNotNull); 4445
4466 expect(relative.toString(), "package:a/c/lib.dart"); 4446 void _assertResolve(String baseStr, String containedStr, String expectedStr) {
4447 Uri base = Uri.parse(baseStr);
Paul Berry 2016/08/12 17:51:18 I'm curious what the motivation was for using Uri.
scheglov 2016/08/12 17:58:06 To allow parsing empty Uri.
4448 Uri contained = Uri.parse(containedStr);
4449 Uri result = resolveRelativeUri(base, contained);
4450 expect(result, isNotNull);
4451 expect(result.toString(), expectedStr);
4467 } 4452 }
4468 } 4453 }
4469 4454
4470 @reflectiveTest 4455 @reflectiveTest
4471 class SDKLibrariesReaderTest extends EngineTestCase { 4456 class SDKLibrariesReaderTest extends EngineTestCase {
4472 void test_readFrom_dart2js() { 4457 void test_readFrom_dart2js() {
4473 LibraryMap libraryMap = new SdkLibrariesReader(true).readFromFile( 4458 LibraryMap libraryMap = new SdkLibrariesReader(true).readFromFile(
4474 FileUtilities2.createFile("/libs.dart"), 4459 FileUtilities2.createFile("/libs.dart"),
4475 r''' 4460 r'''
4476 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { 4461 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
4550 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); 4535 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI));
4551 expect(UriKind.fromEncoding(0x58), same(null)); 4536 expect(UriKind.fromEncoding(0x58), same(null));
4552 } 4537 }
4553 4538
4554 void test_getEncoding() { 4539 void test_getEncoding() {
4555 expect(UriKind.DART_URI.encoding, 0x64); 4540 expect(UriKind.DART_URI.encoding, 0x64);
4556 expect(UriKind.FILE_URI.encoding, 0x66); 4541 expect(UriKind.FILE_URI.encoding, 0x66);
4557 expect(UriKind.PACKAGE_URI.encoding, 0x70); 4542 expect(UriKind.PACKAGE_URI.encoding, 0x70);
4558 } 4543 }
4559 } 4544 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/utilities_dart.dart ('k') | pkg/analyzer/test/src/summary/linker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698