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

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

Issue 415263002: Drop 'errorToJson', use server's AnalysisError. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | 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'; 7 import 'package:analysis_server/src/computer/element.dart';
8 import 'package:analysis_server/src/computer/error.dart'; 8 import 'package:analysis_server/src/computer/error.dart';
9 import 'package:analysis_services/constants.dart'; 9 import 'package:analysis_services/constants.dart';
10 import 'package:analysis_testing/abstract_single_unit.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/element.dart' as engine;
13 import 'package:analyzer/src/generated/engine.dart' as engine;
14 import 'package:analyzer/src/generated/error.dart' as engine; 12 import 'package:analyzer/src/generated/error.dart' as engine;
15 import 'package:analyzer/src/generated/utilities_dart.dart' as engine; 13 import 'package:analyzer/src/generated/source.dart';
14 import 'package:typed_mock/typed_mock.dart';
16 import 'package:unittest/unittest.dart'; 15 import 'package:unittest/unittest.dart';
17 16
18 17
19 18
20 main() { 19 main() {
21 groupSep = ' | '; 20 groupSep = ' | ';
22 runReflectiveTests(AnalysisErrorTest); 21 runReflectiveTests(AnalysisErrorTest);
23 } 22 }
24 23
25 24
25 class AnalysisErrorMock extends TypedMock implements engine.AnalysisError {
26 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
27 }
28
29
26 @ReflectiveTestCase() 30 @ReflectiveTestCase()
27 class AnalysisErrorTest extends AbstractSingleUnitTest { 31 class AnalysisErrorTest {
28 void test_fromEngine() { 32 Source source = new MockSource();
29 verifyNoTestUnitErrors = false; 33 LineInfo lineInfo;
30 resolveTestUnit(''' 34 engine.AnalysisError engineError = new AnalysisErrorMock();
31 main() { 35
32 print(42) 36 void setUp() {
33 } 37 // prepare Source
34 '''); 38 when(source.fullName).thenReturn('foo.dart');
35 engine.AnalysisErrorInfo errors = context.getErrors(testSource); 39 // prepare LineInfo
36 engine.AnalysisError engineError = errors.errors[0]; 40 lineInfo = new LineInfo([0, 5, 9, 20]);
37 AnalysisError error = 41 // prepare AnalysisError
38 new AnalysisError.fromEngine(errors.lineInfo, engineError); 42 when(engineError.source).thenReturn(source);
39 { 43 when(
40 Location location = error.location; 44 engineError.errorCode).thenReturn(engine.CompileTimeErrorCode.AMBIGUOUS_ EXPORT);
41 expect(location.file, testFile); 45 when(engineError.message).thenReturn('my message');
42 expect(location.offset, 19); 46 when(engineError.offset).thenReturn(10);
43 expect(location.length, 1); 47 when(engineError.length).thenReturn(20);
44 expect(location.startLine, 2); 48 }
45 expect(location.startColumn, 11); 49
46 } 50 void tearDown() {
47 expect(error.message, "Expected to find ';'"); 51 source = null;
48 expect(error.severity, "ERROR"); 52 engineError = null;
49 expect(error.type, "SYNTACTIC_ERROR"); 53 }
50 expect( 54
51 error.toString(), 55 void test_fromEngine_hasCorrection() {
52 'AnalysisError(location=Location(file=/test.dart; offset=19; ' 56 when(engineError.correction).thenReturn('my correction');
53 'length=1; startLine=2; startColumn=11) ' 57 AnalysisError error = new AnalysisError.fromEngine(lineInfo, engineError);
54 'message=Expected to find \';\'; severity=ERROR; ' 58 expect(error.toJson(), {
55 'type=SYNTACTIC_ERROR; correction=null'); 59 SEVERITY: 'ERROR',
60 TYPE: 'COMPILE_TIME_ERROR',
61 LOCATION: {
62 FILE: 'foo.dart',
63 OFFSET: 10,
64 LENGTH: 20,
65 START_LINE: 3,
66 START_COLUMN: 2
67 },
68 MESSAGE: 'my message',
69 CORRECTION: 'my correction'
70 });
71 }
72
73 void test_fromEngine_noCorrection() {
74 when(engineError.correction).thenReturn(null);
75 AnalysisError error = new AnalysisError.fromEngine(lineInfo, engineError);
76 expect(error.toJson(), {
77 SEVERITY: 'ERROR',
78 TYPE: 'COMPILE_TIME_ERROR',
79 LOCATION: {
80 FILE: 'foo.dart',
81 OFFSET: 10,
82 LENGTH: 20,
83 START_LINE: 3,
84 START_COLUMN: 2
85 },
86 MESSAGE: 'my message'
87 });
88 }
89
90 void test_fromEngine_noLineInfo() {
91 when(engineError.correction).thenReturn(null);
92 AnalysisError error = new AnalysisError.fromEngine(null, engineError);
93 expect(error.toJson(), {
94 SEVERITY: 'ERROR',
95 TYPE: 'COMPILE_TIME_ERROR',
96 LOCATION: {
97 FILE: 'foo.dart',
98 OFFSET: 10,
99 LENGTH: 20,
100 START_LINE: -1,
101 START_COLUMN: -1
102 },
103 MESSAGE: 'my message'
104 });
56 } 105 }
57 106
58 void test_fromJson() { 107 void test_fromJson() {
59 var json = { 108 var json = {
60 SEVERITY: 'ERROR', 109 SEVERITY: 'ERROR',
61 TYPE: 'SYNTACTIC_ERROR', 110 TYPE: 'SYNTACTIC_ERROR',
62 LOCATION: { 111 LOCATION: {
63 FILE: '/test.dart', 112 FILE: '/test.dart',
64 OFFSET: 19, 113 OFFSET: 19,
65 LENGTH: 1, 114 LENGTH: 1,
66 START_LINE: 2, 115 START_LINE: 2,
67 START_COLUMN: 11 116 START_COLUMN: 11
68 }, 117 },
69 MESSAGE: 'Expected to find \';\'' 118 MESSAGE: 'Expected to find \';\'',
119 CORRECTION: 'my correction'
70 }; 120 };
71 AnalysisError error = AnalysisError.fromJson(json); 121 AnalysisError error = AnalysisError.fromJson(json);
72 { 122 {
73 Location location = error.location; 123 Location location = error.location;
74 expect(location.file, testFile); 124 expect(location.file, '/test.dart');
75 expect(location.offset, 19); 125 expect(location.offset, 19);
76 expect(location.length, 1); 126 expect(location.length, 1);
77 expect(location.startLine, 2); 127 expect(location.startLine, 2);
78 expect(location.startColumn, 11); 128 expect(location.startColumn, 11);
79 } 129 }
80 expect(error.message, "Expected to find ';'"); 130 expect(error.message, "Expected to find ';'");
81 expect(error.severity, "ERROR"); 131 expect(error.severity, 'ERROR');
82 expect(error.type, "SYNTACTIC_ERROR"); 132 expect(error.type, 'SYNTACTIC_ERROR');
133 expect(error.correction, "my correction");
83 } 134 }
84 135
85 void test_toJson() { 136 void test_engineErrorsToJson() {
86 verifyNoTestUnitErrors = false; 137 var json = engineErrorsToJson(lineInfo, [engineError]);
87 resolveTestUnit(''' 138 expect(json, unorderedEquals([{
88 main() { 139 'severity': 'ERROR',
89 print(42) 140 'type': 'COMPILE_TIME_ERROR',
90 } 141 'location': {
91 '''); 142 'file': 'foo.dart',
92 engine.AnalysisErrorInfo errors = context.getErrors(testSource); 143 'offset': 10,
93 engine.AnalysisError engineError = errors.errors[0]; 144 'length': 20,
94 AnalysisError error = 145 'startLine': 3,
95 new AnalysisError.fromEngine(errors.lineInfo, engineError); 146 'startColumn': 2
96 expect(error.toJson(), { 147 },
97 SEVERITY: 'ERROR', 148 'message': 'my message'
98 TYPE: 'SYNTACTIC_ERROR', 149 }]));
99 LOCATION: {
100 FILE: '/test.dart',
101 OFFSET: 19,
102 LENGTH: 1,
103 START_LINE: 2,
104 START_COLUMN: 11
105 },
106 MESSAGE: 'Expected to find \';\''
107 });
108 } 150 }
109 } 151 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698