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

Side by Side Diff: test/codegen/expect/expect.js

Issue 1989663002: fix #470, string interpolation now respects Dart toString (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « test/codegen/expect/covariance.js ('k') | test/codegen/expect/expect/expect.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 dart_library.library('expect', null, /* Imports */[ 1 dart_library.library('expect', null, /* Imports */[
2 'dart_sdk' 2 'dart_sdk'
3 ], function(exports, dart_sdk) { 3 ], function(exports, dart_sdk) {
4 'use strict'; 4 'use strict';
5 const core = dart_sdk.core; 5 const core = dart_sdk.core;
6 const dart = dart_sdk.dart; 6 const dart = dart_sdk.dart;
7 const dartx = dart_sdk.dartx; 7 const dartx = dart_sdk.dartx;
8 const expect = Object.create(null); 8 const expect = Object.create(null);
9 expect.Expect = class Expect extends core.Object { 9 expect.Expect = class Expect extends core.Object {
10 static _truncateString(string, start, end, length) { 10 static _truncateString(string, start, end, length) {
(...skipping 29 matching lines...) Expand all
40 if (expected[dartx.codeUnitAt](i) != actual[dartx.codeUnitAt](i)) { 40 if (expected[dartx.codeUnitAt](i) != actual[dartx.codeUnitAt](i)) {
41 let start = i; 41 let start = i;
42 i++; 42 i++;
43 while (i < dart.notNull(expected[dartx.length]) && i < dart.notNull(ac tual[dartx.length])) { 43 while (i < dart.notNull(expected[dartx.length]) && i < dart.notNull(ac tual[dartx.length])) {
44 if (expected[dartx.codeUnitAt](i) == actual[dartx.codeUnitAt](i)) br eak; 44 if (expected[dartx.codeUnitAt](i) == actual[dartx.codeUnitAt](i)) br eak;
45 i++; 45 i++;
46 } 46 }
47 let end = i; 47 let end = i;
48 let truncExpected = expect.Expect._truncateString(expected, start, end , 20); 48 let truncExpected = expect.Expect._truncateString(expected, start, end , 20);
49 let truncActual = expect.Expect._truncateString(actual, start, end, 20 ); 49 let truncActual = expect.Expect._truncateString(actual, start, end, 20 );
50 return `at index ${start}: Expected <${truncExpected}>, ` + `Found: <$ {truncActual}>`; 50 return dart.str`at index ${start}: Expected <${truncExpected}>, ` + da rt.str`Found: <${truncActual}>`;
51 } 51 }
52 } 52 }
53 return null; 53 return null;
54 } 54 }
55 static equals(expected, actual, reason) { 55 static equals(expected, actual, reason) {
56 if (reason === void 0) reason = null; 56 if (reason === void 0) reason = null;
57 if (dart.equals(expected, actual)) return; 57 if (dart.equals(expected, actual)) return;
58 let msg = expect.Expect._getMessage(reason); 58 let msg = expect.Expect._getMessage(reason);
59 if (typeof expected == 'string' && typeof actual == 'string') { 59 if (typeof expected == 'string' && typeof actual == 'string') {
60 let stringDifference = expect.Expect._stringDifference(expected, actual) ; 60 let stringDifference = expect.Expect._stringDifference(expected, actual) ;
61 if (stringDifference != null) { 61 if (stringDifference != null) {
62 expect.Expect._fail(`Expect.equals(${stringDifference}${msg}) fails.`) ; 62 expect.Expect._fail(dart.str`Expect.equals(${stringDifference}${msg}) fails.`);
63 } 63 }
64 } 64 }
65 expect.Expect._fail(`Expect.equals(expected: <${expected}>, actual: <${act ual}>${msg}) fails.`); 65 expect.Expect._fail(dart.str`Expect.equals(expected: <${expected}>, actual : <${actual}>${msg}) fails.`);
66 } 66 }
67 static isTrue(actual, reason) { 67 static isTrue(actual, reason) {
68 if (reason === void 0) reason = null; 68 if (reason === void 0) reason = null;
69 if (dart.notNull(expect._identical(actual, true))) return; 69 if (dart.notNull(expect._identical(actual, true))) return;
70 let msg = expect.Expect._getMessage(reason); 70 let msg = expect.Expect._getMessage(reason);
71 expect.Expect._fail(`Expect.isTrue(${actual}${msg}) fails.`); 71 expect.Expect._fail(dart.str`Expect.isTrue(${actual}${msg}) fails.`);
72 } 72 }
73 static isFalse(actual, reason) { 73 static isFalse(actual, reason) {
74 if (reason === void 0) reason = null; 74 if (reason === void 0) reason = null;
75 if (dart.notNull(expect._identical(actual, false))) return; 75 if (dart.notNull(expect._identical(actual, false))) return;
76 let msg = expect.Expect._getMessage(reason); 76 let msg = expect.Expect._getMessage(reason);
77 expect.Expect._fail(`Expect.isFalse(${actual}${msg}) fails.`); 77 expect.Expect._fail(dart.str`Expect.isFalse(${actual}${msg}) fails.`);
78 } 78 }
79 static isNull(actual, reason) { 79 static isNull(actual, reason) {
80 if (reason === void 0) reason = null; 80 if (reason === void 0) reason = null;
81 if (null == actual) return; 81 if (null == actual) return;
82 let msg = expect.Expect._getMessage(reason); 82 let msg = expect.Expect._getMessage(reason);
83 expect.Expect._fail(`Expect.isNull(actual: <${actual}>${msg}) fails.`); 83 expect.Expect._fail(dart.str`Expect.isNull(actual: <${actual}>${msg}) fail s.`);
84 } 84 }
85 static isNotNull(actual, reason) { 85 static isNotNull(actual, reason) {
86 if (reason === void 0) reason = null; 86 if (reason === void 0) reason = null;
87 if (null != actual) return; 87 if (null != actual) return;
88 let msg = expect.Expect._getMessage(reason); 88 let msg = expect.Expect._getMessage(reason);
89 expect.Expect._fail(`Expect.isNotNull(actual: <${actual}>${msg}) fails.`); 89 expect.Expect._fail(dart.str`Expect.isNotNull(actual: <${actual}>${msg}) f ails.`);
90 } 90 }
91 static identical(expected, actual, reason) { 91 static identical(expected, actual, reason) {
92 if (reason === void 0) reason = null; 92 if (reason === void 0) reason = null;
93 if (dart.notNull(expect._identical(expected, actual))) return; 93 if (dart.notNull(expect._identical(expected, actual))) return;
94 let msg = expect.Expect._getMessage(reason); 94 let msg = expect.Expect._getMessage(reason);
95 expect.Expect._fail(`Expect.identical(expected: <${expected}>, actual: <${ actual}>${msg}) ` + "fails."); 95 expect.Expect._fail(dart.str`Expect.identical(expected: <${expected}>, act ual: <${actual}>${msg}) ` + "fails.");
96 } 96 }
97 static fail(msg) { 97 static fail(msg) {
98 expect.Expect._fail(`Expect.fail('${msg}')`); 98 expect.Expect._fail(dart.str`Expect.fail('${msg}')`);
99 } 99 }
100 static approxEquals(expected, actual, tolerance, reason) { 100 static approxEquals(expected, actual, tolerance, reason) {
101 if (tolerance === void 0) tolerance = null; 101 if (tolerance === void 0) tolerance = null;
102 if (reason === void 0) reason = null; 102 if (reason === void 0) reason = null;
103 if (tolerance == null) { 103 if (tolerance == null) {
104 tolerance = (dart.notNull(expected) / 10000.0)[dartx.abs](); 104 tolerance = (dart.notNull(expected) / 10000.0)[dartx.abs]();
105 } 105 }
106 if (dart.notNull((dart.notNull(expected) - dart.notNull(actual))[dartx.abs ]()) <= dart.notNull(tolerance)) return; 106 if (dart.notNull((dart.notNull(expected) - dart.notNull(actual))[dartx.abs ]()) <= dart.notNull(tolerance)) return;
107 let msg = expect.Expect._getMessage(reason); 107 let msg = expect.Expect._getMessage(reason);
108 expect.Expect._fail(`Expect.approxEquals(expected:<${expected}>, actual:<$ {actual}>, ` + `tolerance:<${tolerance}>${msg}) fails`); 108 expect.Expect._fail(dart.str`Expect.approxEquals(expected:<${expected}>, a ctual:<${actual}>, ` + dart.str`tolerance:<${tolerance}>${msg}) fails`);
109 } 109 }
110 static notEquals(unexpected, actual, reason) { 110 static notEquals(unexpected, actual, reason) {
111 if (reason === void 0) reason = null; 111 if (reason === void 0) reason = null;
112 if (!dart.equals(unexpected, actual)) return; 112 if (!dart.equals(unexpected, actual)) return;
113 let msg = expect.Expect._getMessage(reason); 113 let msg = expect.Expect._getMessage(reason);
114 expect.Expect._fail(`Expect.notEquals(unexpected: <${unexpected}>, actual: <${actual}>${msg}) ` + "fails."); 114 expect.Expect._fail(dart.str`Expect.notEquals(unexpected: <${unexpected}>, actual:<${actual}>${msg}) ` + "fails.");
115 } 115 }
116 static listEquals(expected, actual, reason) { 116 static listEquals(expected, actual, reason) {
117 if (reason === void 0) reason = null; 117 if (reason === void 0) reason = null;
118 let msg = expect.Expect._getMessage(reason); 118 let msg = expect.Expect._getMessage(reason);
119 let n = dart.notNull(expected[dartx.length]) < dart.notNull(actual[dartx.l ength]) ? expected[dartx.length] : actual[dartx.length]; 119 let n = dart.notNull(expected[dartx.length]) < dart.notNull(actual[dartx.l ength]) ? expected[dartx.length] : actual[dartx.length];
120 for (let i = 0; i < dart.notNull(n); i++) { 120 for (let i = 0; i < dart.notNull(n); i++) {
121 if (!dart.equals(expected[dartx.get](i), actual[dartx.get](i))) { 121 if (!dart.equals(expected[dartx.get](i), actual[dartx.get](i))) {
122 expect.Expect._fail(`Expect.listEquals(at index ${i}, ` + `expected: < ${expected[dartx.get](i)}>, actual: <${actual[dartx.get](i)}>${msg}) fails`); 122 expect.Expect._fail(dart.str`Expect.listEquals(at index ${i}, ` + dart .str`expected: <${expected[dartx.get](i)}>, actual: <${actual[dartx.get](i)}>${m sg}) fails`);
123 } 123 }
124 } 124 }
125 if (expected[dartx.length] != actual[dartx.length]) { 125 if (expected[dartx.length] != actual[dartx.length]) {
126 expect.Expect._fail('Expect.listEquals(list length, ' + `expected: <${ex pected[dartx.length]}>, actual: <${actual[dartx.length]}>${msg}) ` + 'fails: Nex t element <' + `${dart.notNull(expected[dartx.length]) > dart.notNull(n) ? expec ted[dartx.get](n) : actual[dartx.get](n)}>`); 126 expect.Expect._fail('Expect.listEquals(list length, ' + dart.str`expecte d: <${expected[dartx.length]}>, actual: <${actual[dartx.length]}>${msg}) ` + 'fa ils: Next element <' + dart.str`${dart.notNull(expected[dartx.length]) > dart.no tNull(n) ? expected[dartx.get](n) : actual[dartx.get](n)}>`);
127 } 127 }
128 } 128 }
129 static mapEquals(expected, actual, reason) { 129 static mapEquals(expected, actual, reason) {
130 if (reason === void 0) reason = null; 130 if (reason === void 0) reason = null;
131 let msg = expect.Expect._getMessage(reason); 131 let msg = expect.Expect._getMessage(reason);
132 for (let key of expected[dartx.keys]) { 132 for (let key of expected[dartx.keys]) {
133 if (!dart.notNull(actual[dartx.containsKey](key))) { 133 if (!dart.notNull(actual[dartx.containsKey](key))) {
134 expect.Expect._fail(`Expect.mapEquals(missing expected key: <${key}>${ msg}) fails`); 134 expect.Expect._fail(dart.str`Expect.mapEquals(missing expected key: <$ {key}>${msg}) fails`);
135 } 135 }
136 expect.Expect.equals(expected[dartx.get](key), actual[dartx.get](key)); 136 expect.Expect.equals(expected[dartx.get](key), actual[dartx.get](key));
137 } 137 }
138 for (let key of actual[dartx.keys]) { 138 for (let key of actual[dartx.keys]) {
139 if (!dart.notNull(expected[dartx.containsKey](key))) { 139 if (!dart.notNull(expected[dartx.containsKey](key))) {
140 expect.Expect._fail(`Expect.mapEquals(unexpected key: <${key}>${msg}) fails`); 140 expect.Expect._fail(dart.str`Expect.mapEquals(unexpected key: <${key}> ${msg}) fails`);
141 } 141 }
142 } 142 }
143 } 143 }
144 static stringEquals(expected, actual, reason) { 144 static stringEquals(expected, actual, reason) {
145 if (reason === void 0) reason = null; 145 if (reason === void 0) reason = null;
146 if (expected == actual) return; 146 if (expected == actual) return;
147 let msg = expect.Expect._getMessage(reason); 147 let msg = expect.Expect._getMessage(reason);
148 let defaultMessage = `Expect.stringEquals(expected: <${expected}>", <${act ual}>${msg}) fails`; 148 let defaultMessage = dart.str`Expect.stringEquals(expected: <${expected}>" , <${actual}>${msg}) fails`;
149 if (expected == null || actual == null) { 149 if (expected == null || actual == null) {
150 expect.Expect._fail(`${defaultMessage}`); 150 expect.Expect._fail(dart.str`${defaultMessage}`);
151 } 151 }
152 let left = 0; 152 let left = 0;
153 let right = 0; 153 let right = 0;
154 let eLen = expected[dartx.length]; 154 let eLen = expected[dartx.length];
155 let aLen = actual[dartx.length]; 155 let aLen = actual[dartx.length];
156 while (true) { 156 while (true) {
157 if (left == eLen || left == aLen || expected[dartx.get](left) != actual[ dartx.get](left)) { 157 if (left == eLen || left == aLen || expected[dartx.get](left) != actual[ dartx.get](left)) {
158 break; 158 break;
159 } 159 }
160 left++; 160 left++;
(...skipping 14 matching lines...) Expand all
175 if (dart.notNull(eSnippet[dartx.length]) > 43) { 175 if (dart.notNull(eSnippet[dartx.length]) > 43) {
176 eSnippet = dart.notNull(eSnippet[dartx.substring](0, 20)) + "..." + dart .notNull(eSnippet[dartx.substring](dart.notNull(eSnippet[dartx.length]) - 20)); 176 eSnippet = dart.notNull(eSnippet[dartx.substring](0, 20)) + "..." + dart .notNull(eSnippet[dartx.substring](dart.notNull(eSnippet[dartx.length]) - 20));
177 } 177 }
178 if (dart.notNull(aSnippet[dartx.length]) > 43) { 178 if (dart.notNull(aSnippet[dartx.length]) > 43) {
179 aSnippet = dart.notNull(aSnippet[dartx.substring](0, 20)) + "..." + dart .notNull(aSnippet[dartx.substring](dart.notNull(aSnippet[dartx.length]) - 20)); 179 aSnippet = dart.notNull(aSnippet[dartx.substring](0, 20)) + "..." + dart .notNull(aSnippet[dartx.substring](dart.notNull(aSnippet[dartx.length]) - 20));
180 } 180 }
181 let leftLead = "..."; 181 let leftLead = "...";
182 let rightTail = "..."; 182 let rightTail = "...";
183 if (left <= 10) leftLead = ""; 183 if (left <= 10) leftLead = "";
184 if (right <= 10) rightTail = ""; 184 if (right <= 10) rightTail = "";
185 let diff = `\nDiff (${left}..${dart.notNull(eLen) - right}/${dart.notNull( aLen) - right}):\n` + `${leftLead}${leftSnippet}[ ${eSnippet} ]${rightSnippet}${ rightTail}\n` + `${leftLead}${leftSnippet}[ ${aSnippet} ]${rightSnippet}${rightT ail}`; 185 let diff = dart.str`\nDiff (${left}..${dart.notNull(eLen) - right}/${dart. notNull(aLen) - right}):\n` + dart.str`${leftLead}${leftSnippet}[ ${eSnippet} ]$ {rightSnippet}${rightTail}\n` + dart.str`${leftLead}${leftSnippet}[ ${aSnippet} ]${rightSnippet}${rightTail}`;
186 expect.Expect._fail(`${defaultMessage}${diff}`); 186 expect.Expect._fail(dart.str`${defaultMessage}${diff}`);
187 } 187 }
188 static setEquals(expected, actual, reason) { 188 static setEquals(expected, actual, reason) {
189 if (reason === void 0) reason = null; 189 if (reason === void 0) reason = null;
190 let missingSet = core.Set.from(expected); 190 let missingSet = core.Set.from(expected);
191 missingSet.removeAll(actual); 191 missingSet.removeAll(actual);
192 let extraSet = core.Set.from(actual); 192 let extraSet = core.Set.from(actual);
193 extraSet.removeAll(expected); 193 extraSet.removeAll(expected);
194 if (dart.notNull(extraSet.isEmpty) && dart.notNull(missingSet.isEmpty)) re turn; 194 if (dart.notNull(extraSet.isEmpty) && dart.notNull(missingSet.isEmpty)) re turn;
195 let msg = expect.Expect._getMessage(reason); 195 let msg = expect.Expect._getMessage(reason);
196 let sb = new core.StringBuffer(`Expect.setEquals(${msg}) fails`); 196 let sb = new core.StringBuffer(dart.str`Expect.setEquals(${msg}) fails`);
197 if (!dart.notNull(missingSet.isEmpty)) { 197 if (!dart.notNull(missingSet.isEmpty)) {
198 sb.write('\nExpected collection does not contain: '); 198 sb.write('\nExpected collection does not contain: ');
199 } 199 }
200 for (let val of missingSet) { 200 for (let val of missingSet) {
201 sb.write(`${val} `); 201 sb.write(dart.str`${val} `);
202 } 202 }
203 if (!dart.notNull(extraSet.isEmpty)) { 203 if (!dart.notNull(extraSet.isEmpty)) {
204 sb.write('\nExpected collection should not contain: '); 204 sb.write('\nExpected collection should not contain: ');
205 } 205 }
206 for (let val of extraSet) { 206 for (let val of extraSet) {
207 sb.write(`${val} `); 207 sb.write(dart.str`${val} `);
208 } 208 }
209 expect.Expect._fail(sb.toString()); 209 expect.Expect._fail(sb.toString());
210 } 210 }
211 static throws(f, check, reason) { 211 static throws(f, check, reason) {
212 if (check === void 0) check = null; 212 if (check === void 0) check = null;
213 if (reason === void 0) reason = null; 213 if (reason === void 0) reason = null;
214 let msg = reason == null ? "" : `(${reason})`; 214 let msg = reason == null ? "" : dart.str`(${reason})`;
215 if (!dart.is(f, expect._Nullary)) { 215 if (!dart.is(f, expect._Nullary)) {
216 expect.Expect._fail(`Expect.throws${msg}: Function f not callable with z ero arguments`); 216 expect.Expect._fail(dart.str`Expect.throws${msg}: Function f not callabl e with zero arguments`);
217 } 217 }
218 try { 218 try {
219 f(); 219 f();
220 } catch (e) { 220 } catch (e) {
221 let s = dart.stackTrace(e); 221 let s = dart.stackTrace(e);
222 if (check != null) { 222 if (check != null) {
223 if (!dart.notNull(dart.dcall(check, e))) { 223 if (!dart.notNull(dart.dcall(check, e))) {
224 expect.Expect._fail(`Expect.throws${msg}: Unexpected '${e}'\n${s}`); 224 expect.Expect._fail(dart.str`Expect.throws${msg}: Unexpected '${e}'\ n${s}`);
225 } 225 }
226 } 226 }
227 return; 227 return;
228 } 228 }
229 229
230 expect.Expect._fail(`Expect.throws${msg} fails: Did not throw`); 230 expect.Expect._fail(dart.str`Expect.throws${msg} fails: Did not throw`);
231 } 231 }
232 static _getMessage(reason) { 232 static _getMessage(reason) {
233 return reason == null ? "" : `, '${reason}'`; 233 return reason == null ? "" : dart.str`, '${reason}'`;
234 } 234 }
235 static _fail(message) { 235 static _fail(message) {
236 dart.throw(new expect.ExpectException(message)); 236 dart.throw(new expect.ExpectException(message));
237 } 237 }
238 }; 238 };
239 dart.setSignature(expect.Expect, { 239 dart.setSignature(expect.Expect, {
240 statics: () => ({ 240 statics: () => ({
241 _truncateString: [core.String, [core.String, core.int, core.int, core.int] ], 241 _truncateString: [core.String, [core.String, core.int, core.int, core.int] ],
242 _stringDifference: [core.String, [core.String, core.String]], 242 _stringDifference: [core.String, [core.String, core.String]],
243 equals: [dart.void, [dart.dynamic, dart.dynamic], [core.String]], 243 equals: [dart.void, [dart.dynamic, dart.dynamic], [core.String]],
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 expect.AssumeDynamic = class AssumeDynamic extends core.Object { 294 expect.AssumeDynamic = class AssumeDynamic extends core.Object {
295 new() { 295 new() {
296 } 296 }
297 }; 297 };
298 dart.setSignature(expect.AssumeDynamic, { 298 dart.setSignature(expect.AssumeDynamic, {
299 constructors: () => ({new: [expect.AssumeDynamic, []]}) 299 constructors: () => ({new: [expect.AssumeDynamic, []]})
300 }); 300 });
301 // Exports: 301 // Exports:
302 exports.expect = expect; 302 exports.expect = expect;
303 }); 303 });
OLDNEW
« no previous file with comments | « test/codegen/expect/covariance.js ('k') | test/codegen/expect/expect/expect.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698