Index: pkg/analyzer/test/generated/sdk_test.dart |
diff --git a/pkg/analyzer/test/generated/sdk_test.dart b/pkg/analyzer/test/generated/sdk_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8976b9cc4bd7483c51427d57a6ae73aec016716c |
--- /dev/null |
+++ b/pkg/analyzer/test/generated/sdk_test.dart |
@@ -0,0 +1,132 @@ |
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+library analyzer.test.generated.sdk_test; |
+ |
+import 'package:analyzer/dart/ast/token.dart'; |
+import 'package:analyzer/src/dart/ast/token.dart'; |
+import 'package:analyzer/src/dart/scanner/reader.dart'; |
+import 'package:analyzer/src/dart/scanner/scanner.dart'; |
+import 'package:analyzer/src/generated/engine.dart'; |
+import 'package:analyzer/src/generated/error.dart'; |
+import 'package:analyzer/src/generated/sdk.dart'; |
+import 'package:analyzer/src/generated/source.dart'; |
+import 'package:unittest/unittest.dart'; |
+ |
+import '../reflective_tests.dart'; |
+import '../src/context/mock_sdk.dart'; |
+import '../utils.dart'; |
+import 'test_support.dart'; |
+ |
+main() { |
+ initializeTestEnvironment(); |
+ runReflectiveTests(DartSdkManagerTest); |
+ runReflectiveTests(SdkDescriptionTest); |
+} |
+ |
+@reflectiveTest |
+class DartSdkManagerTest extends EngineTestCase { |
+ void test_anySdk() { |
+ DartSdkManager manager = |
+ new DartSdkManager('/a/b/c', false, _failIfCreated); |
+ expect(manager.anySdk, isNull); |
+ |
+ AnalysisOptions options = new AnalysisOptionsImpl(); |
+ SdkDescription description = new SdkDescription(<String>['/c/d'], options); |
+ DartSdk sdk = new MockSdk(); |
+ manager.getSdk(description, () => sdk); |
+ expect(manager.anySdk, same(sdk)); |
+ } |
+ |
+ void test_getSdk_differentDescriptors() { |
+ DartSdkManager manager = |
+ new DartSdkManager('/a/b/c', false, _failIfCreated); |
+ AnalysisOptions options = new AnalysisOptionsImpl(); |
+ SdkDescription description1 = new SdkDescription(<String>['/c/d'], options); |
+ DartSdk sdk1 = new MockSdk(); |
+ DartSdk result1 = manager.getSdk(description1, () => sdk1); |
+ expect(result1, same(sdk1)); |
+ SdkDescription description2 = new SdkDescription(<String>['/e/f'], options); |
+ DartSdk sdk2 = new MockSdk(); |
+ DartSdk result2 = manager.getSdk(description2, () => sdk2); |
+ expect(result2, same(sdk2)); |
+ |
+ manager.getSdk(description1, _failIfAbsent); |
+ manager.getSdk(description2, _failIfAbsent); |
+ } |
+ |
+ void test_getSdk_sameDescriptor() { |
+ DartSdkManager manager = |
+ new DartSdkManager('/a/b/c', false, _failIfCreated); |
+ AnalysisOptions options = new AnalysisOptionsImpl(); |
+ SdkDescription description = new SdkDescription(<String>['/c/d'], options); |
+ DartSdk sdk = new MockSdk(); |
+ DartSdk result = manager.getSdk(description, () => sdk); |
+ expect(result, same(sdk)); |
+ manager.getSdk(description, _failIfAbsent); |
+ } |
+ |
+ DartSdk _failIfAbsent() { |
+ fail('Use of ifAbsent function'); |
+ return null; |
+ } |
+ |
+ DartSdk _failIfCreated(_) { |
+ fail('Use of sdkCreator'); |
+ return null; |
+ } |
+} |
+ |
+@reflectiveTest |
+class SdkDescriptionTest extends EngineTestCase { |
+ void test_equals_differentPaths_nested() { |
+ AnalysisOptions options = new AnalysisOptionsImpl(); |
+ SdkDescription left = new SdkDescription(<String>['/a/b/c'], options); |
+ SdkDescription right = new SdkDescription(<String>['/a/b'], options); |
+ expect(left == right, isFalse); |
+ } |
+ |
+ void test_equals_differentPaths_unrelated() { |
+ AnalysisOptions options = new AnalysisOptionsImpl(); |
+ SdkDescription left = new SdkDescription(<String>['/a/b/c'], options); |
+ SdkDescription right = new SdkDescription(<String>['/d/e'], options); |
+ expect(left == right, isFalse); |
+ } |
+ |
+ void test_equals_noPaths() { |
+ AnalysisOptions options = new AnalysisOptionsImpl(); |
+ SdkDescription left = new SdkDescription(<String>[], options); |
+ SdkDescription right = new SdkDescription(<String>[], options); |
+ expect(left == right, isTrue); |
+ } |
+ |
+ void test_equals_samePaths_differentOptions() { |
+ String path = '/a/b/c'; |
+ AnalysisOptionsImpl leftOptions = new AnalysisOptionsImpl(); |
+ AnalysisOptionsImpl rightOptions = new AnalysisOptionsImpl(); |
+ rightOptions.strongMode = !leftOptions.strongMode; |
+ SdkDescription left = new SdkDescription(<String>[path], leftOptions); |
+ SdkDescription right = new SdkDescription(<String>[path], rightOptions); |
+ expect(left == right, isFalse); |
+ } |
+ |
+ void test_equals_samePaths_sameOptions_multiple() { |
+ String leftPath = '/a/b/c'; |
+ String rightPath = '/d/e'; |
+ AnalysisOptions options = new AnalysisOptionsImpl(); |
+ SdkDescription left = |
+ new SdkDescription(<String>[leftPath, rightPath], options); |
+ SdkDescription right = |
+ new SdkDescription(<String>[leftPath, rightPath], options); |
+ expect(left == right, isTrue); |
+ } |
+ |
+ void test_equals_samePaths_sameOptions_single() { |
+ String path = '/a/b/c'; |
+ AnalysisOptions options = new AnalysisOptionsImpl(); |
+ SdkDescription left = new SdkDescription(<String>[path], options); |
+ SdkDescription right = new SdkDescription(<String>[path], options); |
+ expect(left == right, isTrue); |
+ } |
+} |