| 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 'dart:async'; |
| 9 import "package:expect/expect.dart"; | 9 import "package:expect/expect.dart"; |
| 10 | 10 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 js.JavaScriptBackend backend = compiler.backend; | 82 js.JavaScriptBackend backend = compiler.backend; |
| 83 return backend.assembleCode(element); | 83 return backend.assembleCode(element); |
| 84 } | 84 } |
| 85 | 85 |
| 86 // TODO(herhut): Disallow warnings and errors during compilation by default. | 86 // TODO(herhut): Disallow warnings and errors during compilation by default. |
| 87 MockCompiler compilerFor(String code, Uri uri, | 87 MockCompiler compilerFor(String code, Uri uri, |
| 88 {bool analyzeAll: false, | 88 {bool analyzeAll: false, |
| 89 bool analyzeOnly: false, | 89 bool analyzeOnly: false, |
| 90 String coreSource: DEFAULT_CORELIB, | 90 String coreSource: DEFAULT_CORELIB, |
| 91 bool disableInlining: true, | 91 bool disableInlining: true, |
| 92 bool minify: false, | |
| 93 int expectedErrors, | 92 int expectedErrors, |
| 94 int expectedWarnings}) { | 93 int expectedWarnings}) { |
| 95 MockCompiler compiler = new MockCompiler( | 94 MockCompiler compiler = new MockCompiler( |
| 96 analyzeAll: analyzeAll, | 95 analyzeAll: analyzeAll, |
| 97 analyzeOnly: analyzeOnly, | 96 analyzeOnly: analyzeOnly, |
| 98 coreSource: coreSource, | 97 coreSource: coreSource, |
| 99 disableInlining: disableInlining, | 98 disableInlining: disableInlining, |
| 100 enableMinification: minify, | |
| 101 expectedErrors: expectedErrors, | 99 expectedErrors: expectedErrors, |
| 102 expectedWarnings: expectedWarnings); | 100 expectedWarnings: expectedWarnings); |
| 103 compiler.sourceFiles[uri.toString()] = | 101 compiler.sourceFiles[uri.toString()] = |
| 104 new StringSourceFile(uri.toString(), code); | 102 new StringSourceFile(uri.toString(), code); |
| 105 return compiler; | 103 return compiler; |
| 106 } | 104 } |
| 107 | 105 |
| 108 Future<String> compileAll(String code, | 106 Future<String> compileAll(String code, |
| 109 {String coreSource: DEFAULT_CORELIB, | 107 {String coreSource: DEFAULT_CORELIB, |
| 110 bool disableInlining: true, | 108 bool disableInlining: true, |
| 111 bool minify: false, | |
| 112 int expectedErrors, | 109 int expectedErrors, |
| 113 int expectedWarnings}) { | 110 int expectedWarnings}) { |
| 114 Uri uri = new Uri(scheme: 'source'); | 111 Uri uri = new Uri(scheme: 'source'); |
| 115 MockCompiler compiler = compilerFor( | 112 MockCompiler compiler = compilerFor( |
| 116 code, uri, coreSource: coreSource, disableInlining: disableInlining, | 113 code, uri, coreSource: coreSource, disableInlining: disableInlining, |
| 117 minify: minify, expectedErrors: expectedErrors, | 114 expectedErrors: expectedErrors, expectedWarnings: expectedWarnings); |
| 118 expectedWarnings: expectedWarnings); | |
| 119 return compiler.runCompiler(uri).then((_) { | 115 return compiler.runCompiler(uri).then((_) { |
| 120 Expect.isFalse(compiler.compilationFailed, | 116 Expect.isFalse(compiler.compilationFailed, |
| 121 'Unexpected compilation error'); | 117 'Unexpected compilation error'); |
| 122 return compiler.assembledCode; | 118 return compiler.assembledCode; |
| 123 }); | 119 }); |
| 124 } | 120 } |
| 125 | 121 |
| 126 Future compileAndCheck(String code, | 122 Future compileAndCheck(String code, |
| 127 String name, | 123 String name, |
| 128 check(MockCompiler compiler, lego.Element element), | 124 check(MockCompiler compiler, lego.Element element), |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 final xRe = new RegExp('\\bx\\b'); | 228 final xRe = new RegExp('\\bx\\b'); |
| 233 regexp = regexp.replaceAll(xRe, '(?:$anyIdentifier)'); | 229 regexp = regexp.replaceAll(xRe, '(?:$anyIdentifier)'); |
| 234 final spaceRe = new RegExp('\\s+'); | 230 final spaceRe = new RegExp('\\s+'); |
| 235 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); | 231 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); |
| 236 if (shouldMatch) { | 232 if (shouldMatch) { |
| 237 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); | 233 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); |
| 238 } else { | 234 } else { |
| 239 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); | 235 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); |
| 240 } | 236 } |
| 241 } | 237 } |
| OLD | NEW |