| 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 package com.google.dart.compiler.parser; | 5 package com.google.dart.compiler.parser; |
| 6 | 6 |
| 7 import com.google.common.base.Joiner; | 7 import com.google.common.base.Joiner; |
| 8 import com.google.dart.compiler.DartCompilerListener; | 8 import com.google.dart.compiler.DartCompilerListener; |
| 9 import com.google.dart.compiler.DartSourceTest; | 9 import com.google.dart.compiler.DartSourceTest; |
| 10 import com.google.dart.compiler.ast.DartArrayLiteral; | 10 import com.google.dart.compiler.ast.DartArrayLiteral; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 126 } |
| 127 | 127 |
| 128 public void testTryCatch () { | 128 public void testTryCatch () { |
| 129 DartUnit unit = parseUnit("TryCatch.dart"); | 129 DartUnit unit = parseUnit("TryCatch.dart"); |
| 130 | 130 |
| 131 List<DartNode> nodes = unit.getTopLevelNodes(); | 131 List<DartNode> nodes = unit.getTopLevelNodes(); |
| 132 assertEquals(7, nodes.size()); | 132 assertEquals(7, nodes.size()); |
| 133 | 133 |
| 134 DartTryStatement tryCatch; | 134 DartTryStatement tryCatch; |
| 135 DartMethodDefinition a = (DartMethodDefinition) nodes.get(2); | 135 DartMethodDefinition a = (DartMethodDefinition) nodes.get(2); |
| 136 assertEquals("a", ((DartIdentifier)a.getName()).getTargetName()); | 136 assertEquals("a", ((DartIdentifier)a.getName()).getName()); |
| 137 tryCatch = (DartTryStatement) a.getFunction().getBody().getStatements().get(
0); | 137 tryCatch = (DartTryStatement) a.getFunction().getBody().getStatements().get(
0); |
| 138 assertEquals(1, tryCatch.getCatchBlocks().size()); | 138 assertEquals(1, tryCatch.getCatchBlocks().size()); |
| 139 assertNotNull(tryCatch.getFinallyBlock()); | 139 assertNotNull(tryCatch.getFinallyBlock()); |
| 140 | 140 |
| 141 DartMethodDefinition b = (DartMethodDefinition) nodes.get(3); | 141 DartMethodDefinition b = (DartMethodDefinition) nodes.get(3); |
| 142 assertEquals("b", ((DartIdentifier)b.getName()).getTargetName()); | 142 assertEquals("b", ((DartIdentifier)b.getName()).getName()); |
| 143 tryCatch = (DartTryStatement) b.getFunction().getBody().getStatements().get(
0); | 143 tryCatch = (DartTryStatement) b.getFunction().getBody().getStatements().get(
0); |
| 144 assertEquals(1, tryCatch.getCatchBlocks().size()); | 144 assertEquals(1, tryCatch.getCatchBlocks().size()); |
| 145 assertNull(tryCatch.getFinallyBlock()); | 145 assertNull(tryCatch.getFinallyBlock()); |
| 146 | 146 |
| 147 DartMethodDefinition c = (DartMethodDefinition) nodes.get(4); | 147 DartMethodDefinition c = (DartMethodDefinition) nodes.get(4); |
| 148 assertEquals("c", ((DartIdentifier)c.getName()).getTargetName()); | 148 assertEquals("c", ((DartIdentifier)c.getName()).getName()); |
| 149 tryCatch = (DartTryStatement) c.getFunction().getBody().getStatements().get(
0); | 149 tryCatch = (DartTryStatement) c.getFunction().getBody().getStatements().get(
0); |
| 150 assertEquals(0, tryCatch.getCatchBlocks().size()); | 150 assertEquals(0, tryCatch.getCatchBlocks().size()); |
| 151 assertNotNull(tryCatch.getFinallyBlock()); | 151 assertNotNull(tryCatch.getFinallyBlock()); |
| 152 | 152 |
| 153 DartMethodDefinition d = (DartMethodDefinition) nodes.get(5); | 153 DartMethodDefinition d = (DartMethodDefinition) nodes.get(5); |
| 154 assertEquals("d", ((DartIdentifier)d.getName()).getTargetName()); | 154 assertEquals("d", ((DartIdentifier)d.getName()).getName()); |
| 155 tryCatch = (DartTryStatement) d.getFunction().getBody().getStatements().get(
0); | 155 tryCatch = (DartTryStatement) d.getFunction().getBody().getStatements().get(
0); |
| 156 assertEquals(2, tryCatch.getCatchBlocks().size()); | 156 assertEquals(2, tryCatch.getCatchBlocks().size()); |
| 157 assertNull(tryCatch.getFinallyBlock()); | 157 assertNull(tryCatch.getFinallyBlock()); |
| 158 | 158 |
| 159 DartMethodDefinition e = (DartMethodDefinition) nodes.get(6); | 159 DartMethodDefinition e = (DartMethodDefinition) nodes.get(6); |
| 160 assertEquals("e", ((DartIdentifier)e.getName()).getTargetName()); | 160 assertEquals("e", ((DartIdentifier)e.getName()).getName()); |
| 161 tryCatch = (DartTryStatement) e.getFunction().getBody().getStatements().get(
0); | 161 tryCatch = (DartTryStatement) e.getFunction().getBody().getStatements().get(
0); |
| 162 assertEquals(2, tryCatch.getCatchBlocks().size()); | 162 assertEquals(2, tryCatch.getCatchBlocks().size()); |
| 163 assertNotNull(tryCatch.getFinallyBlock()); | 163 assertNotNull(tryCatch.getFinallyBlock()); |
| 164 | 164 |
| 165 parseUnitErrors("TryCatchNegative.dart", | 165 parseUnitErrors("TryCatchNegative.dart", |
| 166 ParserErrorCode.CATCH_OR_FINALLY_EXPECTED, 8, 3); | 166 ParserErrorCode.CATCH_OR_FINALLY_EXPECTED, 8, 3); |
| 167 } | 167 } |
| 168 | 168 |
| 169 public void testArrayLiteral() { | 169 public void testArrayLiteral() { |
| 170 DartUnit unit = parseUnit("phony_array_literal.dart", "var x = <int>[1,2,3];
"); | 170 DartUnit unit = parseUnit("phony_array_literal.dart", "var x = <int>[1,2,3];
"); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 Joiner.on("\n").join( | 217 Joiner.on("\n").join( |
| 218 "class A {", | 218 "class A {", |
| 219 " pref.A foo() {", | 219 " pref.A foo() {", |
| 220 " return new pref.A();", | 220 " return new pref.A();", |
| 221 " }", | 221 " }", |
| 222 "}")); | 222 "}")); |
| 223 List<DartNode> nodes = unit.getTopLevelNodes(); | 223 List<DartNode> nodes = unit.getTopLevelNodes(); |
| 224 assertEquals(1, nodes.size()); | 224 assertEquals(1, nodes.size()); |
| 225 } | 225 } |
| 226 } | 226 } |
| OLD | NEW |