Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Side by Side Diff: tests/compiler/dart2js/compiler_helper.dart

Issue 11194025: Second round of cleanups for new optional parameter semantics. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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");
11 #import("../../../lib/compiler/implementation/js_backend/js_backend.dart", prefi x: "js"); 11 #import("../../../lib/compiler/implementation/js_backend/js_backend.dart", prefi x: "js");
12 #import("../../../lib/compiler/implementation/leg.dart", prefix: "leg"); 12 #import("../../../lib/compiler/implementation/leg.dart", prefix: "leg");
13 #import("../../../lib/compiler/implementation/ssa/ssa.dart", prefix: "ssa"); 13 #import("../../../lib/compiler/implementation/ssa/ssa.dart", prefix: "ssa");
14 #import("../../../lib/compiler/implementation/util/util.dart"); 14 #import("../../../lib/compiler/implementation/util/util.dart");
15 #import('../../../lib/compiler/implementation/source_file.dart'); 15 #import('../../../lib/compiler/implementation/source_file.dart');
16 16
17 #import("mock_compiler.dart"); 17 #import("mock_compiler.dart");
18 #import("parser_helper.dart"); 18 #import("parser_helper.dart");
19 19
20 String compile(String code, [String entry = 'main', 20 String compile(String code, {String entry: 'main',
21 bool enableTypeAssertions = false, 21 bool enableTypeAssertions: false,
22 bool minify = false]) { 22 bool minify: false}) {
23 MockCompiler compiler = 23 MockCompiler compiler =
24 new MockCompiler(enableTypeAssertions: enableTypeAssertions, 24 new MockCompiler(enableTypeAssertions: enableTypeAssertions,
25 enableMinification: minify); 25 enableMinification: minify);
26 compiler.parseScript(code); 26 compiler.parseScript(code);
27 lego.Element element = compiler.mainApp.find(buildSourceString(entry)); 27 lego.Element element = compiler.mainApp.find(buildSourceString(entry));
28 if (element === null) return null; 28 if (element === null) return null;
29 compiler.backend.enqueueHelpers(compiler.enqueuer.resolution); 29 compiler.backend.enqueueHelpers(compiler.enqueuer.resolution);
30 compiler.processQueue(compiler.enqueuer.resolution, element); 30 compiler.processQueue(compiler.enqueuer.resolution, element);
31 var context = new js.JavaScriptItemCompilationContext(); 31 var context = new js.JavaScriptItemCompilationContext();
32 leg.WorkItem work = new leg.WorkItem(element, null, context); 32 leg.WorkItem work = new leg.WorkItem(element, null, context);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
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: 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: 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 99
100 // Does a compile and then a match where every 'x' is replaced by something 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. 101 // that matches any variable, and every space is optional.
102 void compileAndMatchFuzzy(String code, String entry, String regexp) { 102 void compileAndMatchFuzzy(String code, String entry, String regexp) {
103 compileAndMatchFuzzyHelper(code, entry, regexp, true); 103 compileAndMatchFuzzyHelper(code, entry, regexp, true);
104 } 104 }
105 105
106 void compileAndDoNotMatchFuzzy(String code, String entry, String regexp) { 106 void compileAndDoNotMatchFuzzy(String code, String entry, String regexp) {
107 compileAndMatchFuzzyHelper(code, entry, regexp, false); 107 compileAndMatchFuzzyHelper(code, entry, regexp, false);
108 } 108 }
109 109
110 void compileAndMatchFuzzyHelper( 110 void compileAndMatchFuzzyHelper(
111 String code, String entry, String regexp, bool shouldMatch) { 111 String code, String entry, String regexp, bool shouldMatch) {
112 String generated = compile(code, entry); 112 String generated = compile(code, entry: entry);
113 final xRe = new RegExp('\\bx\\b'); 113 final xRe = new RegExp('\\bx\\b');
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698