OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 idlparser_test; | 5 library idlparser_test; |
6 | 6 |
7 import '../../../utils/peg/pegparser.dart'; | 7 import '../../../utils/peg/pegparser.dart'; |
8 | 8 |
9 part 'idlparser.dart'; | 9 part 'idlparser.dart'; |
10 part 'idlrenderer.dart'; | 10 part 'idlrenderer.dart'; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 try { | 88 try { |
89 ast = grammar.parse(rule, input); | 89 ast = grammar.parse(rule, input); |
90 } catch (exception) { | 90 } catch (exception) { |
91 ast = exception; | 91 ast = exception; |
92 } | 92 } |
93 | 93 |
94 var formatted = ast; | 94 var formatted = ast; |
95 if (expected is String) | 95 if (expected is String) |
96 formatted = printList(ast); | 96 formatted = printList(ast); |
97 | 97 |
98 Expect.equals(expected, formatted, "parse: $input"); | 98 if (expected != formatted) { |
| 99 throw new StateError("parse: $input"); |
| 100 } |
99 } | 101 } |
100 | 102 |
101 // Prints the list in [1,2,3] notation, including nested lists. | 103 // Prints the list in [1,2,3] notation, including nested lists. |
102 void printList(item) { | 104 void printList(item) { |
103 if (item is List) { | 105 if (item is List) { |
104 StringBuffer sb = new StringBuffer(); | 106 StringBuffer sb = new StringBuffer(); |
105 sb.add('['); | 107 sb.add('['); |
106 var sep = ''; | 108 var sep = ''; |
107 for (var x in item) { | 109 for (var x in item) { |
108 sb.add(sep); | 110 sb.add(sep); |
109 sb.add(printList(x)); | 111 sb.add(printList(x)); |
110 sep = ','; | 112 sep = ','; |
111 } | 113 } |
112 sb.add(']'); | 114 sb.add(']'); |
113 return sb.toString(); | 115 return sb.toString(); |
114 } | 116 } |
115 if (item == null) | 117 if (item == null) |
116 return 'null'; | 118 return 'null'; |
117 return item.toString(); | 119 return item.toString(); |
118 } | 120 } |
OLD | NEW |