| 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 // Unit test of the [NativeBehavior.processSpecString] method. | 5 // Unit test of the [NativeBehavior.processSpecString] method. |
| 6 | 6 |
| 7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
| 8 import 'package:compiler/src/native/native.dart'; | 8 import 'package:compiler/src/native/native.dart'; |
| 9 import 'package:compiler/src/dart2jslib.dart' | 9 import 'package:compiler/src/dart2jslib.dart' |
| 10 show DiagnosticListener; | 10 show DiagnosticListener; |
| 11 import 'package:compiler/src/universe/universe.dart' | 11 import 'package:compiler/src/universe/universe.dart' |
| 12 show SideEffects; | 12 show SideEffects; |
| 13 | 13 |
| 14 const OBJECT = 'Object'; | 14 const OBJECT = 'Object'; |
| 15 const NULL = 'Null'; | 15 const NULL = 'Null'; |
| 16 | 16 |
| 17 class Listener implements DiagnosticListener { | 17 class Listener implements DiagnosticListener { |
| 18 String errorMessage; | 18 String errorMessage; |
| 19 internalError(spannable, message) { | 19 internalError(spannable, message) { |
| 20 errorMessage = message; | 20 errorMessage = message; |
| 21 throw "error"; | 21 throw "error"; |
| 22 } | 22 } |
| 23 reportError(spannable, kind, arguments) { |
| 24 errorMessage = '$arguments'; // E.g. "{text: Duplicate tag 'new'.}" |
| 25 throw "error"; |
| 26 } |
| 23 | 27 |
| 24 noSuchMethod(_) => null; | 28 noSuchMethod(_) => null; |
| 25 } | 29 } |
| 26 | 30 |
| 27 void test(String specString, | 31 void test(String specString, |
| 28 {List returns, | 32 {List returns, |
| 29 List creates, | 33 List creates, |
| 30 SideEffects expectedSideEffects, | 34 SideEffects expectedSideEffects, |
| 31 NativeThrowBehavior expectedThrows, | 35 NativeThrowBehavior expectedThrows, |
| 32 bool expectedNew, | 36 bool expectedNew, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 46 specString, | 50 specString, |
| 47 setSideEffects: (effects) { actualSideEffects = effects; }, | 51 setSideEffects: (effects) { actualSideEffects = effects; }, |
| 48 setThrows: (b) { actualThrows = b; }, | 52 setThrows: (b) { actualThrows = b; }, |
| 49 setIsAllocation: (b) { actualNew = b; }, | 53 setIsAllocation: (b) { actualNew = b; }, |
| 50 setUseGvn: (b) { actualGvn = b; }, | 54 setUseGvn: (b) { actualGvn = b; }, |
| 51 resolveType: (t) => t, | 55 resolveType: (t) => t, |
| 52 typesReturned: actualReturns, typesInstantiated: actualCreates, | 56 typesReturned: actualReturns, typesInstantiated: actualCreates, |
| 53 objectType: OBJECT, nullType: NULL); | 57 objectType: OBJECT, nullType: NULL); |
| 54 } catch (e) { | 58 } catch (e) { |
| 55 Expect.isTrue(expectError); | 59 Expect.isTrue(expectError); |
| 56 Expect.isNotNull(listener.errorMessage, 'Internal error expected.'); | 60 Expect.isNotNull(listener.errorMessage, 'Error expected.'); |
| 57 return; | 61 return; |
| 58 } | 62 } |
| 59 Expect.isNull(listener.errorMessage, 'Unexpected internal error.'); | 63 Expect.isNull(listener.errorMessage, 'Unexpected error.'); |
| 60 if (returns != null) { | 64 if (returns != null) { |
| 61 Expect.listEquals(returns, actualReturns, 'Unexpected returns.'); | 65 Expect.listEquals(returns, actualReturns, 'Unexpected returns.'); |
| 62 } | 66 } |
| 63 if (creates != null) { | 67 if (creates != null) { |
| 64 Expect.listEquals(creates, actualCreates, 'Unexpected creates.'); | 68 Expect.listEquals(creates, actualCreates, 'Unexpected creates.'); |
| 65 } | 69 } |
| 66 Expect.equals(expectedSideEffects, actualSideEffects); | 70 Expect.equals(expectedSideEffects, actualSideEffects); |
| 67 Expect.equals(expectedThrows, actualThrows); | 71 Expect.equals(expectedThrows, actualThrows); |
| 68 Expect.equals(expectedNew, actualNew); | 72 Expect.equals(expectedNew, actualNew); |
| 69 Expect.equals(expectedGvn, actualGvn); | 73 Expect.equals(expectedGvn, actualGvn); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 test('gvn:false', expectedGvn: false); | 276 test('gvn:false', expectedGvn: false); |
| 273 test('returns:A;gvn:true', returns: ['A'], expectedGvn: true); | 277 test('returns:A;gvn:true', returns: ['A'], expectedGvn: true); |
| 274 test(' gvn : true ; returns:A;', returns: ['A'], expectedGvn: true); | 278 test(' gvn : true ; returns:A;', returns: ['A'], expectedGvn: true); |
| 275 test('gvn:true;returns:A;gvn:true', expectError: true); | 279 test('gvn:true;returns:A;gvn:true', expectError: true); |
| 276 | 280 |
| 277 test('gvn: true; new: true', expectError: true); | 281 test('gvn: true; new: true', expectError: true); |
| 278 test('gvn: true; new: false', expectedGvn: true, expectedNew: false); | 282 test('gvn: true; new: false', expectedGvn: true, expectedNew: false); |
| 279 test('gvn: false; new: true', expectedGvn: false, expectedNew: true); | 283 test('gvn: false; new: true', expectedGvn: false, expectedNew: true); |
| 280 test('gvn: false; new: false', expectedGvn: false, expectedNew: false); | 284 test('gvn: false; new: false', expectedGvn: false, expectedNew: false); |
| 281 } | 285 } |
| OLD | NEW |