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

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

Issue 1209773002: SourceFactoryTest extraction. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/source_factory_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.all_the_rest_test; 8 library engine.all_the_rest_test;
9 9
10 import 'package:analyzer/file_system/file_system.dart'; 10 import 'package:analyzer/file_system/file_system.dart';
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 runReflectiveTests(FileBasedSourceTest); 67 runReflectiveTests(FileBasedSourceTest);
68 runReflectiveTests(FileUriResolverTest); 68 runReflectiveTests(FileUriResolverTest);
69 if (!AnalysisEngine.instance.useTaskModel) { 69 if (!AnalysisEngine.instance.useTaskModel) {
70 runReflectiveTests(HtmlParserTest); 70 runReflectiveTests(HtmlParserTest);
71 runReflectiveTests(HtmlTagInfoBuilderTest); 71 runReflectiveTests(HtmlTagInfoBuilderTest);
72 runReflectiveTests(HtmlUnitBuilderTest); 72 runReflectiveTests(HtmlUnitBuilderTest);
73 runReflectiveTests(HtmlWarningCodeTest); 73 runReflectiveTests(HtmlWarningCodeTest);
74 } 74 }
75 runReflectiveTests(ReferenceFinderTest); 75 runReflectiveTests(ReferenceFinderTest);
76 runReflectiveTests(SDKLibrariesReaderTest); 76 runReflectiveTests(SDKLibrariesReaderTest);
77 runReflectiveTests(SourceFactoryTest);
78 runReflectiveTests(ToSourceVisitorTest); 77 runReflectiveTests(ToSourceVisitorTest);
79 runReflectiveTests(UriKindTest); 78 runReflectiveTests(UriKindTest);
80 runReflectiveTests(StringScannerTest); 79 runReflectiveTests(StringScannerTest);
81 } 80 }
82 81
83 abstract class AbstractScannerTest { 82 abstract class AbstractScannerTest {
84 ht.AbstractScanner newScanner(String input); 83 ht.AbstractScanner newScanner(String input);
85 84
86 void test_tokenize_attribute() { 85 void test_tokenize_attribute() {
87 _tokenize("<html bob=\"one two\">", <Object>[ 86 _tokenize("<html bob=\"one two\">", <Object>[
(...skipping 8165 matching lines...) Expand 10 before | Expand all | Expand 10 after
8253 expect(second.category, "Second"); 8252 expect(second.category, "Second");
8254 expect(second.path, "second/second.dart"); 8253 expect(second.path, "second/second.dart");
8255 expect(second.shortName, "dart:second"); 8254 expect(second.shortName, "dart:second");
8256 expect(second.isDart2JsLibrary, false); 8255 expect(second.isDart2JsLibrary, false);
8257 expect(second.isDocumented, false); 8256 expect(second.isDocumented, false);
8258 expect(second.isImplementation, true); 8257 expect(second.isImplementation, true);
8259 expect(second.isVmLibrary, false); 8258 expect(second.isVmLibrary, false);
8260 } 8259 }
8261 } 8260 }
8262 8261
8263 @reflectiveTest
8264 class SourceFactoryTest {
8265 void test_creation() {
8266 expect(new SourceFactory([]), isNotNull);
8267 }
8268 void test_fromEncoding_invalidUri() {
8269 SourceFactory factory = new SourceFactory([]);
8270 try {
8271 factory.fromEncoding("<:&%>");
8272 fail("Expected IllegalArgumentException");
8273 } on IllegalArgumentException {}
8274 }
8275 void test_fromEncoding_noResolver() {
8276 SourceFactory factory = new SourceFactory([]);
8277 try {
8278 factory.fromEncoding("foo:/does/not/exist.dart");
8279 fail("Expected IllegalArgumentException");
8280 } on IllegalArgumentException {}
8281 }
8282 void test_fromEncoding_valid() {
8283 String encoding = "file:///does/not/exist.dart";
8284 SourceFactory factory = new SourceFactory(
8285 [new UriResolver_SourceFactoryTest_test_fromEncoding_valid(encoding)]);
8286 expect(factory.fromEncoding(encoding), isNotNull);
8287 }
8288 void test_resolveUri_absolute() {
8289 UriResolver_absolute resolver = new UriResolver_absolute();
8290 SourceFactory factory = new SourceFactory([resolver]);
8291 factory.resolveUri(null, "dart:core");
8292 expect(resolver.invoked, isTrue);
8293 }
8294 void test_resolveUri_nonAbsolute_absolute() {
8295 SourceFactory factory =
8296 new SourceFactory([new UriResolver_nonAbsolute_absolute()]);
8297 String absolutePath = "/does/not/matter.dart";
8298 Source containingSource =
8299 new FileBasedSource(FileUtilities2.createFile("/does/not/exist.dart"));
8300 Source result = factory.resolveUri(containingSource, absolutePath);
8301 expect(result.fullName,
8302 FileUtilities2.createFile(absolutePath).getAbsolutePath());
8303 }
8304 void test_resolveUri_nonAbsolute_relative() {
8305 SourceFactory factory =
8306 new SourceFactory([new UriResolver_nonAbsolute_relative()]);
8307 Source containingSource =
8308 new FileBasedSource(FileUtilities2.createFile("/does/not/have.dart"));
8309 Source result = factory.resolveUri(containingSource, "exist.dart");
8310 expect(result.fullName,
8311 FileUtilities2.createFile("/does/not/exist.dart").getAbsolutePath());
8312 }
8313
8314 void test_resolveUri_nonAbsolute_relative_package() {
8315 MemoryResourceProvider provider = new MemoryResourceProvider();
8316 Context context = provider.pathContext;
8317 String packagePath =
8318 context.joinAll([context.separator, 'path', 'to', 'package']);
8319 String libPath = context.joinAll([packagePath, 'lib']);
8320 String dirPath = context.joinAll([libPath, 'dir']);
8321 String firstPath = context.joinAll([dirPath, 'first.dart']);
8322 String secondPath = context.joinAll([dirPath, 'second.dart']);
8323
8324 provider.newFolder(packagePath);
8325 Folder libFolder = provider.newFolder(libPath);
8326 provider.newFolder(dirPath);
8327 File firstFile = provider.newFile(firstPath, '');
8328 provider.newFile(secondPath, '');
8329
8330 PackageMapUriResolver resolver =
8331 new PackageMapUriResolver(provider, {'package': [libFolder]});
8332 SourceFactory factory = new SourceFactory([resolver]);
8333 Source librarySource =
8334 firstFile.createSource(Uri.parse('package:package/dir/first.dart'));
8335
8336 Source result = factory.resolveUri(librarySource, 'second.dart');
8337 expect(result, isNotNull);
8338 expect(result.fullName, secondPath);
8339 expect(result.uri.toString(), 'package:package/dir/second.dart');
8340 }
8341
8342 void test_restoreUri() {
8343 JavaFile file1 = FileUtilities2.createFile("/some/file1.dart");
8344 JavaFile file2 = FileUtilities2.createFile("/some/file2.dart");
8345 Source source1 = new FileBasedSource(file1);
8346 Source source2 = new FileBasedSource(file2);
8347 Uri expected1 = parseUriWithException("file:///my_file.dart");
8348 SourceFactory factory =
8349 new SourceFactory([new UriResolver_restoreUri(source1, expected1)]);
8350 expect(factory.restoreUri(source1), same(expected1));
8351 expect(factory.restoreUri(source2), same(null));
8352 }
8353 }
8354 8262
8355 @reflectiveTest 8263 @reflectiveTest
8356 class StringScannerTest extends AbstractScannerTest { 8264 class StringScannerTest extends AbstractScannerTest {
8357 @override 8265 @override
8358 ht.AbstractScanner newScanner(String input) { 8266 ht.AbstractScanner newScanner(String input) {
8359 return new ht.StringScanner(null, input); 8267 return new ht.StringScanner(null, input);
8360 } 8268 }
8361 } 8269 }
8362 8270
8363 /** 8271 /**
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
8421 expect(UriKind.fromEncoding(0x58), same(null)); 8329 expect(UriKind.fromEncoding(0x58), same(null));
8422 } 8330 }
8423 8331
8424 void test_getEncoding() { 8332 void test_getEncoding() {
8425 expect(UriKind.DART_URI.encoding, 0x64); 8333 expect(UriKind.DART_URI.encoding, 0x64);
8426 expect(UriKind.FILE_URI.encoding, 0x66); 8334 expect(UriKind.FILE_URI.encoding, 0x66);
8427 expect(UriKind.PACKAGE_URI.encoding, 0x70); 8335 expect(UriKind.PACKAGE_URI.encoding, 0x70);
8428 } 8336 }
8429 } 8337 }
8430 8338
8431 class UriResolver_absolute extends UriResolver {
8432 bool invoked = false;
8433
8434 UriResolver_absolute();
8435
8436 @override
8437 Source resolveAbsolute(Uri uri) {
8438 invoked = true;
8439 return null;
8440 }
8441 }
8442
8443 class UriResolver_nonAbsolute_absolute extends UriResolver {
8444 @override
8445 Source resolveAbsolute(Uri uri) {
8446 return new FileBasedSource(new JavaFile.fromUri(uri), uri);
8447 }
8448 }
8449
8450 class UriResolver_nonAbsolute_relative extends UriResolver {
8451 @override
8452 Source resolveAbsolute(Uri uri) {
8453 return new FileBasedSource(new JavaFile.fromUri(uri), uri);
8454 }
8455 }
8456
8457 class UriResolver_restoreUri extends UriResolver {
8458 Source source1;
8459
8460 Uri expected1;
8461
8462 UriResolver_restoreUri(this.source1, this.expected1);
8463
8464 @override
8465 Source resolveAbsolute(Uri uri) => null;
8466
8467 @override
8468 Uri restoreAbsolute(Source source) {
8469 if (identical(source, source1)) {
8470 return expected1;
8471 }
8472 return null;
8473 }
8474 }
8475
8476 class UriResolver_SourceFactoryTest_test_fromEncoding_valid
8477 extends UriResolver {
8478 String encoding;
8479
8480 UriResolver_SourceFactoryTest_test_fromEncoding_valid(this.encoding);
8481
8482 @override
8483 Source resolveAbsolute(Uri uri) {
8484 if (uri.toString() == encoding) {
8485 return new TestSource();
8486 }
8487 return null;
8488 }
8489 }
8490
8491 /** 8339 /**
8492 * Instances of `XmlValidator` traverse an [XmlNode] structure and validate the node 8340 * Instances of `XmlValidator` traverse an [XmlNode] structure and validate the node
8493 * hierarchy. 8341 * hierarchy.
8494 */ 8342 */
8495 class XmlValidator extends ht.RecursiveXmlVisitor<Object> { 8343 class XmlValidator extends ht.RecursiveXmlVisitor<Object> {
8496 /** 8344 /**
8497 * A list containing the errors found while traversing the AST structure. 8345 * A list containing the errors found while traversing the AST structure.
8498 */ 8346 */
8499 List<String> _errors = new List<String>(); 8347 List<String> _errors = new List<String>();
8500 /** 8348 /**
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
8754 if (_expectedExternalScriptName == null) { 8602 if (_expectedExternalScriptName == null) {
8755 expect(scriptSource, isNull, reason: "script $scriptIndex"); 8603 expect(scriptSource, isNull, reason: "script $scriptIndex");
8756 } else { 8604 } else {
8757 expect(scriptSource, isNotNull, reason: "script $scriptIndex"); 8605 expect(scriptSource, isNotNull, reason: "script $scriptIndex");
8758 String actualExternalScriptName = scriptSource.shortName; 8606 String actualExternalScriptName = scriptSource.shortName;
8759 expect(actualExternalScriptName, _expectedExternalScriptName, 8607 expect(actualExternalScriptName, _expectedExternalScriptName,
8760 reason: "script $scriptIndex"); 8608 reason: "script $scriptIndex");
8761 } 8609 }
8762 } 8610 }
8763 } 8611 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/source_factory_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698