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

Side by Side Diff: pkg/analyzer/test/src/task/dart_test.dart

Issue 1193143002: Next steps toward HTML support (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comments Created 5 years, 6 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 test.src.task.dart_test; 5 library test.src.task.dart_test;
6 6
7 import 'package:analyzer/src/context/cache.dart'; 7 import 'package:analyzer/src/context/cache.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/constant.dart'; 9 import 'package:analyzer/src/generated/constant.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
11 import 'package:analyzer/src/generated/engine.dart' 11 import 'package:analyzer/src/generated/engine.dart'
12 show AnalysisOptionsImpl, CacheState; 12 show AnalysisOptionsImpl, CacheState;
13 import 'package:analyzer/src/generated/error.dart'; 13 import 'package:analyzer/src/generated/error.dart';
14 import 'package:analyzer/src/generated/resolver.dart'; 14 import 'package:analyzer/src/generated/resolver.dart';
15 import 'package:analyzer/src/generated/scanner.dart';
15 import 'package:analyzer/src/generated/sdk.dart'; 16 import 'package:analyzer/src/generated/sdk.dart';
16 import 'package:analyzer/src/generated/source.dart'; 17 import 'package:analyzer/src/generated/source.dart';
17 import 'package:analyzer/src/task/dart.dart'; 18 import 'package:analyzer/src/task/dart.dart';
19 import 'package:analyzer/src/task/html.dart';
18 import 'package:analyzer/task/dart.dart'; 20 import 'package:analyzer/task/dart.dart';
19 import 'package:analyzer/task/general.dart'; 21 import 'package:analyzer/task/general.dart';
20 import 'package:analyzer/task/model.dart'; 22 import 'package:analyzer/task/model.dart';
21 import 'package:unittest/unittest.dart'; 23 import 'package:unittest/unittest.dart';
22 24
23 import '../../generated/test_support.dart'; 25 import '../../generated/test_support.dart';
24 import '../../reflective_tests.dart'; 26 import '../../reflective_tests.dart';
25 import '../context/abstract_context.dart'; 27 import '../context/abstract_context.dart';
26 28
27 main() { 29 main() {
(...skipping 2172 matching lines...) Expand 10 before | Expand all | Expand 10 after
2200 2202
2201 @reflectiveTest 2203 @reflectiveTest
2202 class ParseDartTaskTest extends _AbstractDartTaskTest { 2204 class ParseDartTaskTest extends _AbstractDartTaskTest {
2203 Source source; 2205 Source source;
2204 2206
2205 test_buildInputs() { 2207 test_buildInputs() {
2206 Map<String, TaskInput> inputs = ParseDartTask.buildInputs(emptySource); 2208 Map<String, TaskInput> inputs = ParseDartTask.buildInputs(emptySource);
2207 expect(inputs, isNotNull); 2209 expect(inputs, isNotNull);
2208 expect(inputs.keys, unorderedEquals([ 2210 expect(inputs.keys, unorderedEquals([
2209 ParseDartTask.LINE_INFO_INPUT_NAME, 2211 ParseDartTask.LINE_INFO_INPUT_NAME,
2210 ParseDartTask.MODIFICATION_TIME_INPUT_NAME,
2211 ParseDartTask.TOKEN_STREAM_INPUT_NAME 2212 ParseDartTask.TOKEN_STREAM_INPUT_NAME
2212 ])); 2213 ]));
2213 } 2214 }
2214 2215
2215 test_constructor() { 2216 test_constructor() {
2216 ParseDartTask task = new ParseDartTask(context, emptySource); 2217 ParseDartTask task = new ParseDartTask(context, emptySource);
2217 expect(task, isNotNull); 2218 expect(task, isNotNull);
2218 expect(task.context, context); 2219 expect(task.context, context);
2219 expect(task.target, emptySource); 2220 expect(task.target, emptySource);
2220 } 2221 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2269 2270
2270 test_perform_doesNotExist() { 2271 test_perform_doesNotExist() {
2271 _performParseTask(null); 2272 _performParseTask(null);
2272 expect(outputs, hasLength(8)); 2273 expect(outputs, hasLength(8));
2273 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); 2274 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0));
2274 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); 2275 expect(outputs[EXPORTED_LIBRARIES], hasLength(0));
2275 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); 2276 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1);
2276 expect(outputs[INCLUDED_PARTS], hasLength(0)); 2277 expect(outputs[INCLUDED_PARTS], hasLength(0));
2277 expect(outputs[PARSE_ERRORS], hasLength(0)); 2278 expect(outputs[PARSE_ERRORS], hasLength(0));
2278 expect(outputs[PARSED_UNIT], isNotNull); 2279 expect(outputs[PARSED_UNIT], isNotNull);
2279 expect(outputs[SOURCE_KIND], SourceKind.UNKNOWN); 2280 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY);
2280 expect(outputs[UNITS], hasLength(1)); 2281 expect(outputs[UNITS], hasLength(1));
2281 } 2282 }
2282 2283
2283 test_perform_invalidDirectives() { 2284 test_perform_invalidDirectives() {
2284 _performParseTask(r''' 2285 _performParseTask(r'''
2285 library lib; 2286 library lib;
2286 import '/does/not/exist.dart'; 2287 import '/does/not/exist.dart';
2287 import '://invaliduri.dart'; 2288 import '://invaliduri.dart';
2288 export '${a}lib3.dart'; 2289 export '${a}lib3.dart';
2289 part 'part.dart'; 2290 part 'part.dart';
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
2658 } 2659 }
2659 2660
2660 test_perform_noErrors() { 2661 test_perform_noErrors() {
2661 _performScanTask('class A {}'); 2662 _performScanTask('class A {}');
2662 expect(outputs, hasLength(3)); 2663 expect(outputs, hasLength(3));
2663 expect(outputs[LINE_INFO], isNotNull); 2664 expect(outputs[LINE_INFO], isNotNull);
2664 expect(outputs[SCAN_ERRORS], hasLength(0)); 2665 expect(outputs[SCAN_ERRORS], hasLength(0));
2665 expect(outputs[TOKEN_STREAM], isNotNull); 2666 expect(outputs[TOKEN_STREAM], isNotNull);
2666 } 2667 }
2667 2668
2669 test_perform_script() {
2670 String scriptContent = '''
2671 void buttonPressed() {
2672 ''';
2673 String htmlContent = '''
2674 <!DOCTYPE html>
2675 <html>
2676 <head>
2677 <title>test page</title>
2678 <script type='application/dart'>$scriptContent</script>
2679 </head>
2680 <body>Test</body>
2681 </html>
2682 ''';
2683 Source source = newSource('/test.html', htmlContent);
2684 DartScript script =
2685 new DartScript(source, [new ScriptFragment(97, 5, 36, scriptContent)]);
2686
2687 computeResult(script, TOKEN_STREAM);
2688 expect(task, new isInstanceOf<ScanDartTask>());
2689 expect(outputs[LINE_INFO], isNotNull);
2690 expect(outputs[SCAN_ERRORS], isEmpty);
2691 Token tokenStream = outputs[TOKEN_STREAM];
2692 expect(tokenStream, isNotNull);
2693 expect(tokenStream.lexeme, 'void');
2694 }
2695
2668 void _performScanTask(String content) { 2696 void _performScanTask(String content) {
2669 AnalysisTarget target = newSource('/test.dart', content); 2697 AnalysisTarget target = newSource('/test.dart', content);
2670 computeResult(target, TOKEN_STREAM); 2698 computeResult(target, TOKEN_STREAM);
2671 expect(task, new isInstanceOf<ScanDartTask>()); 2699 expect(task, new isInstanceOf<ScanDartTask>());
2672 } 2700 }
2673 } 2701 }
2674 2702
2675 @reflectiveTest 2703 @reflectiveTest
2676 class VerifyUnitTaskTest extends _AbstractDartTaskTest { 2704 class VerifyUnitTaskTest extends _AbstractDartTaskTest {
2677 test_perform_constantError() { 2705 test_perform_constantError() {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2737 } 2765 }
2738 2766
2739 void assertSameResults(List<ResultDescriptor> descriptors) { 2767 void assertSameResults(List<ResultDescriptor> descriptors) {
2740 descriptors.forEach((descriptor) { 2768 descriptors.forEach((descriptor) {
2741 var oldResult = oldOutputs[descriptor]; 2769 var oldResult = oldOutputs[descriptor];
2742 var newResult = outputs[descriptor]; 2770 var newResult = outputs[descriptor];
2743 expect(newResult, same(oldResult), reason: descriptor.name); 2771 expect(newResult, same(oldResult), reason: descriptor.name);
2744 }); 2772 });
2745 } 2773 }
2746 2774
2775 /**
2776 * Create a script object with a single fragment containing the given
2777 * [scriptContent].
2778 */
2779 DartScript createScript(String scriptContent) {
2780 String htmlContent = '''
2781 <!DOCTYPE html>
2782 <html>
2783 <head>
2784 <title>test page</title>
2785 <script type='application/dart'>$scriptContent</script>
2786 </head>
2787 <body>Test</body>
2788 </html>
2789 ''';
2790 Source source = newSource('/test.html', htmlContent);
2791 return new DartScript(
2792 source, [new ScriptFragment(97, 5, 36, scriptContent)]);
2793 }
2794
2747 void setUp() { 2795 void setUp() {
2748 super.setUp(); 2796 super.setUp();
2749 emptySource = newSource('/test.dart'); 2797 emptySource = newSource('/test.dart');
2750 } 2798 }
2751 2799
2752 /** 2800 /**
2753 * Fill [errorListener] with [result] errors in the current [task]. 2801 * Fill [errorListener] with [result] errors in the current [task].
2754 */ 2802 */
2755 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { 2803 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) {
2756 List<AnalysisError> errors = task.outputs[result]; 2804 List<AnalysisError> errors = task.outputs[result];
2757 expect(errors, isNotNull, reason: result.name); 2805 expect(errors, isNotNull, reason: result.name);
2758 errorListener = new GatheringErrorListener(); 2806 errorListener = new GatheringErrorListener();
2759 errorListener.addAll(errors); 2807 errorListener.addAll(errors);
2760 } 2808 }
2761 } 2809 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/context/context_test.dart ('k') | pkg/analyzer/test/src/task/html_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698