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

Side by Side Diff: pkg/analyzer/test/src/context/context_test.dart

Issue 2155923002: Update COMPILATION_UNIT_CONSTANTS after incremental elements building. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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 | « pkg/analyzer/lib/src/task/dart.dart ('k') | no next file » | 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 library analyzer.test.src.context.context_test; 5 library analyzer.test.src.context.context_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
11 import 'package:analyzer/dart/element/element.dart'; 11 import 'package:analyzer/dart/element/element.dart';
12 import 'package:analyzer/dart/element/type.dart'; 12 import 'package:analyzer/dart/element/type.dart';
13 import 'package:analyzer/dart/element/visitor.dart'; 13 import 'package:analyzer/dart/element/visitor.dart';
14 import 'package:analyzer/file_system/memory_file_system.dart'; 14 import 'package:analyzer/file_system/memory_file_system.dart';
15 import 'package:analyzer/source/package_map_resolver.dart'; 15 import 'package:analyzer/source/package_map_resolver.dart';
16 import 'package:analyzer/src/cancelable_future.dart'; 16 import 'package:analyzer/src/cancelable_future.dart';
17 import 'package:analyzer/src/context/cache.dart'; 17 import 'package:analyzer/src/context/cache.dart';
18 import 'package:analyzer/src/context/context.dart'; 18 import 'package:analyzer/src/context/context.dart';
19 import 'package:analyzer/src/dart/element/element.dart';
19 import 'package:analyzer/src/dart/scanner/scanner.dart'; 20 import 'package:analyzer/src/dart/scanner/scanner.dart';
20 import 'package:analyzer/src/generated/engine.dart'; 21 import 'package:analyzer/src/generated/engine.dart';
21 import 'package:analyzer/src/generated/error.dart'; 22 import 'package:analyzer/src/generated/error.dart';
22 import 'package:analyzer/src/generated/java_engine.dart'; 23 import 'package:analyzer/src/generated/java_engine.dart';
23 import 'package:analyzer/src/generated/resolver.dart'; 24 import 'package:analyzer/src/generated/resolver.dart';
24 import 'package:analyzer/src/generated/source.dart'; 25 import 'package:analyzer/src/generated/source.dart';
25 import 'package:analyzer/src/generated/utilities_collection.dart'; 26 import 'package:analyzer/src/generated/utilities_collection.dart';
26 import 'package:analyzer/src/task/dart.dart'; 27 import 'package:analyzer/src/task/dart.dart';
27 import 'package:analyzer/src/task/html.dart'; 28 import 'package:analyzer/src/task/html.dart';
28 import 'package:analyzer/task/dart.dart'; 29 import 'package:analyzer/task/dart.dart';
(...skipping 3354 matching lines...) Expand 10 before | Expand all | Expand 10 after
3383 expect(analysisCache.getValue(target, RESOLVED_UNIT1), same(unitA)); 3384 expect(analysisCache.getValue(target, RESOLVED_UNIT1), same(unitA));
3384 expect(unitA.element, same(unitElementA)); 3385 expect(unitA.element, same(unitElementA));
3385 expect(unitElementA.library, same(libraryElementA)); 3386 expect(unitElementA.library, same(libraryElementA));
3386 } 3387 }
3387 // Analyze. 3388 // Analyze.
3388 _performPendingAnalysisTasks(); 3389 _performPendingAnalysisTasks();
3389 expect(context.getErrors(a).errors, hasLength(0)); 3390 expect(context.getErrors(a).errors, hasLength(0));
3390 expect(context.getErrors(b).errors, hasLength(0)); 3391 expect(context.getErrors(b).errors, hasLength(0));
3391 } 3392 }
3392 3393
3394 void test_sequence_unitConstants() {
3395 Source a = addSource(
3396 '/a.dart',
3397 r'''
3398 const A = 1;
3399 const B = 2;
3400 const C = 3;
3401 ''');
3402 _performPendingAnalysisTasks();
3403 LibrarySpecificUnit unitA = new LibrarySpecificUnit(a, a);
3404 expect(context.getResult(unitA, COMPILATION_UNIT_CONSTANTS), hasLength(3));
3405 // Update and
3406 context.setContents(
3407 a,
3408 r'''
3409 const A = 1;
3410 const B = 2;
3411 const D = 4;
3412 main() {
3413 const V = 42;
3414 }
3415 ''');
3416 List<ConstantEvaluationTarget> constants =
3417 context.getResult(unitA, COMPILATION_UNIT_CONSTANTS);
3418 expect(constants, hasLength(4));
3419 // Perform analysis, compute constant values.
3420 _performPendingAnalysisTasks();
3421 // Validate const variable values.
3422 Map<String, ConstVariableElement> constVariables =
3423 <String, ConstVariableElement>{};
3424 constants.forEach((c) {
3425 if (c is ConstVariableElement) {
3426 constVariables[c.name] = c;
3427 }
3428 });
3429 expect(constVariables['A'].evaluationResult.value.toIntValue(), 1);
3430 expect(constVariables['B'].evaluationResult.value.toIntValue(), 2);
3431 expect(constVariables['D'].evaluationResult.value.toIntValue(), 4);
3432 expect(constVariables['V'].evaluationResult.value.toIntValue(), 42);
3433 }
3434
3393 void test_sequence_useAnyResolvedUnit() { 3435 void test_sequence_useAnyResolvedUnit() {
3394 Source a = addSource( 3436 Source a = addSource(
3395 '/a.dart', 3437 '/a.dart',
3396 r''' 3438 r'''
3397 class A {} 3439 class A {}
3398 class B {} 3440 class B {}
3399 '''); 3441 ''');
3400 Source b = addSource( 3442 Source b = addSource(
3401 '/b.dart', 3443 '/b.dart',
3402 r''' 3444 r'''
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
3975 * Initialize the visitor. 4017 * Initialize the visitor.
3976 */ 4018 */
3977 _ElementGatherer(); 4019 _ElementGatherer();
3978 4020
3979 @override 4021 @override
3980 void visitElement(Element element) { 4022 void visitElement(Element element) {
3981 elements[element] = element; 4023 elements[element] = element;
3982 super.visitElement(element); 4024 super.visitElement(element);
3983 } 4025 }
3984 } 4026 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/dart.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698