| 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 // Test constant folding. | 4 // Test constant folding. |
| 5 | 5 |
| 6 library compiler_helper; | 6 library compiler_helper; |
| 7 | 7 |
| 8 import 'dart:async'; |
| 8 import "package:expect/expect.dart"; | 9 import "package:expect/expect.dart"; |
| 9 | 10 |
| 10 import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t' | 11 import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t' |
| 11 as lego; | 12 as lego; |
| 12 export '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t'; | 13 export '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t'; |
| 13 | 14 |
| 14 import '../../../sdk/lib/_internal/compiler/implementation/js_backend/js_backend
.dart' | 15 import '../../../sdk/lib/_internal/compiler/implementation/js_backend/js_backend
.dart' |
| 15 as js; | 16 as js; |
| 16 | 17 |
| 17 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' | 18 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 bool analyzeOnly: false, | 84 bool analyzeOnly: false, |
| 84 String coreSource: DEFAULT_CORELIB}) { | 85 String coreSource: DEFAULT_CORELIB}) { |
| 85 MockCompiler compiler = new MockCompiler( | 86 MockCompiler compiler = new MockCompiler( |
| 86 analyzeAll: analyzeAll, | 87 analyzeAll: analyzeAll, |
| 87 analyzeOnly: analyzeOnly, | 88 analyzeOnly: analyzeOnly, |
| 88 coreSource: coreSource); | 89 coreSource: coreSource); |
| 89 compiler.sourceFiles[uri.toString()] = new SourceFile(uri.toString(), code); | 90 compiler.sourceFiles[uri.toString()] = new SourceFile(uri.toString(), code); |
| 90 return compiler; | 91 return compiler; |
| 91 } | 92 } |
| 92 | 93 |
| 93 String compileAll(String code, {String coreSource: DEFAULT_CORELIB}) { | 94 Future<String> compileAll(String code, {String coreSource: DEFAULT_CORELIB}) { |
| 94 Uri uri = new Uri(scheme: 'source'); | 95 Uri uri = new Uri(scheme: 'source'); |
| 95 MockCompiler compiler = compilerFor(code, uri, coreSource: coreSource); | 96 MockCompiler compiler = compilerFor(code, uri, coreSource: coreSource); |
| 96 compiler.runCompiler(uri); | 97 return compiler.runCompiler(uri).then((_) { |
| 97 Expect.isFalse(compiler.compilationFailed, | 98 Expect.isFalse(compiler.compilationFailed, |
| 98 'Unexpected compilation error'); | 99 'Unexpected compilation error'); |
| 99 return compiler.assembledCode; | 100 return compiler.assembledCode; |
| 101 }); |
| 100 } | 102 } |
| 101 | 103 |
| 102 dynamic compileAndCheck(String code, | 104 Future compileAndCheck(String code, |
| 103 String name, | 105 String name, |
| 104 check(MockCompiler compiler, lego.Element element)) { | 106 check(MockCompiler compiler, lego.Element element)) { |
| 105 Uri uri = new Uri(scheme: 'source'); | 107 Uri uri = new Uri(scheme: 'source'); |
| 106 MockCompiler compiler = compilerFor(code, uri); | 108 MockCompiler compiler = compilerFor(code, uri); |
| 107 compiler.runCompiler(uri); | 109 return compiler.runCompiler(uri).then((_) { |
| 108 lego.Element element = findElement(compiler, name); | 110 lego.Element element = findElement(compiler, name); |
| 109 return check(compiler, element); | 111 return check(compiler, element); |
| 112 }); |
| 110 } | 113 } |
| 111 | 114 |
| 112 compileSources(Map<String, String> sources, | 115 Future compileSources(Map<String, String> sources, |
| 113 check(MockCompiler compiler)) { | 116 check(MockCompiler compiler)) { |
| 114 Uri base = new Uri(scheme: 'source'); | 117 Uri base = new Uri(scheme: 'source'); |
| 115 Uri mainUri = base.resolve('main.dart'); | 118 Uri mainUri = base.resolve('main.dart'); |
| 116 String mainCode = sources['main.dart']; | 119 String mainCode = sources['main.dart']; |
| 117 Expect.isNotNull(mainCode, 'No source code found for "main.dart"'); | 120 Expect.isNotNull(mainCode, 'No source code found for "main.dart"'); |
| 118 MockCompiler compiler = compilerFor(mainCode, mainUri); | 121 MockCompiler compiler = compilerFor(mainCode, mainUri); |
| 119 | |
| 120 sources.forEach((String path, String code) { | 122 sources.forEach((String path, String code) { |
| 121 if (path == 'main.dart') return; | 123 if (path == 'main.dart') return; |
| 122 compiler.registerSource(base.resolve(path), code); | 124 compiler.registerSource(base.resolve(path), code); |
| 123 }); | 125 }); |
| 124 | 126 |
| 125 compiler.runCompiler(mainUri); | 127 return compiler.runCompiler(mainUri).then((_) { |
| 126 return check(compiler); | 128 return check(compiler); |
| 129 }); |
| 127 } | 130 } |
| 128 | 131 |
| 129 lego.Element findElement(compiler, String name) { | 132 lego.Element findElement(compiler, String name) { |
| 130 var element = compiler.mainApp.find(buildSourceString(name)); | 133 var element = compiler.mainApp.find(buildSourceString(name)); |
| 131 Expect.isNotNull(element, 'Could not locate $name.'); | 134 Expect.isNotNull(element, 'Could not locate $name.'); |
| 132 return element; | 135 return element; |
| 133 } | 136 } |
| 134 | 137 |
| 135 types.TypeMask findTypeMask(compiler, String name, | 138 types.TypeMask findTypeMask(compiler, String name, |
| 136 [String how = 'nonNullExact']) { | 139 [String how = 'nonNullExact']) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 final xRe = new RegExp('\\bx\\b'); | 212 final xRe = new RegExp('\\bx\\b'); |
| 210 regexp = regexp.replaceAll(xRe, '(?:$anyIdentifier)'); | 213 regexp = regexp.replaceAll(xRe, '(?:$anyIdentifier)'); |
| 211 final spaceRe = new RegExp('\\s+'); | 214 final spaceRe = new RegExp('\\s+'); |
| 212 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); | 215 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); |
| 213 if (shouldMatch) { | 216 if (shouldMatch) { |
| 214 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); | 217 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); |
| 215 } else { | 218 } else { |
| 216 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); | 219 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); |
| 217 } | 220 } |
| 218 } | 221 } |
| OLD | NEW |