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 |
Brian Wilkerson
2012/06/25 14:24:38
nit: copyright year
scheglov
2012/06/26 19:46:34
Done.
| |
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 static com.google.dart.compiler.parser.ParserEventsTest.Mark.ArrayLiteral ; | 7 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.ArrayLiteral ; |
8 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.BinaryExpres sion; | 8 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.BinaryExpres sion; |
9 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.Block; | 9 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.Block; |
10 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.BreakStateme nt; | 10 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.BreakStateme nt; |
11 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.CatchClause; | 11 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.CatchClause; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.TypeAnnotati on; | 60 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.TypeAnnotati on; |
61 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.TypeArgument s; | 61 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.TypeArgument s; |
62 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.TypeExpressi on; | 62 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.TypeExpressi on; |
63 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.TypeFunction OrVarable; | 63 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.TypeFunction OrVarable; |
64 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.TypeParamete r; | 64 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.TypeParamete r; |
65 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.UnaryExpress ion; | 65 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.UnaryExpress ion; |
66 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.VarDeclarati on; | 66 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.VarDeclarati on; |
67 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.VariableDecl aration; | 67 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.VariableDecl aration; |
68 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.WhileStateme nt; | 68 import static com.google.dart.compiler.parser.ParserEventsTest.Mark.WhileStateme nt; |
69 | 69 |
70 import com.google.common.collect.Sets; | |
71 import com.google.dart.compiler.DartCompilerListener; | |
72 import com.google.dart.compiler.Source; | |
73 import com.google.dart.compiler.metrics.CompilerMetrics; | |
74 | |
70 import java.util.HashSet; | 75 import java.util.HashSet; |
71 import java.util.LinkedHashSet; | 76 import java.util.LinkedHashSet; |
77 import java.util.Set; | |
72 | 78 |
73 public class ParserEventsTest extends AbstractParserTest { | 79 public class ParserEventsTest extends AbstractParserTest { |
74 | 80 |
75 /** | 81 /** |
76 * A collection of marks representing interesting parser states. Copied from | 82 * A collection of marks representing interesting parser states. Copied from |
77 * com.google.dart.tools.core.internal.completion. | 83 * com.google.dart.tools.core.internal.completion. |
78 * <p> | 84 * <p> |
79 * TODO(messick) Find a way to share the implementation of Mark. | 85 * TODO(messick) Find a way to share the implementation of Mark. |
80 */ | 86 */ |
81 static enum Mark { | 87 static enum Mark { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 super.rollback(); | 186 super.rollback(); |
181 Mark lastMark = null; | 187 Mark lastMark = null; |
182 for (Mark mark: marks) { | 188 for (Mark mark: marks) { |
183 lastMark = mark; | 189 lastMark = mark; |
184 } | 190 } |
185 if (lastMark != null) { | 191 if (lastMark != null) { |
186 marks.remove(lastMark); | 192 marks.remove(lastMark); |
187 } | 193 } |
188 } | 194 } |
189 | 195 |
190 public ParserEventRecorder(ParserContext ctx) { | 196 public ParserEventRecorder(Source source, |
191 super(ctx); | 197 String sourceCode, |
198 boolean isDietParse, | |
199 Set<String> prefixes, | |
200 DartCompilerListener listener, | |
201 CompilerMetrics compilerMetrics) { | |
202 super(source, sourceCode, isDietParse, prefixes, listener, compilerMetrics ); | |
192 marks = new LinkedHashSet<Mark>(); | 203 marks = new LinkedHashSet<Mark>(); |
193 } | 204 } |
194 | 205 |
195 @SuppressWarnings({"unchecked", "rawtypes"}) | 206 @SuppressWarnings({"unchecked", "rawtypes"}) |
196 public HashSet<Mark> copyMarks() { | 207 public HashSet<Mark> copyMarks() { |
197 return (HashSet) marks.clone(); | 208 return (HashSet) marks.clone(); |
198 } | 209 } |
199 | 210 |
200 @Override | 211 @Override |
201 protected void beginArrayLiteral() { | 212 protected void beginArrayLiteral() { |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
745 } | 756 } |
746 | 757 |
747 @Override | 758 @Override |
748 public void testTopLevel() { | 759 public void testTopLevel() { |
749 parseUnit("TopLevel.dart"); | 760 parseUnit("TopLevel.dart"); |
750 compareMarks(ArrayLiteral, CompilationUnit, PostfixExpression, NativeBody, L iteral, Identifier, | 761 compareMarks(ArrayLiteral, CompilationUnit, PostfixExpression, NativeBody, L iteral, Identifier, |
751 ClassMember, Block, MethodName, TopLevelElement, TypeAnnotation, Express ion, | 762 ClassMember, Block, MethodName, TopLevelElement, TypeAnnotation, Express ion, |
752 QualifiedIdentifier, ConditionalExpression, BinaryExpression, VariableDe claration, | 763 QualifiedIdentifier, ConditionalExpression, BinaryExpression, VariableDe claration, |
753 FormalParameterList); | 764 FormalParameterList); |
754 } | 765 } |
755 | 766 |
756 @Override | 767 @Override |
757 protected DartParser makeParser(ParserContext context) { | 768 protected DartParser makeParser(Source src, String sourceCode, DartCompilerLis tener listener) { |
758 recorder = new ParserEventRecorder(context); | 769 recorder = new ParserEventRecorder(src, sourceCode, false, Sets.<String>newH ashSet(), listener, null); |
759 return recorder; | 770 return recorder; |
760 } | 771 } |
761 | 772 |
762 private void compareMarks(Mark... expectedMarks) { | 773 private void compareMarks(Mark... expectedMarks) { |
763 HashSet<Mark> recordedMarks = recorder.copyMarks(); | 774 HashSet<Mark> recordedMarks = recorder.copyMarks(); |
764 for (Mark m : expectedMarks) { | 775 for (Mark m : expectedMarks) { |
765 assertNotNull("Missing mark: " + m.name(), recordedMarks.remove(m)); | 776 assertNotNull("Missing mark: " + m.name(), recordedMarks.remove(m)); |
766 } | 777 } |
767 for (Mark m : recordedMarks) { | 778 for (Mark m : recordedMarks) { |
768 fail("Unexpected mark: " + m.name()); | 779 fail("Unexpected mark: " + m.name()); |
769 } | 780 } |
770 } | 781 } |
771 } | 782 } |
OLD | NEW |