OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library analyzer.test.generated.sdk_test; |
| 6 |
| 7 import 'package:analyzer/dart/ast/token.dart'; |
| 8 import 'package:analyzer/src/dart/ast/token.dart'; |
| 9 import 'package:analyzer/src/dart/scanner/reader.dart'; |
| 10 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
| 11 import 'package:analyzer/src/generated/engine.dart'; |
| 12 import 'package:analyzer/src/generated/error.dart'; |
| 13 import 'package:analyzer/src/generated/sdk.dart'; |
| 14 import 'package:analyzer/src/generated/source.dart'; |
| 15 import 'package:unittest/unittest.dart'; |
| 16 |
| 17 import '../reflective_tests.dart'; |
| 18 import '../src/context/mock_sdk.dart'; |
| 19 import '../utils.dart'; |
| 20 import 'test_support.dart'; |
| 21 |
| 22 main() { |
| 23 initializeTestEnvironment(); |
| 24 runReflectiveTests(DartSdkManagerTest); |
| 25 runReflectiveTests(SdkDescriptionTest); |
| 26 } |
| 27 |
| 28 @reflectiveTest |
| 29 class DartSdkManagerTest extends EngineTestCase { |
| 30 void test_anySdk() { |
| 31 DartSdkManager manager = |
| 32 new DartSdkManager('/a/b/c', false, _failIfCreated); |
| 33 expect(manager.anySdk, isNull); |
| 34 |
| 35 AnalysisOptions options = new AnalysisOptionsImpl(); |
| 36 SdkDescription description = new SdkDescription(<String>['/c/d'], options); |
| 37 DartSdk sdk = new MockSdk(); |
| 38 manager.getSdk(description, () => sdk); |
| 39 expect(manager.anySdk, same(sdk)); |
| 40 } |
| 41 |
| 42 void test_getSdk_differentDescriptors() { |
| 43 DartSdkManager manager = |
| 44 new DartSdkManager('/a/b/c', false, _failIfCreated); |
| 45 AnalysisOptions options = new AnalysisOptionsImpl(); |
| 46 SdkDescription description1 = new SdkDescription(<String>['/c/d'], options); |
| 47 DartSdk sdk1 = new MockSdk(); |
| 48 DartSdk result1 = manager.getSdk(description1, () => sdk1); |
| 49 expect(result1, same(sdk1)); |
| 50 SdkDescription description2 = new SdkDescription(<String>['/e/f'], options); |
| 51 DartSdk sdk2 = new MockSdk(); |
| 52 DartSdk result2 = manager.getSdk(description2, () => sdk2); |
| 53 expect(result2, same(sdk2)); |
| 54 |
| 55 manager.getSdk(description1, _failIfAbsent); |
| 56 manager.getSdk(description2, _failIfAbsent); |
| 57 } |
| 58 |
| 59 void test_getSdk_sameDescriptor() { |
| 60 DartSdkManager manager = |
| 61 new DartSdkManager('/a/b/c', false, _failIfCreated); |
| 62 AnalysisOptions options = new AnalysisOptionsImpl(); |
| 63 SdkDescription description = new SdkDescription(<String>['/c/d'], options); |
| 64 DartSdk sdk = new MockSdk(); |
| 65 DartSdk result = manager.getSdk(description, () => sdk); |
| 66 expect(result, same(sdk)); |
| 67 manager.getSdk(description, _failIfAbsent); |
| 68 } |
| 69 |
| 70 DartSdk _failIfAbsent() { |
| 71 fail('Use of ifAbsent function'); |
| 72 return null; |
| 73 } |
| 74 |
| 75 DartSdk _failIfCreated(_) { |
| 76 fail('Use of sdkCreator'); |
| 77 return null; |
| 78 } |
| 79 } |
| 80 |
| 81 @reflectiveTest |
| 82 class SdkDescriptionTest extends EngineTestCase { |
| 83 void test_equals_differentPaths_nested() { |
| 84 AnalysisOptions options = new AnalysisOptionsImpl(); |
| 85 SdkDescription left = new SdkDescription(<String>['/a/b/c'], options); |
| 86 SdkDescription right = new SdkDescription(<String>['/a/b'], options); |
| 87 expect(left == right, isFalse); |
| 88 } |
| 89 |
| 90 void test_equals_differentPaths_unrelated() { |
| 91 AnalysisOptions options = new AnalysisOptionsImpl(); |
| 92 SdkDescription left = new SdkDescription(<String>['/a/b/c'], options); |
| 93 SdkDescription right = new SdkDescription(<String>['/d/e'], options); |
| 94 expect(left == right, isFalse); |
| 95 } |
| 96 |
| 97 void test_equals_noPaths() { |
| 98 AnalysisOptions options = new AnalysisOptionsImpl(); |
| 99 SdkDescription left = new SdkDescription(<String>[], options); |
| 100 SdkDescription right = new SdkDescription(<String>[], options); |
| 101 expect(left == right, isTrue); |
| 102 } |
| 103 |
| 104 void test_equals_samePaths_differentOptions() { |
| 105 String path = '/a/b/c'; |
| 106 AnalysisOptionsImpl leftOptions = new AnalysisOptionsImpl(); |
| 107 AnalysisOptionsImpl rightOptions = new AnalysisOptionsImpl(); |
| 108 rightOptions.strongMode = !leftOptions.strongMode; |
| 109 SdkDescription left = new SdkDescription(<String>[path], leftOptions); |
| 110 SdkDescription right = new SdkDescription(<String>[path], rightOptions); |
| 111 expect(left == right, isFalse); |
| 112 } |
| 113 |
| 114 void test_equals_samePaths_sameOptions_multiple() { |
| 115 String leftPath = '/a/b/c'; |
| 116 String rightPath = '/d/e'; |
| 117 AnalysisOptions options = new AnalysisOptionsImpl(); |
| 118 SdkDescription left = |
| 119 new SdkDescription(<String>[leftPath, rightPath], options); |
| 120 SdkDescription right = |
| 121 new SdkDescription(<String>[leftPath, rightPath], options); |
| 122 expect(left == right, isTrue); |
| 123 } |
| 124 |
| 125 void test_equals_samePaths_sameOptions_single() { |
| 126 String path = '/a/b/c'; |
| 127 AnalysisOptions options = new AnalysisOptionsImpl(); |
| 128 SdkDescription left = new SdkDescription(<String>[path], options); |
| 129 SdkDescription right = new SdkDescription(<String>[path], options); |
| 130 expect(left == right, isTrue); |
| 131 } |
| 132 } |
OLD | NEW |