| 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/computer/element.dart'; |
| 8 import 'package:analysis_server/src/computer/error.dart'; |
| 9 import 'package:analysis_services/constants.dart'; |
| 10 import 'package:analysis_testing/abstract_single_unit.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; |
| 15 import 'package:analyzer/src/generated/utilities_dart.dart' as engine; |
| 16 import 'package:unittest/unittest.dart'; |
| 17 |
| 18 |
| 19 |
| 20 main() { |
| 21 groupSep = ' | '; |
| 22 group('AnalysisError', () { |
| 23 runReflectiveTests(AnalysisErrorTest); |
| 24 }); |
| 25 } |
| 26 |
| 27 |
| 28 @ReflectiveTestCase() |
| 29 class AnalysisErrorTest extends AbstractSingleUnitTest { |
| 30 void test_fromEngine() { |
| 31 verifyNoTestUnitErrors = false; |
| 32 resolveTestUnit(''' |
| 33 main() { |
| 34 print(42) |
| 35 } |
| 36 '''); |
| 37 engine.AnalysisErrorInfo errors = context.getErrors(testSource); |
| 38 engine.AnalysisError engineError = errors.errors[0]; |
| 39 AnalysisError error = |
| 40 new AnalysisError.fromEngine(errors.lineInfo, engineError); |
| 41 { |
| 42 Location location = error.location; |
| 43 expect(location.file, testFile); |
| 44 expect(location.offset, 19); |
| 45 expect(location.length, 1); |
| 46 expect(location.startLine, 2); |
| 47 expect(location.startColumn, 11); |
| 48 } |
| 49 expect(error.message, "Expected to find ';'"); |
| 50 expect(error.severity, "ERROR"); |
| 51 expect(error.type, "SYNTACTIC_ERROR"); |
| 52 expect( |
| 53 error.toString(), |
| 54 'AnalysisError(location=Location(file=/test.dart; offset=19; ' |
| 55 'length=1; startLine=2; startColumn=11) ' |
| 56 'message=Expected to find \';\'; severity=ERROR; ' |
| 57 'type=SYNTACTIC_ERROR; correction=null'); |
| 58 } |
| 59 |
| 60 void test_fromJson() { |
| 61 var json = { |
| 62 SEVERITY: 'ERROR', |
| 63 TYPE: 'SYNTACTIC_ERROR', |
| 64 LOCATION: { |
| 65 FILE: '/test.dart', |
| 66 OFFSET: 19, |
| 67 LENGTH: 1, |
| 68 START_LINE: 2, |
| 69 START_COLUMN: 11 |
| 70 }, |
| 71 MESSAGE: 'Expected to find \';\'' |
| 72 }; |
| 73 AnalysisError error = AnalysisError.fromJson(json); |
| 74 { |
| 75 Location location = error.location; |
| 76 expect(location.file, testFile); |
| 77 expect(location.offset, 19); |
| 78 expect(location.length, 1); |
| 79 expect(location.startLine, 2); |
| 80 expect(location.startColumn, 11); |
| 81 } |
| 82 expect(error.message, "Expected to find ';'"); |
| 83 expect(error.severity, "ERROR"); |
| 84 expect(error.type, "SYNTACTIC_ERROR"); |
| 85 } |
| 86 |
| 87 void test_toJson() { |
| 88 verifyNoTestUnitErrors = false; |
| 89 resolveTestUnit(''' |
| 90 main() { |
| 91 print(42) |
| 92 } |
| 93 '''); |
| 94 engine.AnalysisErrorInfo errors = context.getErrors(testSource); |
| 95 engine.AnalysisError engineError = errors.errors[0]; |
| 96 AnalysisError error = |
| 97 new AnalysisError.fromEngine(errors.lineInfo, engineError); |
| 98 expect(error.toJson(), { |
| 99 SEVERITY: 'ERROR', |
| 100 TYPE: 'SYNTACTIC_ERROR', |
| 101 LOCATION: { |
| 102 FILE: '/test.dart', |
| 103 OFFSET: 19, |
| 104 LENGTH: 1, |
| 105 START_LINE: 2, |
| 106 START_COLUMN: 11 |
| 107 }, |
| 108 MESSAGE: 'Expected to find \';\'' |
| 109 }); |
| 110 } |
| 111 } |
| OLD | NEW |