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

Unified Diff: tests/compiler/dart2js/unparser2_test.dart

Issue 10834374: Add a field to ClassNode that holds a NodeList of its members. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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: tests/compiler/dart2js/unparser2_test.dart
===================================================================
--- tests/compiler/dart2js/unparser2_test.dart (revision 0)
+++ tests/compiler/dart2js/unparser2_test.dart (revision 0)
@@ -0,0 +1,129 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#import("../../../lib/compiler/implementation/scanner/scannerlib.dart");
+#import("../../../lib/compiler/implementation/elements/elements.dart"); // only need CompilationUnitElement
ahe 2012/08/21 11:56:17 If you import parser_helper.dart from this directo
messick 2012/08/21 15:35:40 If I import parser_helper I don't have visibility
+#import("../../../lib/compiler/implementation/tree/tree.dart");
+#import("../../../lib/compiler/implementation/leg.dart"); // only need DiagnosticListener & Script
+
+main() {
+ testClassDef();
+ testClass1Field();
+ testClass2Fields();
+ testClass1Field1Method();
+ testClass1Field2Method();
+ testClassDefTypeParam();
+}
+
+testClassDef() {
+ compareCode('''
+ class T{}
+ ''', '''
+ class T {
+ }
+ ''');
+}
+
+testClass1Field() {
+ compareCode('''
+ class T{var x;}
+ ''', '''
+ class T {
+ var x;
+ }
+ ''');
+}
+
+testClass2Fields() {
+ compareCode('''
+ class T{var x; var y;}
+ ''', '''
+ class T {
+ var x;
+ var y;
+ }
+ ''');
+}
+
+testClass1Field1Method() {
+ compareCode('''
+ class T{var x;m(){}}
+ ''', '''
+ class T {
+ var x;
+ m(){}
+ }
+ ''');
+}
+
+testClass1Field2Method() {
+ compareCode('''
+ class T{a(){}b(){}}
+ ''', '''
+ class T {
+ a(){}
+ b(){}
+ }
+ ''');
+}
+
+testClassDefTypeParam() {
+ compareCode('''
+ class T<X>{}
+ ''', '''
+ class T<X> {
+ }
+ ''');
+}
+
+void compareCode(String original, String expected) {
+ String unparsed = doUnparse(cleanUpLiteral(original));
+ Expect.equals(cleanUpLiteral(expected), unparsed);
+}
+
+String cleanUpLiteral(String text) {
+ var lines = text.split('\n');
+ for (var j = 0; j < lines.length; j++) {
+ if (lines[j].length > 6) {
+ lines[j] = lines[j].substring(6, lines[j].length);
+ } else {
+ lines[j] = '';
+ }
+ }
+ return Strings.join(lines, '\n');
+}
+
+String doUnparse(String source) {
+ MessageCollector diagnosticListener = new MessageCollector();
+ Script script = new Script(null,null);
ahe 2012/08/21 11:56:17 Space after comma.
messick 2012/08/21 15:35:40 Done.
+ LibraryElement lib = new LibraryElement(script);
+ CompilationUnitElement element = new CompilationUnitElement(script, lib);
+ StringScanner scanner = new StringScanner(source);
+ Token beginToken = scanner.tokenize();
+ NodeListener listener = new NodeListener(diagnosticListener, element);
+ Parser parser = new Parser(listener);
+ parser.parseUnit(beginToken);
+ Node node = listener.popNode();
ahe 2012/08/21 11:56:17 Consider adding: Expect.isTrue(listener.nodes.isE
messick 2012/08/21 15:35:40 Done.
+ return new Unparser().unparse(node);
+}
+
+class MessageCollector implements DiagnosticListener {
+ List<String> messages;
+ MessageCollector() {
+ messages = [];
+ }
+ void cancel([String reason, node, token, instruction, element]) {
+ messages.add(reason);
+ throw new Exception(reason);
ahe 2012/08/21 11:56:17 Why are you creating a new Exception?
messick 2012/08/21 15:35:40 Java hold-over? Changed.
+ }
+ void log(message) {
+ messages.add(message);
+ }
+ void internalErrorOnElement(Element element, String message) {
ahe 2012/08/21 11:56:17 You probably want to say: throw message; Or Exp
messick 2012/08/21 15:35:40 Done.
+ }
+ void internalError(String message,
+ [Node node, Token token, Dynamic instruction,
+ Element element]) {
ahe 2012/08/21 11:56:17 Ditto.
messick 2012/08/21 15:35:40 Done.
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698