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

Unified Diff: client/dom/scripts/idlparser_test.dart

Issue 8404031: IDL parser (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 9 years, 2 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
« no previous file with comments | « client/dom/scripts/idlparser.dart ('k') | client/dom/scripts/idlrenderer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/dom/scripts/idlparser_test.dart
diff --git a/client/dom/scripts/idlparser_test.dart b/client/dom/scripts/idlparser_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a8544c3c5d1038e77554ac73313b3b13ec640cbc
--- /dev/null
+++ b/client/dom/scripts/idlparser_test.dart
@@ -0,0 +1,115 @@
+// Copyright (c) 2011, 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('../../../utils/peg/pegparser.dart');
+#source('idlparser.dart');
+#source('idlrenderer.dart');
+
+main() {
+ IDLParser parser = new IDLParser(FREMONTCUT_SYNTAX);
+ Grammar g = parser.grammar;
+
+ var Type = g['Type'];
+
+ show(g, Type, 'int');
+ show(g, Type, 'int ?');
+ show(g, Type, 'sequence<int?> ?');
+ show(g, Type, 'unsigned long long?');
+ show(g, Type, 'unsignedlonglong?');
+
+
+ var MaybeAnnotations = g['MaybeAnnotations'];
+
+ show(g, MaybeAnnotations, '');
+ show(g, MaybeAnnotations, '@Foo');
+ show(g, MaybeAnnotations, '@Foo @Bar');
+ show(g, MaybeAnnotations, '@Foo(A,B=1) @Bar');
+
+ var MaybeExtAttrs = g['MaybeExtAttrs'];
+ print(MaybeExtAttrs);
+
+ show(g, MaybeExtAttrs, '');
+ show(g, MaybeExtAttrs, '[A]');
+
+ var Module = g['Module'];
+
+ show(g, Module, 'module Harry { const int bob = 30;};');
+ show(g, Module, """
+module Harry { [X,Y,Z=99] const int bob = 30; typedef x y;
+
+ interface Thing : SuperA, @Friendly SuperB {
+
+ [Nice] const unsigned long long kFoo = 12345;
+ [A,B,C,D,E] attribute int attr1;
+ [F=f(int a),K=99,DartName=Bert] int smudge(int a, int b, double x);
+
+ [X,Y,Z] int xyz([U,V] optional in optional int z);
+ [P,Q,R] int pqr();
+ int op1();
+ @Smurf @Beans(B=1,C,A=2) int op2();
+
+ snippet { yadda
+ yadda
+ };
+ };
+
+//[A] const unsigned long long dweeb = 0xff;
+
+};
+""");
+}
+
+
+
+show(grammar, rule, input) {
+ print('show: "$input"');
+ var ast;
+ try {
+ ast = grammar.parse(rule, input);
+ } catch (var exception) {
+ if (exception is ParseError)
+ ast = exception;
+ else
+ throw;
+ }
+ print('${printList(ast)}');
+ print(render(ast));
+}
+
+void check(grammar, rule, input, expected) {
+ // If [expected] is String then the result is coerced to string.
+ // If [expected] is !String, the result is compared directly.
+ print('check: "$input"');
+ var ast;
+ try {
+ ast = grammar.parse(rule, input);
+ } catch (var exception) {
+ ast = exception;
+ }
+
+ var formatted = ast;
+ if (expected is String)
+ formatted = printList(ast);
+
+ Expect.equals(expected, formatted, "parse: $input");
+}
+
+// Prints the list in [1,2,3] notation, including nested lists.
+void printList(item) {
+ if (item is List) {
+ StringBuffer sb = new StringBuffer();
+ sb.add('[');
+ var sep = '';
+ for (var x in item) {
+ sb.add(sep);
+ sb.add(printList(x));
+ sep = ',';
+ }
+ sb.add(']');
+ return sb.toString();
+ }
+ if (item == null)
+ return 'null';
+ return item.toString();
+}
« no previous file with comments | « client/dom/scripts/idlparser.dart ('k') | client/dom/scripts/idlrenderer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698