Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Unified Diff: pkg/analyzer/test/generated/parser_fasta_listener.dart

Issue 2985703002: new handleInvalidTopLevelDeclaration event in fasta parser (Closed)
Patch Set: cleanup forwarding listener - enclosingEvent Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/test/generated/parser_fasta_listener.dart
diff --git a/pkg/analyzer/test/generated/parser_fasta_listener.dart b/pkg/analyzer/test/generated/parser_fasta_listener.dart
index 412de6e9be5baef55918b9ddbb496ff3d2372939..7fae3318257a3cedd23a7cca7bd7766dff7c2f14 100644
--- a/pkg/analyzer/test/generated/parser_fasta_listener.dart
+++ b/pkg/analyzer/test/generated/parser_fasta_listener.dart
@@ -15,17 +15,32 @@ import 'package:test/test.dart';
* Proxy implementation of the fasta parser listener that
* asserts begin/end pairs of events and forwards all events
* to the specified listener.
+ *
+ * When `parseUnit` is called, then all events are generated as expected.
+ * When "lower level" parse methods are called, then some "higher level"
+ * begin/end event pairs will not be generated. In this case,
+ * construct a new listener and set the [enclosingEvent] to be the begin/end
+ * event pair that would have been generated. For example, when
+ * `parseTopLevelDeclaration` is called, then the [beginCompilationUnit]
+ * and [endCompilationUnit] event pair is not generated. In this situation,
+ * set [enclosingEvent] to "CompilationUnit" so that the listener knows that
+ * this event pair will not be generated but is expected.
*/
class ForwardingTestListener implements fasta.Listener {
final fasta.Listener listener;
final _stack = <String>[];
+ String enclosingEvent;
void _begin(String event) {
+ expect(event, isNotNull);
+ expect(event, isNot(enclosingEvent));
_stack.add(event);
}
void _in(String event) {
- if (_stack.isEmpty || _stack.last != event) {
+ if (enclosingEvent == event) {
+ expect(_stack, isEmpty);
+ } else if (_stack.isEmpty || _stack.last != event) {
fail('Expected $event, but found $_stack');
}
}
@@ -994,6 +1009,7 @@ class ForwardingTestListener implements fasta.Listener {
void endTopLevelDeclaration(Token token) {
// There is no corresponding beginTopLevelDeclaration
//_expectBegin('TopLevelDeclaration');
+ _in('CompilationUnit');
listener.endTopLevelDeclaration(token);
}
@@ -1200,6 +1216,12 @@ class ForwardingTestListener implements fasta.Listener {
}
@override
+ void handleInvalidTopLevelDeclaration(Token beginToken, Token endToken) {
+ _in('CompilationUnit');
+ listener.handleInvalidTopLevelDeclaration(beginToken, endToken);
+ }
+
+ @override
void handleIsOperator(Token operator, Token not, Token endToken) {
listener.handleIsOperator(operator, not, endToken);
// TODO(danrubel): implement handleIsOperator

Powered by Google App Engine
This is Rietveld 408576698