Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// Helper methods for converting a [Mirror] to a [String]. | 5 /// Helper methods for converting a [Mirror] to a [String]. |
| 6 library test.stringify; | 6 library test.stringify; |
| 7 | 7 |
| 8 import 'dart:mirrors'; | 8 import 'dart:mirrors'; |
| 9 | 9 |
| 10 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 var buffer = new StringBuffer(); | 59 var buffer = new StringBuffer(); |
| 60 writeVariableOn(variable, buffer); | 60 writeVariableOn(variable, buffer); |
| 61 return 'Variable($buffer)'; | 61 return 'Variable($buffer)'; |
| 62 } | 62 } |
| 63 | 63 |
| 64 stringifyParameter(ParameterMirror parameter) { | 64 stringifyParameter(ParameterMirror parameter) { |
| 65 var buffer = new StringBuffer(); | 65 var buffer = new StringBuffer(); |
| 66 writeVariableOn(parameter, buffer); | 66 writeVariableOn(parameter, buffer); |
| 67 if (parameter.isOptional) buffer.write(', optional'); | 67 if (parameter.isOptional) buffer.write(', optional'); |
| 68 if (parameter.isNamed) buffer.write(', named'); | 68 if (parameter.isNamed) buffer.write(', named'); |
| 69 if (parameter.hasDefaultValue) { | 69 // TODO(6490,12430): Add this check as soon as it's properly implemented in |
| 70 buffer.write(', value = ${stringify(parameter.defaultValue)}'); | 70 // the VM and dart2js. |
|
ahe
2013/08/13 21:32:55
Remove extra whitespace at beginning of line.
Michael Lippautz (Google)
2013/08/13 21:37:10
Done.
| |
| 71 } | 71 // if (parameter.hasDefaultValue) { |
| 72 // buffer.write(', value = ${stringify(parameter.defaultValue)}'); | |
| 73 // } | |
| 72 // TODO(ahe): Move to writeVariableOn. | 74 // TODO(ahe): Move to writeVariableOn. |
| 73 buffer.write(', type = ${stringify(parameter.type)}'); | 75 buffer.write(', type = ${stringify(parameter.type)}'); |
| 74 return 'Parameter($buffer)'; | 76 return 'Parameter($buffer)'; |
| 75 } | 77 } |
| 76 | 78 |
| 77 stringifyType(TypeMirror type) { | 79 stringifyType(TypeMirror type) { |
| 78 var buffer = new StringBuffer(); | 80 var buffer = new StringBuffer(); |
| 79 writeDeclarationOn(type, buffer); | 81 writeDeclarationOn(type, buffer); |
| 80 return 'Type($buffer)'; | 82 return 'Type($buffer)'; |
| 81 } | 83 } |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 107 if (value is TypeMirror) return stringifyType(value); | 109 if (value is TypeMirror) return stringifyType(value); |
| 108 if (value == null) return '<null>'; | 110 if (value == null) return '<null>'; |
| 109 throw 'Unexpected value: $value'; | 111 throw 'Unexpected value: $value'; |
| 110 } | 112 } |
| 111 | 113 |
| 112 expect(expected, actual) => Expect.stringEquals(expected, stringify(actual)); | 114 expect(expected, actual) => Expect.stringEquals(expected, stringify(actual)); |
| 113 | 115 |
| 114 compareSymbols(Symbol a, Symbol b) { | 116 compareSymbols(Symbol a, Symbol b) { |
| 115 return MirrorSystem.getName(a).compareTo(MirrorSystem.getName(b)); | 117 return MirrorSystem.getName(a).compareTo(MirrorSystem.getName(b)); |
| 116 } | 118 } |
| OLD | NEW |