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

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

Issue 1243503007: fixes #221, initial sync*, async, async* implementation (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 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
« no previous file with comments | « test/codegen/expect/unittest.txt ('k') | test/codegen/js_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 dart_library.library('unittest/unittest', null, /* Imports */[
2 "dart_runtime/dart",
3 'dom/dom',
4 'dart/core',
5 'dart/async'
6 ], /* Lazy imports */[
7 ], function(exports, dart, dom, core, async) {
8 'use strict';
9 let dartx = dart.dartx;
10 function group(name, body) {
11 return dart.dsend(dart.as(dom.window, dart.dynamic), 'suite', name, body);
12 }
13 dart.fn(group, dart.void, [core.String, dart.functionType(dart.void, [])]);
14 function test(name, body, opts) {
15 let skip = opts && 'skip' in opts ? opts.skip : null;
16 if (skip != null) {
17 core.print(`SKIP ${name}: ${skip}`);
18 return;
19 }
20 dart.dsend(dart.as(dom.window, dart.dynamic), 'test', name, dart.fn(done => {
21 function _finishTest(f) {
22 if (dart.is(f, async.Future)) {
23 dart.dsend(f, 'then', _finishTest);
24 } else {
25 dart.dcall(done);
26 }
27 }
28 dart.fn(_finishTest);
29 _finishTest(body());
30 }));
31 }
32 dart.fn(test, dart.void, [core.String, dart.functionType(dart.dynamic, [])], { skip: core.String});
33 function expect(actual, matcher) {
34 if (!dart.is(matcher, Matcher))
35 matcher = equals(matcher);
36 if (!dart.notNull(dart.as(dart.dcall(matcher, actual), core.bool))) {
37 dart.throw(`Expect failed to match ${actual} with ${matcher}`);
38 }
39 }
40 dart.fn(expect, dart.void, [core.Object, dart.dynamic]);
41 function fail(message) {
42 dart.throw('TestFailure: ' + dart.notNull(message));
43 }
44 dart.fn(fail, dart.void, [core.String]);
45 function equals(expected) {
46 return dart.fn(actual => {
47 if (dart.is(expected, core.List) && dart.is(actual, core.List)) {
48 let len = expected[dartx.length];
49 if (!dart.equals(len, dart.dload(actual, 'length')))
50 return false;
51 for (let i = 0; dart.notNull(i) < dart.notNull(len); i = dart.notNull(i) + 1) {
52 if (!dart.notNull(dart.as(dart.dcall(equals(expected[dartx.get](i)), d art.dindex(actual, i)), core.bool)))
53 return false;
54 }
55 return true;
56 } else {
57 return dart.equals(expected, actual);
58 }
59 });
60 }
61 dart.fn(equals, () => dart.definiteFunctionType(Matcher, [core.Object]));
62 function same(expected) {
63 return dart.fn(actual => core.identical(expected, actual), core.bool, [dart. dynamic]);
64 }
65 dart.fn(same, () => dart.definiteFunctionType(Matcher, [core.Object]));
66 function isNot(matcher) {
67 if (!dart.is(matcher, Matcher))
68 matcher = equals(matcher);
69 return dart.fn(actual => !dart.notNull(dart.as(dart.dcall(matcher, actual), core.bool)), core.bool, [dart.dynamic]);
70 }
71 dart.fn(isNot, () => dart.definiteFunctionType(Matcher, [dart.dynamic]));
72 function isTrue(actual) {
73 return dart.equals(actual, true);
74 }
75 dart.fn(isTrue, core.bool, [dart.dynamic]);
76 function isNull(actual) {
77 return actual == null;
78 }
79 dart.fn(isNull, core.bool, [dart.dynamic]);
80 dart.defineLazyProperties(exports, {
81 get isNotNull() {
82 return isNot(isNull);
83 }
84 });
85 function isRangeError(actual) {
86 return dart.is(actual, core.RangeError);
87 }
88 dart.fn(isRangeError, core.bool, [dart.dynamic]);
89 function isNoSuchMethodError(actual) {
90 return dart.is(actual, core.NoSuchMethodError);
91 }
92 dart.fn(isNoSuchMethodError, core.bool, [dart.dynamic]);
93 function lessThan(expected) {
94 return dart.fn(actual => dart.dsend(actual, '<', expected));
95 }
96 dart.fn(lessThan, () => dart.definiteFunctionType(Matcher, [dart.dynamic]));
97 function greaterThan(expected) {
98 return dart.fn(actual => dart.dsend(actual, '>', expected));
99 }
100 dart.fn(greaterThan, () => dart.definiteFunctionType(Matcher, [dart.dynamic])) ;
101 function throwsA(matcher) {
102 if (!dart.is(matcher, Matcher))
103 matcher = equals(matcher);
104 return dart.fn(actual => {
105 try {
106 dart.dcall(actual);
107 return false;
108 } catch (e) {
109 return dart.dcall(matcher, e);
110 }
111
112 });
113 }
114 dart.fn(throwsA, () => dart.definiteFunctionType(Matcher, [dart.dynamic]));
115 dart.defineLazyProperties(exports, {
116 get throws() {
117 return throwsA(dart.fn(a => true, core.bool, [dart.dynamic]));
118 }
119 });
120 let Matcher = dart.typedef('Matcher', () => dart.functionType(dart.dynamic, [d art.dynamic]));
121 // Exports:
122 exports.group = group;
123 exports.test = test;
124 exports.expect = expect;
125 exports.fail = fail;
126 exports.equals = equals;
127 exports.same = same;
128 exports.isNot = isNot;
129 exports.isTrue = isTrue;
130 exports.isNull = isNull;
131 exports.isRangeError = isRangeError;
132 exports.isNoSuchMethodError = isNoSuchMethodError;
133 exports.lessThan = lessThan;
134 exports.greaterThan = greaterThan;
135 exports.throwsA = throwsA;
136 exports.Matcher = Matcher;
137 });
OLDNEW
« no previous file with comments | « test/codegen/expect/unittest.txt ('k') | test/codegen/js_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698