| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #import('dart:uri'); |
| 5 #import('parser_helper.dart'); | 6 #import('parser_helper.dart'); |
| 7 #import("../../../lib/compiler/compiler.dart"); |
| 6 #import("../../../lib/compiler/implementation/tree/tree.dart"); | 8 #import("../../../lib/compiler/implementation/tree/tree.dart"); |
| 7 | 9 |
| 8 testUnparse(String statement) { | 10 testUnparse(String statement) { |
| 9 Node node = parseStatement(statement); | 11 Node node = parseStatement(statement); |
| 10 Expect.equals(statement, node.unparse()); | 12 Expect.equals(statement, node.unparse()); |
| 11 } | 13 } |
| 12 | 14 |
| 13 testUnparseMember(String member) { | 15 testUnparseMember(String member) { |
| 14 Node node = parseMember(member); | 16 Node node = parseMember(member); |
| 15 Expect.equals(member, node.unparse()); | 17 Expect.equals(member, node.unparse()); |
| 16 } | 18 } |
| 17 | 19 |
| 20 final coreLib = @''' |
| 21 #library('corelib'); |
| 22 interface Object {} |
| 23 interface bool {} |
| 24 interface num {} |
| 25 interface int extends num {} |
| 26 interface double extends num {} |
| 27 interface String {} |
| 28 interface Function {} |
| 29 interface List {} |
| 30 interface Closure {} |
| 31 interface Dynamic {} |
| 32 interface Null {} |
| 33 '''; |
| 34 |
| 35 testDart2Dart(String src, void continuation(String s)) { |
| 36 fileUri(path) => new Uri(scheme: 'file', path: path); |
| 37 |
| 38 final scriptUri = fileUri('script.dart'); |
| 39 |
| 40 provider(uri) { |
| 41 if (uri == scriptUri) return new Future.immediate(src); |
| 42 if (uri.path.endsWith('/core.dart')) return new Future.immediate(coreLib); |
| 43 return new Future.immediate(''); |
| 44 } |
| 45 |
| 46 handler(uri, begin, end, message, kind) { |
| 47 if (kind === Diagnostic.ERROR || kind === Diagnostic.CRASH) { |
| 48 Expect.fail('$uri: $begin-$end: $message [$kind]'); |
| 49 } |
| 50 } |
| 51 |
| 52 compile( |
| 53 scriptUri, |
| 54 fileUri('libraryRoot'), |
| 55 fileUri('packageRoot'), |
| 56 provider, |
| 57 handler, |
| 58 const ['--output-type=dart', '--unparse-validation']).then(continuation); |
| 59 } |
| 60 |
| 18 testGenericTypes() { | 61 testGenericTypes() { |
| 19 testUnparse('var x=new List<List<int>>();'); | 62 testUnparse('var x=new List<List<int>>();'); |
| 20 testUnparse('var x=new List<List<List<int>>>();'); | 63 testUnparse('var x=new List<List<List<int>>>();'); |
| 21 testUnparse('var x=new List<List<List<List<int>>>>();'); | 64 testUnparse('var x=new List<List<List<List<int>>>>();'); |
| 22 testUnparse('var x=new List<List<List<List<List<int>>>>>();'); | 65 testUnparse('var x=new List<List<List<List<List<int>>>>>();'); |
| 23 } | 66 } |
| 24 | 67 |
| 25 testForLoop() { | 68 testForLoop() { |
| 26 testUnparse('for(;i<100;i++){}'); | 69 testUnparse('for(;i<100;i++){}'); |
| 27 testUnparse('for(i=0;i<100;i++){}'); | 70 testUnparse('for(i=0;i<100;i++){}'); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 38 testIndexedOperatorDecl() { | 81 testIndexedOperatorDecl() { |
| 39 testUnparseMember('operator[](int i)=> null;'); | 82 testUnparseMember('operator[](int i)=> null;'); |
| 40 } | 83 } |
| 41 | 84 |
| 42 testNativeMethods() { | 85 testNativeMethods() { |
| 43 testUnparseMember('foo()native;'); | 86 testUnparseMember('foo()native;'); |
| 44 testUnparseMember('foo()native "bar";'); | 87 testUnparseMember('foo()native "bar";'); |
| 45 testUnparseMember('foo()native "this.x = 41";'); | 88 testUnparseMember('foo()native "this.x = 41";'); |
| 46 } | 89 } |
| 47 | 90 |
| 91 testSimpleFileUnparse() { |
| 92 testDart2Dart('main() {}', (String s) { |
| 93 }); |
| 94 } |
| 95 |
| 48 main() { | 96 main() { |
| 49 testGenericTypes(); | 97 testGenericTypes(); |
| 50 testForLoop(); | 98 testForLoop(); |
| 51 testEmptyList(); | 99 testEmptyList(); |
| 52 testClosure(); | 100 testClosure(); |
| 53 testIndexedOperatorDecl(); | 101 testIndexedOperatorDecl(); |
| 54 testNativeMethods(); | 102 testNativeMethods(); |
| 103 testSimpleFileUnparse(); |
| 55 } | 104 } |
| OLD | NEW |