| 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 test.operation.analysis; | 5 library test.operation.analysis; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/constants.dart'; |
| 7 import 'package:analysis_server/src/operation/operation_analysis.dart'; | 8 import 'package:analysis_server/src/operation/operation_analysis.dart'; |
| 8 import 'package:analyzer/src/generated/error.dart'; | 9 import 'package:analyzer/src/generated/error.dart'; |
| 9 import 'package:analyzer/src/generated/source.dart'; | 10 import 'package:analyzer/src/generated/source.dart'; |
| 10 import 'package:typed_mock/typed_mock.dart'; | 11 import 'package:typed_mock/typed_mock.dart'; |
| 11 import 'package:unittest/unittest.dart'; | 12 import 'package:unittest/unittest.dart'; |
| 12 | 13 |
| 14 import '../index/store/typed_mocks.dart'; |
| 13 import '../reflective_tests.dart'; | 15 import '../reflective_tests.dart'; |
| 14 | 16 |
| 15 main() { | 17 main() { |
| 16 groupSep = ' | '; | 18 groupSep = ' | '; |
| 17 | 19 |
| 18 group('errorToJson', () { | 20 group('errorToJson', () { |
| 19 runReflectiveTests(Test_errorToJson); | 21 runReflectiveTests(Test_errorToJson); |
| 20 }); | 22 }); |
| 21 } | 23 } |
| 22 | 24 |
| 23 | 25 |
| 26 class AnalysisErrorMock extends TypedMock implements AnalysisError { |
| 27 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 28 } |
| 29 |
| 30 |
| 24 @ReflectiveTestCase() | 31 @ReflectiveTestCase() |
| 25 class Test_errorToJson { | 32 class Test_errorToJson { |
| 26 Source source = new SourceMock(); | 33 Source source = new SourceMock(); |
| 34 LineInfo lineInfo; |
| 27 AnalysisError analysisError = new AnalysisErrorMock(); | 35 AnalysisError analysisError = new AnalysisErrorMock(); |
| 28 | 36 |
| 29 setUp() { | 37 void setUp() { |
| 30 // prepare Source | 38 // prepare Source |
| 31 when(source.fullName).thenReturn('foo.dart'); | 39 when(source.fullName).thenReturn('foo.dart'); |
| 40 // prepare LineInfo |
| 41 lineInfo = new LineInfo([0, 5, 9, 20]); |
| 32 // prepare AnalysisError | 42 // prepare AnalysisError |
| 33 when(analysisError.source).thenReturn(source); | 43 when(analysisError.source).thenReturn(source); |
| 34 when(analysisError.errorCode).thenReturn(CompileTimeErrorCode.AMBIGUOUS_EXPO
RT); | 44 when(analysisError.errorCode).thenReturn( |
| 45 CompileTimeErrorCode.AMBIGUOUS_EXPORT); |
| 35 when(analysisError.message).thenReturn('my message'); | 46 when(analysisError.message).thenReturn('my message'); |
| 36 when(analysisError.offset).thenReturn(10); | 47 when(analysisError.offset).thenReturn(10); |
| 37 when(analysisError.length).thenReturn(20); | 48 when(analysisError.length).thenReturn(20); |
| 38 } | 49 } |
| 39 | 50 |
| 40 tearDown() { | 51 void tearDown() { |
| 41 source = null; | 52 source = null; |
| 42 analysisError = null; | 53 analysisError = null; |
| 43 } | 54 } |
| 44 | 55 |
| 45 test_noCorrection() { | 56 void test_noCorrection() { |
| 46 when(analysisError.correction).thenReturn('my correction'); | 57 Map<String, Object> json = errorToJson(lineInfo, analysisError); |
| 47 Map<String, Object> json = errorToJson(analysisError); | |
| 48 expect(json, { | 58 expect(json, { |
| 49 'file': 'foo.dart', | 59 ERROR_CODE: 'CompileTimeErrorCode.AMBIGUOUS_EXPORT', |
| 50 'errorCode': 'CompileTimeErrorCode.AMBIGUOUS_EXPORT', | 60 SEVERITY: 'ERROR', |
| 51 'offset': 10, | 61 TYPE: 'COMPILE_TIME_ERROR', |
| 52 'length': 20, | 62 LOCATION: { |
| 53 'message': 'my message', | 63 FILE: 'foo.dart', |
| 54 'correction': 'my correction'}); | 64 OFFSET: 10, |
| 65 LENGTH: 20, |
| 66 START_LINE: 3, |
| 67 START_COLUMN: 2 |
| 68 }, |
| 69 MESSAGE: 'my message' |
| 70 }); |
| 55 } | 71 } |
| 56 | 72 |
| 57 test_withCorrection() { | 73 void test_noLineInfo() { |
| 58 Map<String, Object> json = errorToJson(analysisError); | 74 Map<String, Object> json = errorToJson(null, analysisError); |
| 59 expect(json, { | 75 expect(json, { |
| 60 'file': 'foo.dart', | 76 ERROR_CODE: 'CompileTimeErrorCode.AMBIGUOUS_EXPORT', |
| 61 'errorCode': 'CompileTimeErrorCode.AMBIGUOUS_EXPORT', | 77 SEVERITY: 'ERROR', |
| 62 'offset': 10, | 78 TYPE: 'COMPILE_TIME_ERROR', |
| 63 'length': 20, | 79 LOCATION: { |
| 64 'message': 'my message'}); | 80 FILE: 'foo.dart', |
| 81 OFFSET: 10, |
| 82 LENGTH: 20 |
| 83 }, |
| 84 MESSAGE: 'my message' |
| 85 }); |
| 86 } |
| 87 |
| 88 void test_withCorrection() { |
| 89 when(analysisError.correction).thenReturn('my correction'); |
| 90 Map<String, Object> json = errorToJson(lineInfo, analysisError); |
| 91 expect(json, { |
| 92 ERROR_CODE: 'CompileTimeErrorCode.AMBIGUOUS_EXPORT', |
| 93 SEVERITY: 'ERROR', |
| 94 TYPE: 'COMPILE_TIME_ERROR', |
| 95 LOCATION: { |
| 96 FILE: 'foo.dart', |
| 97 OFFSET: 10, |
| 98 LENGTH: 20, |
| 99 START_LINE: 3, |
| 100 START_COLUMN: 2 |
| 101 }, |
| 102 MESSAGE: 'my message', |
| 103 CORRECTION: 'my correction' |
| 104 }); |
| 65 } | 105 } |
| 66 } | 106 } |
| 67 | |
| 68 | |
| 69 class SourceMock extends TypedMock implements Source { | |
| 70 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | |
| 71 } | |
| 72 | |
| 73 | |
| 74 class AnalysisErrorMock extends TypedMock implements AnalysisError { | |
| 75 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | |
| 76 } | |
| OLD | NEW |