| 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 | 9 |
| 10 #import("../../../lib/compiler/implementation/elements/elements.dart", prefix: "
lego"); | 10 #import("../../../lib/compiler/implementation/elements/elements.dart", prefix: "
lego"); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 lego.Element findElement(compiler, String name) { | 62 lego.Element findElement(compiler, String name) { |
| 63 var element = compiler.mainApp.find(buildSourceString(name)); | 63 var element = compiler.mainApp.find(buildSourceString(name)); |
| 64 Expect.isNotNull(element, 'Could not locate $name.'); | 64 Expect.isNotNull(element, 'Could not locate $name.'); |
| 65 return element; | 65 return element; |
| 66 } | 66 } |
| 67 | 67 |
| 68 String anyIdentifier = "[a-zA-Z][a-zA-Z0-9]*"; | 68 String anyIdentifier = "[a-zA-Z][a-zA-Z0-9]*"; |
| 69 | 69 |
| 70 String getIntTypeCheck(String variable) { | 70 String getIntTypeCheck(String variable) { |
| 71 return "\\($variable !== \\($variable \\| 0\\)\\)"; | 71 return "\\($variable ?!== ?\\($variable ?\\| ?0\\)\\)"; |
| 72 } | 72 } |
| 73 | 73 |
| 74 String getNumberTypeCheck(String variable) { | 74 String getNumberTypeCheck(String variable) { |
| 75 return "\\(typeof $variable !== 'number'\\)"; | 75 return "\\(typeof $variable ?!== ?'number'\\)"; |
| 76 } | 76 } |
| 77 | 77 |
| 78 bool checkNumberOfMatches(Iterator it, int nb) { | 78 bool checkNumberOfMatches(Iterator it, int nb) { |
| 79 for (int i = 0; i < nb; i++) { | 79 for (int i = 0; i < nb; i++) { |
| 80 Expect.isTrue(it.hasNext(), "Found less than $nb matches"); | 80 Expect.isTrue(it.hasNext(), "Found less than $nb matches"); |
| 81 it.next(); | 81 it.next(); |
| 82 } | 82 } |
| 83 Expect.isFalse(it.hasNext(), "Found more than $nb matches"); | 83 Expect.isFalse(it.hasNext(), "Found more than $nb matches"); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void compileAndMatch(String code, String entry, RegExp regexp) { | 86 void compileAndMatch(String code, String entry, RegExp regexp) { |
| 87 String generated = compile(code, entry); | 87 String generated = compile(code, entry); |
| 88 Expect.isTrue(regexp.hasMatch(generated), | 88 Expect.isTrue(regexp.hasMatch(generated), |
| 89 '"$generated" does not match /$regexp/'); | 89 '"$generated" does not match /$regexp/'); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void compileAndDoNotMatch(String code, String entry, RegExp regexp) { | 92 void compileAndDoNotMatch(String code, String entry, RegExp regexp) { |
| 93 String generated = compile(code, entry); | 93 String generated = compile(code, entry); |
| 94 Expect.isFalse(regexp.hasMatch(generated), | 94 Expect.isFalse(regexp.hasMatch(generated), |
| 95 '"$generated" has a match in /$regexp/'); | 95 '"$generated" has a match in /$regexp/'); |
| 96 } | 96 } |
| 97 | 97 |
| 98 int length(Link link) => link.isEmpty() ? 0 : length(link.tail) + 1; | 98 int length(Link link) => link.isEmpty() ? 0 : length(link.tail) + 1; |
| 99 |
| 100 // Does a compile and then a match where every 'x' is replaced by something |
| 101 // that matches any variable, and every space is optional. |
| 102 void compileAndMatchFuzzy(String code, String entry, String regexp) { |
| 103 compileAndMatchFuzzyHelper(code, entry, regexp, true); |
| 104 } |
| 105 |
| 106 void compileAndDoNotMatchFuzzy(String code, String entry, String regexp) { |
| 107 compileAndMatchFuzzyHelper(code, entry, regexp, false); |
| 108 } |
| 109 |
| 110 void compileAndMatchFuzzyHelper( |
| 111 String code, String entry, String regexp, bool shouldMatch) { |
| 112 String generated = compile(code, entry); |
| 113 final xRe = new RegExp('\\bx\\b'); |
| 114 regexp = regexp.replaceAll(xRe, '(?:$anyIdentifier)'); |
| 115 final spaceRe = new RegExp('\\s+'); |
| 116 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); |
| 117 if (shouldMatch) { |
| 118 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); |
| 119 } else { |
| 120 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); |
| 121 } |
| 122 } |
| 123 |
| OLD | NEW |