| 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 "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 import 'dart:uri'; | |
| 10 export 'dart:uri' show Uri; | |
| 11 | 9 |
| 12 import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t' | 10 import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t' |
| 13 as lego; | 11 as lego; |
| 14 export '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t'; | 12 export '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t'; |
| 15 | 13 |
| 16 import '../../../sdk/lib/_internal/compiler/implementation/js_backend/js_backend
.dart' | 14 import '../../../sdk/lib/_internal/compiler/implementation/js_backend/js_backend
.dart' |
| 17 as js; | 15 as js; |
| 18 | 16 |
| 19 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' | 17 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' |
| 20 as leg; | 18 as leg; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 String coreSource: DEFAULT_CORELIB}) { | 81 String coreSource: DEFAULT_CORELIB}) { |
| 84 MockCompiler compiler = new MockCompiler( | 82 MockCompiler compiler = new MockCompiler( |
| 85 analyzeAll: analyzeAll, | 83 analyzeAll: analyzeAll, |
| 86 analyzeOnly: analyzeOnly, | 84 analyzeOnly: analyzeOnly, |
| 87 coreSource: coreSource); | 85 coreSource: coreSource); |
| 88 compiler.sourceFiles[uri.toString()] = new SourceFile(uri.toString(), code); | 86 compiler.sourceFiles[uri.toString()] = new SourceFile(uri.toString(), code); |
| 89 return compiler; | 87 return compiler; |
| 90 } | 88 } |
| 91 | 89 |
| 92 String compileAll(String code, {String coreSource: DEFAULT_CORELIB}) { | 90 String compileAll(String code, {String coreSource: DEFAULT_CORELIB}) { |
| 93 Uri uri = new Uri.fromComponents(scheme: 'source'); | 91 Uri uri = new Uri(scheme: 'source'); |
| 94 MockCompiler compiler = compilerFor(code, uri, coreSource: coreSource); | 92 MockCompiler compiler = compilerFor(code, uri, coreSource: coreSource); |
| 95 compiler.runCompiler(uri); | 93 compiler.runCompiler(uri); |
| 96 Expect.isFalse(compiler.compilationFailed, | 94 Expect.isFalse(compiler.compilationFailed, |
| 97 'Unexpected compilation error'); | 95 'Unexpected compilation error'); |
| 98 return compiler.assembledCode; | 96 return compiler.assembledCode; |
| 99 } | 97 } |
| 100 | 98 |
| 101 dynamic compileAndCheck(String code, | 99 dynamic compileAndCheck(String code, |
| 102 String name, | 100 String name, |
| 103 check(MockCompiler compiler, lego.Element element)) { | 101 check(MockCompiler compiler, lego.Element element)) { |
| 104 Uri uri = new Uri.fromComponents(scheme: 'source'); | 102 Uri uri = new Uri(scheme: 'source'); |
| 105 MockCompiler compiler = compilerFor(code, uri); | 103 MockCompiler compiler = compilerFor(code, uri); |
| 106 compiler.runCompiler(uri); | 104 compiler.runCompiler(uri); |
| 107 lego.Element element = findElement(compiler, name); | 105 lego.Element element = findElement(compiler, name); |
| 108 return check(compiler, element); | 106 return check(compiler, element); |
| 109 } | 107 } |
| 110 | 108 |
| 111 compileSources(Map<String, String> sources, | 109 compileSources(Map<String, String> sources, |
| 112 check(MockCompiler compiler)) { | 110 check(MockCompiler compiler)) { |
| 113 Uri base = new Uri.fromComponents(scheme: 'source'); | 111 Uri base = new Uri(scheme: 'source'); |
| 114 Uri mainUri = base.resolve('main.dart'); | 112 Uri mainUri = base.resolve('main.dart'); |
| 115 String mainCode = sources['main.dart']; | 113 String mainCode = sources['main.dart']; |
| 116 Expect.isNotNull(mainCode, 'No source code found for "main.dart"'); | 114 Expect.isNotNull(mainCode, 'No source code found for "main.dart"'); |
| 117 MockCompiler compiler = compilerFor(mainCode, mainUri); | 115 MockCompiler compiler = compilerFor(mainCode, mainUri); |
| 118 | 116 |
| 119 sources.forEach((String path, String code) { | 117 sources.forEach((String path, String code) { |
| 120 if (path == 'main.dart') return; | 118 if (path == 'main.dart') return; |
| 121 compiler.registerSource(base.resolve(path), code); | 119 compiler.registerSource(base.resolve(path), code); |
| 122 }); | 120 }); |
| 123 | 121 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 final xRe = new RegExp('\\bx\\b'); | 206 final xRe = new RegExp('\\bx\\b'); |
| 209 regexp = regexp.replaceAll(xRe, '(?:$anyIdentifier)'); | 207 regexp = regexp.replaceAll(xRe, '(?:$anyIdentifier)'); |
| 210 final spaceRe = new RegExp('\\s+'); | 208 final spaceRe = new RegExp('\\s+'); |
| 211 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); | 209 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); |
| 212 if (shouldMatch) { | 210 if (shouldMatch) { |
| 213 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); | 211 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); |
| 214 } else { | 212 } else { |
| 215 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); | 213 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); |
| 216 } | 214 } |
| 217 } | 215 } |
| OLD | NEW |