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" as lego; | 10 import "../../../lib/compiler/implementation/elements/elements.dart" as lego; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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: entry); | 87 String generated = compile(code, entry: 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: entry); | 93 String generated = compile(code, entry: entry); |
(...skipping 20 matching lines...) Expand all Loading... |
114 regexp = regexp.replaceAll(xRe, '(?:$anyIdentifier)'); | 114 regexp = regexp.replaceAll(xRe, '(?:$anyIdentifier)'); |
115 final spaceRe = new RegExp('\\s+'); | 115 final spaceRe = new RegExp('\\s+'); |
116 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); | 116 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); |
117 if (shouldMatch) { | 117 if (shouldMatch) { |
118 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); | 118 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); |
119 } else { | 119 } else { |
120 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); | 120 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
OLD | NEW |