| 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:uri"); | 8 #import("dart:uri"); |
| 9 #import("../../../lib/compiler/implementation/leg.dart", prefix: "leg"); | 9 #import("../../../lib/compiler/implementation/leg.dart", prefix: "leg"); |
| 10 #import("../../../lib/compiler/implementation/js_backend/js_backend.dart", prefi
x: "js"); | 10 #import("../../../lib/compiler/implementation/js_backend/js_backend.dart", prefi
x: "js"); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 String compileAll(String code) { | 35 String compileAll(String code) { |
| 36 Uri uri = new Uri.fromComponents(scheme: 'source'); | 36 Uri uri = new Uri.fromComponents(scheme: 'source'); |
| 37 MockCompiler compiler = compilerFor(code, uri); | 37 MockCompiler compiler = compilerFor(code, uri); |
| 38 compiler.runCompiler(uri); | 38 compiler.runCompiler(uri); |
| 39 Expect.isFalse(compiler.compilationFailed, | 39 Expect.isFalse(compiler.compilationFailed, |
| 40 'Unexpected compilation error'); | 40 'Unexpected compilation error'); |
| 41 return compiler.assembledCode; | 41 return compiler.assembledCode; |
| 42 } | 42 } |
| 43 | 43 |
| 44 lego.Element findElement(var compiler, String name) { | 44 Dynamic compileAndCheck(String code, |
| 45 String name, |
| 46 check(MockCompiler compiler, lego.Element element)) { |
| 47 Uri uri = new Uri.fromComponents(scheme: 'source'); |
| 48 MockCompiler compiler = compilerFor(code, uri); |
| 49 compiler.runCompiler(uri); |
| 50 lego.Element element = findElement(compiler, name); |
| 51 return check(compiler, element); |
| 52 } |
| 53 |
| 54 lego.Element findElement(compiler, String name) { |
| 45 var element = compiler.mainApp.find(buildSourceString(name)); | 55 var element = compiler.mainApp.find(buildSourceString(name)); |
| 46 Expect.isNotNull(element, 'Could not locate $name.'); | 56 Expect.isNotNull(element, 'Could not locate $name.'); |
| 47 return element; | 57 return element; |
| 48 } | 58 } |
| 49 | 59 |
| 50 String anyIdentifier = "[a-zA-Z][a-zA-Z0-9]*"; | 60 String anyIdentifier = "[a-zA-Z][a-zA-Z0-9]*"; |
| 51 | 61 |
| 52 String getIntTypeCheck(String variable) { | 62 String getIntTypeCheck(String variable) { |
| 53 return "\\($variable !== \\($variable \\| 0\\)\\)"; | 63 return "\\($variable !== \\($variable \\| 0\\)\\)"; |
| 54 } | 64 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 69 String generated = compile(code, entry); | 79 String generated = compile(code, entry); |
| 70 Expect.isTrue(regexp.hasMatch(generated), | 80 Expect.isTrue(regexp.hasMatch(generated), |
| 71 '"$generated" does not match /$regexp/'); | 81 '"$generated" does not match /$regexp/'); |
| 72 } | 82 } |
| 73 | 83 |
| 74 void compileAndDoNotMatch(String code, String entry, RegExp regexp) { | 84 void compileAndDoNotMatch(String code, String entry, RegExp regexp) { |
| 75 String generated = compile(code, entry); | 85 String generated = compile(code, entry); |
| 76 Expect.isFalse(regexp.hasMatch(generated), | 86 Expect.isFalse(regexp.hasMatch(generated), |
| 77 '"$generated" has a match in /$regexp/'); | 87 '"$generated" has a match in /$regexp/'); |
| 78 } | 88 } |
| OLD | NEW |