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

Side by Side Diff: pkg/analysis_server/test/computer/error_test.dart

Issue 486003003: Start using code-generated protocol classes in analysis server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
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 test.computer.error; 5 library test.computer.error;
6 6
7 import 'package:analysis_server/src/computer/element.dart';
8 import 'package:analysis_server/src/computer/error.dart'; 7 import 'package:analysis_server/src/computer/error.dart';
8 import 'package:analysis_server/src/protocol2.dart';
9 import 'package:analysis_server/src/constants.dart'; 9 import 'package:analysis_server/src/constants.dart';
10 import 'package:analysis_testing/mocks.dart'; 10 import 'package:analysis_testing/mocks.dart';
11 import 'package:analysis_testing/reflective_tests.dart'; 11 import 'package:analysis_testing/reflective_tests.dart';
12 import 'package:analyzer/src/generated/error.dart' as engine; 12 import 'package:analyzer/src/generated/error.dart' as engine;
13 import 'package:analyzer/src/generated/source.dart'; 13 import 'package:analyzer/src/generated/source.dart';
14 import 'package:typed_mock/typed_mock.dart'; 14 import 'package:typed_mock/typed_mock.dart';
15 import 'package:unittest/unittest.dart'; 15 import 'package:unittest/unittest.dart';
16 16
17 17
18 18
(...skipping 28 matching lines...) Expand all
47 when(engineError.length).thenReturn(20); 47 when(engineError.length).thenReturn(20);
48 } 48 }
49 49
50 void tearDown() { 50 void tearDown() {
51 source = null; 51 source = null;
52 engineError = null; 52 engineError = null;
53 } 53 }
54 54
55 void test_fromEngine_hasCorrection() { 55 void test_fromEngine_hasCorrection() {
56 when(engineError.correction).thenReturn('my correction'); 56 when(engineError.correction).thenReturn('my correction');
57 AnalysisError error = new AnalysisError.fromEngine(lineInfo, engineError); 57 AnalysisError error = analysisErrorFromEngine(lineInfo, engineError);
58 expect(error.toJson(), { 58 expect(error.toJson(), {
59 SEVERITY: 'ERROR', 59 SEVERITY: 'ERROR',
60 TYPE: 'COMPILE_TIME_ERROR', 60 TYPE: 'COMPILE_TIME_ERROR',
61 LOCATION: { 61 LOCATION: {
62 FILE: 'foo.dart', 62 FILE: 'foo.dart',
63 OFFSET: 10, 63 OFFSET: 10,
64 LENGTH: 20, 64 LENGTH: 20,
65 START_LINE: 3, 65 START_LINE: 3,
66 START_COLUMN: 2 66 START_COLUMN: 2
67 }, 67 },
68 MESSAGE: 'my message', 68 MESSAGE: 'my message',
69 CORRECTION: 'my correction' 69 CORRECTION: 'my correction'
70 }); 70 });
71 } 71 }
72 72
73 void test_fromEngine_noCorrection() { 73 void test_fromEngine_noCorrection() {
74 when(engineError.correction).thenReturn(null); 74 when(engineError.correction).thenReturn(null);
75 AnalysisError error = new AnalysisError.fromEngine(lineInfo, engineError); 75 AnalysisError error = analysisErrorFromEngine(lineInfo, engineError);
76 expect(error.toJson(), { 76 expect(error.toJson(), {
77 SEVERITY: 'ERROR', 77 SEVERITY: 'ERROR',
78 TYPE: 'COMPILE_TIME_ERROR', 78 TYPE: 'COMPILE_TIME_ERROR',
79 LOCATION: { 79 LOCATION: {
80 FILE: 'foo.dart', 80 FILE: 'foo.dart',
81 OFFSET: 10, 81 OFFSET: 10,
82 LENGTH: 20, 82 LENGTH: 20,
83 START_LINE: 3, 83 START_LINE: 3,
84 START_COLUMN: 2 84 START_COLUMN: 2
85 }, 85 },
86 MESSAGE: 'my message' 86 MESSAGE: 'my message'
87 }); 87 });
88 } 88 }
89 89
90 void test_fromEngine_noLineInfo() { 90 void test_fromEngine_noLineInfo() {
91 when(engineError.correction).thenReturn(null); 91 when(engineError.correction).thenReturn(null);
92 AnalysisError error = new AnalysisError.fromEngine(null, engineError); 92 AnalysisError error = analysisErrorFromEngine(null, engineError);
93 expect(error.toJson(), { 93 expect(error.toJson(), {
94 SEVERITY: 'ERROR', 94 SEVERITY: 'ERROR',
95 TYPE: 'COMPILE_TIME_ERROR', 95 TYPE: 'COMPILE_TIME_ERROR',
96 LOCATION: { 96 LOCATION: {
97 FILE: 'foo.dart', 97 FILE: 'foo.dart',
98 OFFSET: 10, 98 OFFSET: 10,
99 LENGTH: 20, 99 LENGTH: 20,
100 START_LINE: -1, 100 START_LINE: -1,
101 START_COLUMN: -1 101 START_COLUMN: -1
102 }, 102 },
103 MESSAGE: 'my message' 103 MESSAGE: 'my message'
104 }); 104 });
105 } 105 }
106 106
107 void test_fromJson() { 107 void test_fromJson() {
108 var json = { 108 var json = {
109 SEVERITY: 'ERROR', 109 SEVERITY: 'ERROR',
110 TYPE: 'SYNTACTIC_ERROR', 110 TYPE: 'SYNTACTIC_ERROR',
111 LOCATION: { 111 LOCATION: {
112 FILE: '/test.dart', 112 FILE: '/test.dart',
113 OFFSET: 19, 113 OFFSET: 19,
114 LENGTH: 1, 114 LENGTH: 1,
115 START_LINE: 2, 115 START_LINE: 2,
116 START_COLUMN: 11 116 START_COLUMN: 11
117 }, 117 },
118 MESSAGE: 'Expected to find \';\'', 118 MESSAGE: 'Expected to find \';\'',
119 CORRECTION: 'my correction' 119 CORRECTION: 'my correction'
120 }; 120 };
121 AnalysisError error = AnalysisError.fromJson(json); 121 AnalysisError error =
122 new AnalysisError.fromJson(new ResponseDecoder(), 'json', json);
122 { 123 {
123 Location location = error.location; 124 Location location = error.location;
124 expect(location.file, '/test.dart'); 125 expect(location.file, '/test.dart');
125 expect(location.offset, 19); 126 expect(location.offset, 19);
126 expect(location.length, 1); 127 expect(location.length, 1);
127 expect(location.startLine, 2); 128 expect(location.startLine, 2);
128 expect(location.startColumn, 11); 129 expect(location.startColumn, 11);
129 } 130 }
130 expect(error.message, "Expected to find ';'"); 131 expect(error.message, "Expected to find ';'");
131 expect(error.severity, 'ERROR'); 132 expect(error.severity, ErrorSeverity.ERROR);
132 expect(error.type, 'SYNTACTIC_ERROR'); 133 expect(error.type, ErrorType.SYNTACTIC_ERROR);
133 expect(error.correction, "my correction"); 134 expect(error.correction, "my correction");
134 } 135 }
135 136
136 void test_engineErrorsToJson() { 137 void test_engineErrorsToJson() {
137 var json = engineErrorsToJson(lineInfo, [engineError]); 138 var json = engineErrorsToJson(lineInfo, [engineError]);
138 expect(json, unorderedEquals([{ 139 expect(json, unorderedEquals([{
139 'severity': 'ERROR', 140 'severity': 'ERROR',
140 'type': 'COMPILE_TIME_ERROR', 141 'type': 'COMPILE_TIME_ERROR',
141 'location': { 142 'location': {
142 'file': 'foo.dart', 143 'file': 'foo.dart',
143 'offset': 10, 144 'offset': 10,
144 'length': 20, 145 'length': 20,
145 'startLine': 3, 146 'startLine': 3,
146 'startColumn': 2 147 'startColumn': 2
147 }, 148 },
148 'message': 'my message' 149 'message': 'my message'
149 }])); 150 }]));
150 } 151 }
151 } 152 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/analysis_server_test.dart ('k') | pkg/analysis_server/test/domain_analysis_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698