| OLD | NEW |
| 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 engine.incremental_resolver_test; | 5 library engine.incremental_resolver_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
| 8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/error.dart'; | 10 import 'package:analyzer/src/generated/error.dart'; |
| (...skipping 2771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2782 _resolveUnit(r''' | 2782 _resolveUnit(r''' |
| 2783 a() {} | 2783 a() {} |
| 2784 b() {} | 2784 b() {} |
| 2785 '''); | 2785 '''); |
| 2786 _updateAndValidate(r''' | 2786 _updateAndValidate(r''' |
| 2787 a() {} | 2787 a() {} |
| 2788 bb() {} | 2788 bb() {} |
| 2789 ''', expectedSuccess: false); | 2789 ''', expectedSuccess: false); |
| 2790 } | 2790 } |
| 2791 | 2791 |
| 2792 void test_false_unbalancedCurlyBrackets_inNew() { |
| 2793 _resolveUnit(r''' |
| 2794 class A { |
| 2795 aaa() { |
| 2796 if (true) { |
| 2797 1; |
| 2798 } |
| 2799 } |
| 2800 |
| 2801 bbb() { |
| 2802 print(0123456789); |
| 2803 } |
| 2804 }'''); |
| 2805 _updateAndValidate(r''' |
| 2806 class A { |
| 2807 aaa() { |
| 2808 1; |
| 2809 } |
| 2810 } |
| 2811 |
| 2812 bbb() { |
| 2813 print(0123456789); |
| 2814 } |
| 2815 }''', expectedSuccess: false); |
| 2816 } |
| 2817 |
| 2818 void test_false_unbalancedCurlyBrackets_inOld() { |
| 2819 _resolveUnit(r''' |
| 2820 class A { |
| 2821 aaa() { |
| 2822 1; |
| 2823 } |
| 2824 } |
| 2825 |
| 2826 bbb() { |
| 2827 print(0123456789); |
| 2828 } |
| 2829 }'''); |
| 2830 _updateAndValidate(r''' |
| 2831 class A { |
| 2832 aaa() { |
| 2833 if (true) { |
| 2834 1; |
| 2835 } |
| 2836 } |
| 2837 |
| 2838 bbb() { |
| 2839 print(0123456789); |
| 2840 } |
| 2841 }''', expectedSuccess: false); |
| 2842 } |
| 2843 |
| 2792 void test_fieldClassField_propagatedType() { | 2844 void test_fieldClassField_propagatedType() { |
| 2793 _resolveUnit(r''' | 2845 _resolveUnit(r''' |
| 2794 class A { | 2846 class A { |
| 2795 static const A b = const B(); | 2847 static const A b = const B(); |
| 2796 const A(); | 2848 const A(); |
| 2797 } | 2849 } |
| 2798 | 2850 |
| 2799 class B extends A { | 2851 class B extends A { |
| 2800 const B(); | 2852 const B(); |
| 2801 } | 2853 } |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3341 // The existing CompilationUnitElement should be updated. | 3393 // The existing CompilationUnitElement should be updated. |
| 3342 expect(newUnit.element, same(oldUnitElement)); | 3394 expect(newUnit.element, same(oldUnitElement)); |
| 3343 // The only expected pending task should return the same resolved | 3395 // The only expected pending task should return the same resolved |
| 3344 // "newUnit", so all clients will get it using the usual way. | 3396 // "newUnit", so all clients will get it using the usual way. |
| 3345 AnalysisResult analysisResult = analysisContext.performAnalysisTask(); | 3397 AnalysisResult analysisResult = analysisContext.performAnalysisTask(); |
| 3346 ChangeNotice notice = analysisResult.changeNotices[0]; | 3398 ChangeNotice notice = analysisResult.changeNotices[0]; |
| 3347 expect(notice.compilationUnit, same(newUnit)); | 3399 expect(notice.compilationUnit, same(newUnit)); |
| 3348 // Resolve "newCode" from scratch. | 3400 // Resolve "newCode" from scratch. |
| 3349 if (compareWithFull) { | 3401 if (compareWithFull) { |
| 3350 _resetWithIncremental(false); | 3402 _resetWithIncremental(false); |
| 3403 source = addSource(newCode + ' '); |
| 3351 source = addSource(newCode); | 3404 source = addSource(newCode); |
| 3352 _runTasks(); | 3405 _runTasks(); |
| 3353 LibraryElement library = resolve(source); | 3406 LibraryElement library = resolve(source); |
| 3354 CompilationUnit fullNewUnit = resolveCompilationUnit(source, library); | 3407 CompilationUnit fullNewUnit = resolveCompilationUnit(source, library); |
| 3408 // Validate tokens. |
| 3409 _assertEqualTokens(newUnit, fullNewUnit); |
| 3355 // Validate that "incremental" and "full" units have the same resolution. | 3410 // Validate that "incremental" and "full" units have the same resolution. |
| 3356 try { | 3411 try { |
| 3357 assertSameResolution(newUnit, fullNewUnit, validateTypes: true); | 3412 assertSameResolution(newUnit, fullNewUnit, validateTypes: true); |
| 3358 } on IncrementalResolutionMismatch catch (mismatch) { | 3413 } on IncrementalResolutionMismatch catch (mismatch) { |
| 3359 fail(mismatch.message); | 3414 fail(mismatch.message); |
| 3360 } | 3415 } |
| 3361 _assertEqualTokens(newUnit, fullNewUnit); | |
| 3362 List<AnalysisError> newFullErrors = | 3416 List<AnalysisError> newFullErrors = |
| 3363 analysisContext.getErrors(source).errors; | 3417 analysisContext.getErrors(source).errors; |
| 3364 _assertEqualErrors(newErrors, newFullErrors); | 3418 _assertEqualErrors(newErrors, newFullErrors); |
| 3365 // TODO(scheglov) check line info | 3419 // TODO(scheglov) check line info |
| 3366 } | 3420 } |
| 3367 } | 3421 } |
| 3368 | 3422 |
| 3369 static void _assertEqualToken(Token incrToken, Token fullToken) { | 3423 static void _assertEqualToken(Token incrToken, Token fullToken) { |
| 3424 // print('[${incrToken.offset}] |$incrToken| vs. [${fullToken.offset}] |$full
Token|'); |
| 3370 expect(incrToken.type, fullToken.type); | 3425 expect(incrToken.type, fullToken.type); |
| 3371 expect(incrToken.offset, fullToken.offset); | 3426 expect(incrToken.offset, fullToken.offset); |
| 3372 expect(incrToken.length, fullToken.length); | 3427 expect(incrToken.length, fullToken.length); |
| 3373 expect(incrToken.lexeme, fullToken.lexeme); | 3428 expect(incrToken.lexeme, fullToken.lexeme); |
| 3374 } | 3429 } |
| 3375 | 3430 |
| 3376 static void _assertEqualTokens(CompilationUnit incrUnit, | 3431 static void _assertEqualTokens(CompilationUnit incrUnit, |
| 3377 CompilationUnit fullUnit) { | 3432 CompilationUnit fullUnit) { |
| 3378 Token incrToken = incrUnit.beginToken; | 3433 Token incrToken = incrUnit.beginToken; |
| 3379 Token fullToken = fullUnit.beginToken; | 3434 Token fullToken = fullUnit.beginToken; |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3641 } | 3696 } |
| 3642 } | 3697 } |
| 3643 | 3698 |
| 3644 | 3699 |
| 3645 class _Edit { | 3700 class _Edit { |
| 3646 final int offset; | 3701 final int offset; |
| 3647 final int length; | 3702 final int length; |
| 3648 final String replacement; | 3703 final String replacement; |
| 3649 _Edit(this.offset, this.length, this.replacement); | 3704 _Edit(this.offset, this.length, this.replacement); |
| 3650 } | 3705 } |
| OLD | NEW |