| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library test.computer.error; | |
| 6 | |
| 7 import 'package:analysis_server/src/constants.dart'; | |
| 8 import 'package:analysis_server/src/protocol_server.dart'; | |
| 9 import 'package:analyzer/src/generated/error.dart' as engine; | |
| 10 import 'package:analyzer/src/generated/source.dart'; | |
| 11 import 'package:typed_mock/typed_mock.dart'; | |
| 12 import 'package:unittest/unittest.dart'; | |
| 13 | |
| 14 import '../mocks.dart'; | |
| 15 import '../reflective_tests.dart'; | |
| 16 | |
| 17 | |
| 18 | |
| 19 main() { | |
| 20 groupSep = ' | '; | |
| 21 runReflectiveTests(AnalysisErrorTest); | |
| 22 } | |
| 23 | |
| 24 | |
| 25 class AnalysisErrorMock extends TypedMock implements engine.AnalysisError { | |
| 26 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | |
| 27 } | |
| 28 | |
| 29 | |
| 30 @ReflectiveTestCase() | |
| 31 class AnalysisErrorTest { | |
| 32 Source source = new MockSource(); | |
| 33 LineInfo lineInfo; | |
| 34 engine.AnalysisError engineError = new AnalysisErrorMock(); | |
| 35 | |
| 36 void setUp() { | |
| 37 // prepare Source | |
| 38 when(source.fullName).thenReturn('foo.dart'); | |
| 39 // prepare LineInfo | |
| 40 lineInfo = new LineInfo([0, 5, 9, 20]); | |
| 41 // prepare AnalysisError | |
| 42 when(engineError.source).thenReturn(source); | |
| 43 when( | |
| 44 engineError.errorCode).thenReturn(engine.CompileTimeErrorCode.AMBIGUOUS_
EXPORT); | |
| 45 when(engineError.message).thenReturn('my message'); | |
| 46 when(engineError.offset).thenReturn(10); | |
| 47 when(engineError.length).thenReturn(20); | |
| 48 } | |
| 49 | |
| 50 void tearDown() { | |
| 51 source = null; | |
| 52 engineError = null; | |
| 53 } | |
| 54 | |
| 55 void test_fromEngine_hasCorrection() { | |
| 56 when(engineError.correction).thenReturn('my correction'); | |
| 57 AnalysisError error = newAnalysisError_fromEngine(lineInfo, engineError); | |
| 58 expect(error.toJson(), { | |
| 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 = newAnalysisError_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 = newAnalysisError_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 }); | |
| 105 } | |
| 106 } | |
| OLD | NEW |