| 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 "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t" | 10 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 String getIntTypeCheck(String variable) { | 76 String getIntTypeCheck(String variable) { |
| 77 return "\\($variable ?!== ?\\($variable ?\\| ?0\\)\\)"; | 77 return "\\($variable ?!== ?\\($variable ?\\| ?0\\)\\)"; |
| 78 } | 78 } |
| 79 | 79 |
| 80 String getNumberTypeCheck(String variable) { | 80 String getNumberTypeCheck(String variable) { |
| 81 return """\\(typeof $variable ?!== ?"number"\\)"""; | 81 return """\\(typeof $variable ?!== ?"number"\\)"""; |
| 82 } | 82 } |
| 83 | 83 |
| 84 bool checkNumberOfMatches(Iterator it, int nb) { | 84 bool checkNumberOfMatches(Iterator it, int nb) { |
| 85 bool hasNext = it.moveNext(); |
| 85 for (int i = 0; i < nb; i++) { | 86 for (int i = 0; i < nb; i++) { |
| 86 Expect.isTrue(it.hasNext, "Found less than $nb matches"); | 87 Expect.isTrue(hasNext, "Found less than $nb matches"); |
| 87 it.next(); | 88 hasNext = it.moveNext(); |
| 88 } | 89 } |
| 89 Expect.isFalse(it.hasNext, "Found more than $nb matches"); | 90 Expect.isFalse(hasNext, "Found more than $nb matches"); |
| 90 } | 91 } |
| 91 | 92 |
| 92 void compileAndMatch(String code, String entry, RegExp regexp) { | 93 void compileAndMatch(String code, String entry, RegExp regexp) { |
| 93 String generated = compile(code, entry: entry); | 94 String generated = compile(code, entry: entry); |
| 94 Expect.isTrue(regexp.hasMatch(generated), | 95 Expect.isTrue(regexp.hasMatch(generated), |
| 95 '"$generated" does not match /$regexp/'); | 96 '"$generated" does not match /$regexp/'); |
| 96 } | 97 } |
| 97 | 98 |
| 98 void compileAndDoNotMatch(String code, String entry, RegExp regexp) { | 99 void compileAndDoNotMatch(String code, String entry, RegExp regexp) { |
| 99 String generated = compile(code, entry: entry); | 100 String generated = compile(code, entry: entry); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 119 final xRe = new RegExp('\\bx\\b'); | 120 final xRe = new RegExp('\\bx\\b'); |
| 120 regexp = regexp.replaceAll(xRe, '(?:$anyIdentifier)'); | 121 regexp = regexp.replaceAll(xRe, '(?:$anyIdentifier)'); |
| 121 final spaceRe = new RegExp('\\s+'); | 122 final spaceRe = new RegExp('\\s+'); |
| 122 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); | 123 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); |
| 123 if (shouldMatch) { | 124 if (shouldMatch) { |
| 124 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); | 125 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); |
| 125 } else { | 126 } else { |
| 126 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); | 127 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); |
| 127 } | 128 } |
| 128 } | 129 } |
| OLD | NEW |