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

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

Issue 2234343003: fix #620, infer the input files from sources (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: fix Created 4 years, 4 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
OLDNEW
(Empty)
1 dart_library.library('expect', null, /* Imports */[
2 'dart_sdk'
3 ], function load__expect(exports, dart_sdk) {
4 'use strict';
5 const core = dart_sdk.core;
6 const dart = dart_sdk.dart;
7 const dartx = dart_sdk.dartx;
8 const expect = Object.create(null);
9 let dynamicAnddynamicTobool = () => (dynamicAnddynamicTobool = dart.constFn(da rt.definiteFunctionType(core.bool, [dart.dynamic, dart.dynamic])))();
10 expect.Expect = class Expect extends core.Object {
11 static _truncateString(string, start, end, length) {
12 if (dart.notNull(end) - dart.notNull(start) > dart.notNull(length)) {
13 end = dart.notNull(start) + dart.notNull(length);
14 } else if (dart.notNull(end) - dart.notNull(start) < dart.notNull(length)) {
15 let overflow = dart.notNull(length) - (dart.notNull(end) - dart.notNull( start));
16 if (overflow > 10) overflow = 10;
17 start = dart.notNull(start) - ((overflow + 1) / 2)[dartx.truncate]();
18 end = dart.notNull(end) + (overflow / 2)[dartx.truncate]();
19 if (dart.notNull(start) < 0) start = 0;
20 if (dart.notNull(end) > dart.notNull(string[dartx.length])) end = string [dartx.length];
21 }
22 if (start == 0 && end == string[dartx.length]) return string;
23 let buf = new core.StringBuffer();
24 if (dart.notNull(start) > 0) buf.write("...");
25 for (let i = start; dart.notNull(i) < dart.notNull(end); i = dart.notNull( i) + 1) {
26 let code = string[dartx.codeUnitAt](i);
27 if (dart.notNull(code) < 32) {
28 buf.write("\\x");
29 buf.write("0123456789abcdef"[dartx.get]((dart.notNull(code) / 16)[dart x.truncate]()));
30 buf.write("0123456789abcdef"[dartx.get](code[dartx['%']](16)));
31 } else {
32 buf.writeCharCode(string[dartx.codeUnitAt](i));
33 }
34 }
35 if (dart.notNull(end) < dart.notNull(string[dartx.length])) buf.write("... ");
36 return buf.toString();
37 }
38 static _stringDifference(expected, actual) {
39 if (dart.notNull(expected[dartx.length]) < 20 && dart.notNull(actual[dartx .length]) < 20) return null;
40 for (let i = 0; i < dart.notNull(expected[dartx.length]) && i < dart.notNu ll(actual[dartx.length]); i++) {
41 if (expected[dartx.codeUnitAt](i) != actual[dartx.codeUnitAt](i)) {
42 let start = i;
43 i++;
44 while (i < dart.notNull(expected[dartx.length]) && i < dart.notNull(ac tual[dartx.length])) {
45 if (expected[dartx.codeUnitAt](i) == actual[dartx.codeUnitAt](i)) br eak;
46 i++;
47 }
48 let end = i;
49 let truncExpected = expect.Expect._truncateString(expected, start, end , 20);
50 let truncActual = expect.Expect._truncateString(actual, start, end, 20 );
51 return dart.str`at index ${start}: Expected <${truncExpected}>, ` + da rt.str`Found: <${truncActual}>`;
52 }
53 }
54 return null;
55 }
56 static equals(expected, actual, reason) {
57 if (reason === void 0) reason = null;
58 if (dart.equals(expected, actual)) return;
59 let msg = expect.Expect._getMessage(reason);
60 if (typeof expected == 'string' && typeof actual == 'string') {
61 let stringDifference = expect.Expect._stringDifference(expected, actual) ;
62 if (stringDifference != null) {
63 expect.Expect._fail(dart.str`Expect.equals(${stringDifference}${msg}) fails.`);
64 }
65 }
66 expect.Expect._fail(dart.str`Expect.equals(expected: <${expected}>, actual : <${actual}>${msg}) fails.`);
67 }
68 static isTrue(actual, reason) {
69 if (reason === void 0) reason = null;
70 if (dart.test(expect._identical(actual, true))) return;
71 let msg = expect.Expect._getMessage(reason);
72 expect.Expect._fail(dart.str`Expect.isTrue(${actual}${msg}) fails.`);
73 }
74 static isFalse(actual, reason) {
75 if (reason === void 0) reason = null;
76 if (dart.test(expect._identical(actual, false))) return;
77 let msg = expect.Expect._getMessage(reason);
78 expect.Expect._fail(dart.str`Expect.isFalse(${actual}${msg}) fails.`);
79 }
80 static isNull(actual, reason) {
81 if (reason === void 0) reason = null;
82 if (null == actual) return;
83 let msg = expect.Expect._getMessage(reason);
84 expect.Expect._fail(dart.str`Expect.isNull(actual: <${actual}>${msg}) fail s.`);
85 }
86 static isNotNull(actual, reason) {
87 if (reason === void 0) reason = null;
88 if (null != actual) return;
89 let msg = expect.Expect._getMessage(reason);
90 expect.Expect._fail(dart.str`Expect.isNotNull(actual: <${actual}>${msg}) f ails.`);
91 }
92 static identical(expected, actual, reason) {
93 if (reason === void 0) reason = null;
94 if (dart.test(expect._identical(expected, actual))) return;
95 let msg = expect.Expect._getMessage(reason);
96 expect.Expect._fail(dart.str`Expect.identical(expected: <${expected}>, act ual: <${actual}>${msg}) ` + "fails.");
97 }
98 static fail(msg) {
99 expect.Expect._fail(dart.str`Expect.fail('${msg}')`);
100 }
101 static approxEquals(expected, actual, tolerance, reason) {
102 if (tolerance === void 0) tolerance = null;
103 if (reason === void 0) reason = null;
104 if (tolerance == null) {
105 tolerance = (dart.notNull(expected) / 10000.0)[dartx.abs]();
106 }
107 if (dart.notNull((dart.notNull(expected) - dart.notNull(actual))[dartx.abs ]()) <= dart.notNull(tolerance)) return;
108 let msg = expect.Expect._getMessage(reason);
109 expect.Expect._fail(dart.str`Expect.approxEquals(expected:<${expected}>, a ctual:<${actual}>, ` + dart.str`tolerance:<${tolerance}>${msg}) fails`);
110 }
111 static notEquals(unexpected, actual, reason) {
112 if (reason === void 0) reason = null;
113 if (!dart.equals(unexpected, actual)) return;
114 let msg = expect.Expect._getMessage(reason);
115 expect.Expect._fail(dart.str`Expect.notEquals(unexpected: <${unexpected}>, actual:<${actual}>${msg}) ` + "fails.");
116 }
117 static listEquals(expected, actual, reason) {
118 if (reason === void 0) reason = null;
119 let msg = expect.Expect._getMessage(reason);
120 let n = dart.notNull(expected[dartx.length]) < dart.notNull(actual[dartx.l ength]) ? expected[dartx.length] : actual[dartx.length];
121 for (let i = 0; i < dart.notNull(n); i++) {
122 if (!dart.equals(expected[dartx.get](i), actual[dartx.get](i))) {
123 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`);
124 }
125 }
126 if (expected[dartx.length] != actual[dartx.length]) {
127 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)}>`);
128 }
129 }
130 static mapEquals(expected, actual, reason) {
131 if (reason === void 0) reason = null;
132 let msg = expect.Expect._getMessage(reason);
133 for (let key of expected[dartx.keys]) {
134 if (!dart.test(actual[dartx.containsKey](key))) {
135 expect.Expect._fail(dart.str`Expect.mapEquals(missing expected key: <$ {key}>${msg}) fails`);
136 }
137 expect.Expect.equals(expected[dartx.get](key), actual[dartx.get](key));
138 }
139 for (let key of actual[dartx.keys]) {
140 if (!dart.test(expected[dartx.containsKey](key))) {
141 expect.Expect._fail(dart.str`Expect.mapEquals(unexpected key: <${key}> ${msg}) fails`);
142 }
143 }
144 }
145 static stringEquals(expected, actual, reason) {
146 if (reason === void 0) reason = null;
147 if (expected == actual) return;
148 let msg = expect.Expect._getMessage(reason);
149 let defaultMessage = dart.str`Expect.stringEquals(expected: <${expected}>" , <${actual}>${msg}) fails`;
150 if (expected == null || actual == null) {
151 expect.Expect._fail(dart.str`${defaultMessage}`);
152 }
153 let left = 0;
154 let right = 0;
155 let eLen = expected[dartx.length];
156 let aLen = actual[dartx.length];
157 while (true) {
158 if (left == eLen || left == aLen || expected[dartx.get](left) != actual[ dartx.get](left)) {
159 break;
160 }
161 left++;
162 }
163 let eRem = dart.notNull(eLen) - left;
164 let aRem = dart.notNull(aLen) - left;
165 while (true) {
166 if (right == eRem || right == aRem || expected[dartx.get](dart.notNull(e Len) - right - 1) != actual[dartx.get](dart.notNull(aLen) - right - 1)) {
167 break;
168 }
169 right++;
170 }
171 let leftSnippet = expected[dartx.substring](left < 10 ? 0 : left - 10, lef t);
172 let rightSnippetLength = right < 10 ? right : 10;
173 let rightSnippet = expected[dartx.substring](dart.notNull(eLen) - right, d art.notNull(eLen) - right + rightSnippetLength);
174 let eSnippet = expected[dartx.substring](left, dart.notNull(eLen) - right) ;
175 let aSnippet = actual[dartx.substring](left, dart.notNull(aLen) - right);
176 if (dart.notNull(eSnippet[dartx.length]) > 43) {
177 eSnippet = dart.notNull(eSnippet[dartx.substring](0, 20)) + "..." + dart .notNull(eSnippet[dartx.substring](dart.notNull(eSnippet[dartx.length]) - 20));
178 }
179 if (dart.notNull(aSnippet[dartx.length]) > 43) {
180 aSnippet = dart.notNull(aSnippet[dartx.substring](0, 20)) + "..." + dart .notNull(aSnippet[dartx.substring](dart.notNull(aSnippet[dartx.length]) - 20));
181 }
182 let leftLead = "...";
183 let rightTail = "...";
184 if (left <= 10) leftLead = "";
185 if (right <= 10) rightTail = "";
186 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}`;
187 expect.Expect._fail(dart.str`${defaultMessage}${diff}`);
188 }
189 static setEquals(expected, actual, reason) {
190 if (reason === void 0) reason = null;
191 let missingSet = core.Set.from(expected);
192 missingSet.removeAll(actual);
193 let extraSet = core.Set.from(actual);
194 extraSet.removeAll(expected);
195 if (dart.test(extraSet.isEmpty) && dart.test(missingSet.isEmpty)) return;
196 let msg = expect.Expect._getMessage(reason);
197 let sb = new core.StringBuffer(dart.str`Expect.setEquals(${msg}) fails`);
198 if (!dart.test(missingSet.isEmpty)) {
199 sb.write('\nExpected collection does not contain: ');
200 }
201 for (let val of missingSet) {
202 sb.write(dart.str`${val} `);
203 }
204 if (!dart.test(extraSet.isEmpty)) {
205 sb.write('\nExpected collection should not contain: ');
206 }
207 for (let val of extraSet) {
208 sb.write(dart.str`${val} `);
209 }
210 expect.Expect._fail(sb.toString());
211 }
212 static throws(f, check, reason) {
213 if (check === void 0) check = null;
214 if (reason === void 0) reason = null;
215 let msg = reason == null ? "" : dart.str`(${reason})`;
216 if (!expect._Nullary.is(f)) {
217 expect.Expect._fail(dart.str`Expect.throws${msg}: Function f not callabl e with zero arguments`);
218 }
219 try {
220 f();
221 } catch (e) {
222 let s = dart.stackTrace(e);
223 if (check != null) {
224 if (!dart.test(dart.dcall(check, e))) {
225 expect.Expect._fail(dart.str`Expect.throws${msg}: Unexpected '${e}'\ n${s}`);
226 }
227 }
228 return;
229 }
230
231 expect.Expect._fail(dart.str`Expect.throws${msg} fails: Did not throw`);
232 }
233 static _getMessage(reason) {
234 return reason == null ? "" : dart.str`, '${reason}'`;
235 }
236 static _fail(message) {
237 dart.throw(new expect.ExpectException(message));
238 }
239 };
240 dart.setSignature(expect.Expect, {
241 statics: () => ({
242 _truncateString: dart.definiteFunctionType(core.String, [core.String, core .int, core.int, core.int]),
243 _stringDifference: dart.definiteFunctionType(core.String, [core.String, co re.String]),
244 equals: dart.definiteFunctionType(dart.void, [dart.dynamic, dart.dynamic], [core.String]),
245 isTrue: dart.definiteFunctionType(dart.void, [dart.dynamic], [core.String] ),
246 isFalse: dart.definiteFunctionType(dart.void, [dart.dynamic], [core.String ]),
247 isNull: dart.definiteFunctionType(dart.void, [dart.dynamic], [core.String] ),
248 isNotNull: dart.definiteFunctionType(dart.void, [dart.dynamic], [core.Stri ng]),
249 identical: dart.definiteFunctionType(dart.void, [dart.dynamic, dart.dynami c], [core.String]),
250 fail: dart.definiteFunctionType(dart.void, [core.String]),
251 approxEquals: dart.definiteFunctionType(dart.void, [core.num, core.num], [ core.num, core.String]),
252 notEquals: dart.definiteFunctionType(dart.void, [dart.dynamic, dart.dynami c], [core.String]),
253 listEquals: dart.definiteFunctionType(dart.void, [core.List, core.List], [ core.String]),
254 mapEquals: dart.definiteFunctionType(dart.void, [core.Map, core.Map], [cor e.String]),
255 stringEquals: dart.definiteFunctionType(dart.void, [core.String, core.Stri ng], [core.String]),
256 setEquals: dart.definiteFunctionType(dart.void, [core.Iterable, core.Itera ble], [core.String]),
257 throws: dart.definiteFunctionType(dart.void, [dart.functionType(dart.void, [])], [expect._CheckExceptionFn, core.String]),
258 _getMessage: dart.definiteFunctionType(core.String, [core.String]),
259 _fail: dart.definiteFunctionType(dart.void, [core.String])
260 }),
261 names: ['_truncateString', '_stringDifference', 'equals', 'isTrue', 'isFalse ', 'isNull', 'isNotNull', 'identical', 'fail', 'approxEquals', 'notEquals', 'lis tEquals', 'mapEquals', 'stringEquals', 'setEquals', 'throws', '_getMessage', '_f ail']
262 });
263 expect._identical = function(a, b) {
264 return core.identical(a, b);
265 };
266 dart.fn(expect._identical, dynamicAnddynamicTobool());
267 expect._CheckExceptionFn = dart.typedef('_CheckExceptionFn', () => dart.functi onType(core.bool, [dart.dynamic]));
268 expect._Nullary = dart.typedef('_Nullary', () => dart.functionType(dart.dynami c, []));
269 expect.ExpectException = class ExpectException extends core.Object {
270 new(message) {
271 this.message = message;
272 }
273 toString() {
274 return this.message;
275 }
276 };
277 expect.ExpectException[dart.implements] = () => [core.Exception];
278 dart.setSignature(expect.ExpectException, {
279 constructors: () => ({new: dart.definiteFunctionType(expect.ExpectException, [core.String])})
280 });
281 expect.NoInline = class NoInline extends core.Object {
282 new() {
283 }
284 };
285 dart.setSignature(expect.NoInline, {
286 constructors: () => ({new: dart.definiteFunctionType(expect.NoInline, [])})
287 });
288 expect.TrustTypeAnnotations = class TrustTypeAnnotations extends core.Object {
289 new() {
290 }
291 };
292 dart.setSignature(expect.TrustTypeAnnotations, {
293 constructors: () => ({new: dart.definiteFunctionType(expect.TrustTypeAnnotat ions, [])})
294 });
295 expect.AssumeDynamic = class AssumeDynamic extends core.Object {
296 new() {
297 }
298 };
299 dart.setSignature(expect.AssumeDynamic, {
300 constructors: () => ({new: dart.definiteFunctionType(expect.AssumeDynamic, [ ])})
301 });
302 // Exports:
303 exports.expect = expect;
304 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698