OLD | NEW |
1 dart_library.library('expect', null, /* Imports */[ | 1 dart_library.library('expect', null, /* Imports */[ |
2 "dart_runtime/dart", | 2 "dart_runtime/dart", |
3 'dart/core' | 3 'dart/core' |
4 ], /* Lazy imports */[ | 4 ], /* Lazy imports */[ |
5 ], function(exports, dart, core) { | 5 ], function(exports, dart, core) { |
6 'use strict'; | 6 'use strict'; |
7 let dartx = dart.dartx; | 7 let dartx = dart.dartx; |
8 class Expect extends core.Object { | 8 class Expect extends core.Object { |
9 static _truncateString(string, start, end, length) { | 9 static _truncateString(string, start, end, length) { |
10 if (dart.notNull(end) - dart.notNull(start) > dart.notNull(length)) { | 10 if (dart.notNull(end) - dart.notNull(start) > dart.notNull(length)) { |
11 end = dart.notNull(start) + dart.notNull(length); | 11 end = dart.notNull(start) + dart.notNull(length); |
12 } else if (dart.notNull(end) - dart.notNull(start) < dart.notNull(length))
{ | 12 } else if (dart.notNull(end) - dart.notNull(start) < dart.notNull(length))
{ |
13 let overflow = dart.notNull(length) - (dart.notNull(end) - dart.notNull(
start)); | 13 let overflow = dart.notNull(length) - (dart.notNull(end) - dart.notNull(
start)); |
14 if (dart.notNull(overflow) > 10) | 14 if (dart.notNull(overflow) > 10) |
15 overflow = 10; | 15 overflow = 10; |
16 start = dart.notNull(start) - ((dart.notNull(overflow) + 1) / 2)[dartx.t
runcate](); | 16 start = dart.notNull(start) - ((dart.notNull(overflow) + 1) / 2)[dartx.t
runcate](); |
17 end = dart.notNull(end) + (dart.notNull(overflow) / 2)[dartx.truncate]()
; | 17 end = dart.notNull(end) + (dart.notNull(overflow) / 2)[dartx.truncate]()
; |
18 if (dart.notNull(start) < 0) | 18 if (dart.notNull(start) < 0) |
19 start = 0; | 19 start = 0; |
20 if (dart.notNull(end) > dart.notNull(string[dartx.length])) | 20 if (dart.notNull(end) > dart.notNull(string[dartx.length])) |
21 end = string[dartx.length]; | 21 end = string[dartx.length]; |
22 } | 22 } |
23 if (start == 0 && end == string[dartx.length]) | 23 if (start == 0 && end == string[dartx.length]) |
24 return string; | 24 return string; |
25 let buf = new core.StringBuffer(); | 25 let buf = new core.StringBuffer(); |
26 if (dart.notNull(start) > 0) | 26 if (dart.notNull(start) > 0) |
27 buf.write("..."); | 27 dart.dcall(buf.write, "..."); |
28 for (let i = start; dart.notNull(i) < dart.notNull(end); i = dart.notNull(
i) + 1) { | 28 for (let i = start; dart.notNull(i) < dart.notNull(end); i = dart.notNull(
i) + 1) { |
29 let code = string[dartx.codeUnitAt](i); | 29 let code = dart.dcall(string[dartx.codeUnitAt], i); |
30 if (dart.notNull(code) < 32) { | 30 if (dart.notNull(code) < 32) { |
31 buf.write("\\x"); | 31 dart.dcall(buf.write, "\\x"); |
32 buf.write("0123456789abcdef"[dartx.get]((dart.notNull(code) / 16)[dart
x.truncate]())); | 32 dart.dcall(buf.write, "0123456789abcdef"[dartx.get]((dart.notNull(code
) / 16)[dartx.truncate]())); |
33 buf.write("0123456789abcdef"[dartx.get](dart.notNull(code) % 16)); | 33 dart.dcall(buf.write, "0123456789abcdef"[dartx.get](dart.notNull(code)
% 16)); |
34 } else { | 34 } else { |
35 buf.writeCharCode(string[dartx.codeUnitAt](i)); | 35 dart.dcall(buf.writeCharCode, dart.dcall(string[dartx.codeUnitAt], i))
; |
36 } | 36 } |
37 } | 37 } |
38 if (dart.notNull(end) < dart.notNull(string[dartx.length])) | 38 if (dart.notNull(end) < dart.notNull(string[dartx.length])) |
39 buf.write("..."); | 39 dart.dcall(buf.write, "..."); |
40 return dart.toString(buf); | 40 return dart.dcall(buf.toString); |
41 } | 41 } |
42 static _stringDifference(expected, actual) { | 42 static _stringDifference(expected, actual) { |
43 if (dart.notNull(expected[dartx.length]) < 20 && dart.notNull(actual[dartx
.length]) < 20) | 43 if (dart.notNull(expected[dartx.length]) < 20 && dart.notNull(actual[dartx
.length]) < 20) |
44 return null; | 44 return null; |
45 for (let i = 0; dart.notNull(i) < dart.notNull(expected[dartx.length]) &&
dart.notNull(i) < dart.notNull(actual[dartx.length]); i = dart.notNull(i) + 1) { | 45 for (let i = 0; dart.notNull(i) < dart.notNull(expected[dartx.length]) &&
dart.notNull(i) < dart.notNull(actual[dartx.length]); i = dart.notNull(i) + 1) { |
46 if (expected[dartx.codeUnitAt](i) != actual[dartx.codeUnitAt](i)) { | 46 if (dart.dcall(expected[dartx.codeUnitAt], i) != dart.dcall(actual[dartx
.codeUnitAt], i)) { |
47 let start = i; | 47 let start = i; |
48 i = dart.notNull(i) + 1; | 48 i = dart.notNull(i) + 1; |
49 while (dart.notNull(i) < dart.notNull(expected[dartx.length]) && dart.
notNull(i) < dart.notNull(actual[dartx.length])) { | 49 while (dart.notNull(i) < dart.notNull(expected[dartx.length]) && dart.
notNull(i) < dart.notNull(actual[dartx.length])) { |
50 if (expected[dartx.codeUnitAt](i) == actual[dartx.codeUnitAt](i)) | 50 if (dart.dcall(expected[dartx.codeUnitAt], i) == dart.dcall(actual[d
artx.codeUnitAt], i)) |
51 break; | 51 break; |
52 i = dart.notNull(i) + 1; | 52 i = dart.notNull(i) + 1; |
53 } | 53 } |
54 let end = i; | 54 let end = i; |
55 let truncExpected = Expect._truncateString(expected, start, end, 20); | 55 let truncExpected = dart.dcall(Expect._truncateString, expected, start
, end, 20); |
56 let truncActual = Expect._truncateString(actual, start, end, 20); | 56 let truncActual = dart.dcall(Expect._truncateString, actual, start, en
d, 20); |
57 return `at index ${start}: Expected <${truncExpected}>, ` + `Found: <$
{truncActual}>`; | 57 return `at index ${start}: Expected <${truncExpected}>, ` + `Found: <$
{truncActual}>`; |
58 } | 58 } |
59 } | 59 } |
60 return null; | 60 return null; |
61 } | 61 } |
62 static equals(expected, actual, reason) { | 62 static equals(expected, actual, reason) { |
63 if (reason === void 0) | 63 if (reason === void 0) |
64 reason = null; | 64 reason = null; |
65 if (dart.equals(expected, actual)) | 65 if (dart.equals(expected, actual)) |
66 return; | 66 return; |
67 let msg = Expect._getMessage(reason); | 67 let msg = dart.dcall(Expect._getMessage, reason); |
68 if (typeof expected == 'string' && typeof actual == 'string') { | 68 if (typeof expected == 'string' && typeof actual == 'string') { |
69 let stringDifference = Expect._stringDifference(dart.as(expected, core.S
tring), dart.as(actual, core.String)); | 69 let stringDifference = dart.dcall(Expect._stringDifference, expected, ac
tual); |
70 if (stringDifference != null) { | 70 if (stringDifference != null) { |
71 Expect._fail(`Expect.equals(${stringDifference}${msg}) fails.`); | 71 dart.dcall(Expect._fail, `Expect.equals(${stringDifference}${msg}) fai
ls.`); |
72 } | 72 } |
73 } | 73 } |
74 Expect._fail(`Expect.equals(expected: <${expected}>, actual: <${actual}>${
msg}) fails.`); | 74 dart.dcall(Expect._fail, `Expect.equals(expected: <${expected}>, actual: <
${actual}>${msg}) fails.`); |
75 } | 75 } |
76 static isTrue(actual, reason) { | 76 static isTrue(actual, reason) { |
77 if (reason === void 0) | 77 if (reason === void 0) |
78 reason = null; | 78 reason = null; |
79 if (dart.notNull(_identical(actual, true))) | 79 if (dart.notNull(dart.dcall(_identical, actual, true))) |
80 return; | 80 return; |
81 let msg = Expect._getMessage(reason); | 81 let msg = dart.dcall(Expect._getMessage, reason); |
82 Expect._fail(`Expect.isTrue(${actual}${msg}) fails.`); | 82 dart.dcall(Expect._fail, `Expect.isTrue(${actual}${msg}) fails.`); |
83 } | 83 } |
84 static isFalse(actual, reason) { | 84 static isFalse(actual, reason) { |
85 if (reason === void 0) | 85 if (reason === void 0) |
86 reason = null; | 86 reason = null; |
87 if (dart.notNull(_identical(actual, false))) | 87 if (dart.notNull(dart.dcall(_identical, actual, false))) |
88 return; | 88 return; |
89 let msg = Expect._getMessage(reason); | 89 let msg = dart.dcall(Expect._getMessage, reason); |
90 Expect._fail(`Expect.isFalse(${actual}${msg}) fails.`); | 90 dart.dcall(Expect._fail, `Expect.isFalse(${actual}${msg}) fails.`); |
91 } | 91 } |
92 static isNull(actual, reason) { | 92 static isNull(actual, reason) { |
93 if (reason === void 0) | 93 if (reason === void 0) |
94 reason = null; | 94 reason = null; |
95 if (null == actual) | 95 if (null == actual) |
96 return; | 96 return; |
97 let msg = Expect._getMessage(reason); | 97 let msg = dart.dcall(Expect._getMessage, reason); |
98 Expect._fail(`Expect.isNull(actual: <${actual}>${msg}) fails.`); | 98 dart.dcall(Expect._fail, `Expect.isNull(actual: <${actual}>${msg}) fails.`
); |
99 } | 99 } |
100 static isNotNull(actual, reason) { | 100 static isNotNull(actual, reason) { |
101 if (reason === void 0) | 101 if (reason === void 0) |
102 reason = null; | 102 reason = null; |
103 if (null != actual) | 103 if (null != actual) |
104 return; | 104 return; |
105 let msg = Expect._getMessage(reason); | 105 let msg = dart.dcall(Expect._getMessage, reason); |
106 Expect._fail(`Expect.isNotNull(actual: <${actual}>${msg}) fails.`); | 106 dart.dcall(Expect._fail, `Expect.isNotNull(actual: <${actual}>${msg}) fail
s.`); |
107 } | 107 } |
108 static identical(expected, actual, reason) { | 108 static identical(expected, actual, reason) { |
109 if (reason === void 0) | 109 if (reason === void 0) |
110 reason = null; | 110 reason = null; |
111 if (dart.notNull(_identical(expected, actual))) | 111 if (dart.notNull(dart.dcall(_identical, expected, actual))) |
112 return; | 112 return; |
113 let msg = Expect._getMessage(reason); | 113 let msg = dart.dcall(Expect._getMessage, reason); |
114 Expect._fail(`Expect.identical(expected: <${expected}>, actual: <${actual}
>${msg}) ` + "fails."); | 114 dart.dcall(Expect._fail, `Expect.identical(expected: <${expected}>, actual
: <${actual}>${msg}) ` + "fails."); |
115 } | 115 } |
116 static fail(msg) { | 116 static fail(msg) { |
117 Expect._fail(`Expect.fail('${msg}')`); | 117 dart.dcall(Expect._fail, `Expect.fail('${msg}')`); |
118 } | 118 } |
119 static approxEquals(expected, actual, tolerance, reason) { | 119 static approxEquals(expected, actual, tolerance, reason) { |
120 if (tolerance === void 0) | 120 if (tolerance === void 0) |
121 tolerance = null; | 121 tolerance = null; |
122 if (reason === void 0) | 122 if (reason === void 0) |
123 reason = null; | 123 reason = null; |
124 if (tolerance == null) { | 124 if (tolerance == null) { |
125 tolerance = (dart.notNull(expected) / 10000.0)[dartx.abs](); | 125 tolerance = dart.dcall((dart.notNull(expected) / 10000.0)[dartx.abs]); |
126 } | 126 } |
127 if (dart.notNull((dart.notNull(expected) - dart.notNull(actual))[dartx.abs
]()) <= dart.notNull(tolerance)) | 127 if (dart.notNull(dart.dcall((dart.notNull(expected) - dart.notNull(actual)
)[dartx.abs])) <= dart.notNull(tolerance)) |
128 return; | 128 return; |
129 let msg = Expect._getMessage(reason); | 129 let msg = dart.dcall(Expect._getMessage, reason); |
130 Expect._fail(`Expect.approxEquals(expected:<${expected}>, actual:<${actual
}>, ` + `tolerance:<${tolerance}>${msg}) fails`); | 130 dart.dcall(Expect._fail, `Expect.approxEquals(expected:<${expected}>, actu
al:<${actual}>, ` + `tolerance:<${tolerance}>${msg}) fails`); |
131 } | 131 } |
132 static notEquals(unexpected, actual, reason) { | 132 static notEquals(unexpected, actual, reason) { |
133 if (reason === void 0) | 133 if (reason === void 0) |
134 reason = null; | 134 reason = null; |
135 if (!dart.equals(unexpected, actual)) | 135 if (!dart.equals(unexpected, actual)) |
136 return; | 136 return; |
137 let msg = Expect._getMessage(reason); | 137 let msg = dart.dcall(Expect._getMessage, reason); |
138 Expect._fail(`Expect.notEquals(unexpected: <${unexpected}>, actual:<${actu
al}>${msg}) ` + "fails."); | 138 dart.dcall(Expect._fail, `Expect.notEquals(unexpected: <${unexpected}>, ac
tual:<${actual}>${msg}) ` + "fails."); |
139 } | 139 } |
140 static listEquals(expected, actual, reason) { | 140 static listEquals(expected, actual, reason) { |
141 if (reason === void 0) | 141 if (reason === void 0) |
142 reason = null; | 142 reason = null; |
143 let msg = Expect._getMessage(reason); | 143 let msg = dart.dcall(Expect._getMessage, reason); |
144 let n = dart.notNull(expected[dartx.length]) < dart.notNull(actual[dartx.l
ength]) ? expected[dartx.length] : actual[dartx.length]; | 144 let n = dart.notNull(expected[dartx.length]) < dart.notNull(actual[dartx.l
ength]) ? expected[dartx.length] : actual[dartx.length]; |
145 for (let i = 0; dart.notNull(i) < dart.notNull(n); i = dart.notNull(i) + 1
) { | 145 for (let i = 0; dart.notNull(i) < dart.notNull(n); i = dart.notNull(i) + 1
) { |
146 if (!dart.equals(expected[dartx.get](i), actual[dartx.get](i))) { | 146 if (!dart.equals(expected[dartx.get](i), actual[dartx.get](i))) { |
147 Expect._fail(`Expect.listEquals(at index ${i}, ` + `expected: <${expec
ted[dartx.get](i)}>, actual: <${actual[dartx.get](i)}>${msg}) fails`); | 147 dart.dcall(Expect._fail, `Expect.listEquals(at index ${i}, ` + `expect
ed: <${expected[dartx.get](i)}>, actual: <${actual[dartx.get](i)}>${msg}) fails`
); |
148 } | 148 } |
149 } | 149 } |
150 if (expected[dartx.length] != actual[dartx.length]) { | 150 if (expected[dartx.length] != actual[dartx.length]) { |
151 Expect._fail('Expect.listEquals(list length, ' + `expected: <${expected[
dartx.length]}>, actual: <${actual[dartx.length]}>${msg}) ` + 'fails: Next eleme
nt <' + `${dart.notNull(expected[dartx.length]) > dart.notNull(n) ? expected[dar
tx.get](n) : actual[dartx.get](n)}>`); | 151 dart.dcall(Expect._fail, 'Expect.listEquals(list length, ' + `expected:
<${expected[dartx.length]}>, actual: <${actual[dartx.length]}>${msg}) ` + 'fails
: Next element <' + `${dart.notNull(expected[dartx.length]) > dart.notNull(n) ?
expected[dartx.get](n) : actual[dartx.get](n)}>`); |
152 } | 152 } |
153 } | 153 } |
154 static mapEquals(expected, actual, reason) { | 154 static mapEquals(expected, actual, reason) { |
155 if (reason === void 0) | 155 if (reason === void 0) |
156 reason = null; | 156 reason = null; |
157 let msg = Expect._getMessage(reason); | 157 let msg = dart.dcall(Expect._getMessage, reason); |
158 for (let key of expected.keys) { | 158 for (let key of expected.keys) { |
159 if (!dart.notNull(actual.containsKey(key))) { | 159 if (!dart.notNull(dart.dcall(actual.containsKey, key))) { |
160 Expect._fail(`Expect.mapEquals(missing expected key: <${key}>${msg}) f
ails`); | 160 dart.dcall(Expect._fail, `Expect.mapEquals(missing expected key: <${ke
y}>${msg}) fails`); |
161 } | 161 } |
162 Expect.equals(expected.get(key), actual.get(key)); | 162 dart.dcall(Expect.equals, expected.get(key), actual.get(key)); |
163 } | 163 } |
164 for (let key of actual.keys) { | 164 for (let key of actual.keys) { |
165 if (!dart.notNull(expected.containsKey(key))) { | 165 if (!dart.notNull(dart.dcall(expected.containsKey, key))) { |
166 Expect._fail(`Expect.mapEquals(unexpected key: <${key}>${msg}) fails`)
; | 166 dart.dcall(Expect._fail, `Expect.mapEquals(unexpected key: <${key}>${m
sg}) fails`); |
167 } | 167 } |
168 } | 168 } |
169 } | 169 } |
170 static stringEquals(expected, actual, reason) { | 170 static stringEquals(expected, actual, reason) { |
171 if (reason === void 0) | 171 if (reason === void 0) |
172 reason = null; | 172 reason = null; |
173 if (expected == actual) | 173 if (expected == actual) |
174 return; | 174 return; |
175 let msg = Expect._getMessage(reason); | 175 let msg = dart.dcall(Expect._getMessage, reason); |
176 let defaultMessage = `Expect.stringEquals(expected: <${expected}>", <${act
ual}>${msg}) fails`; | 176 let defaultMessage = `Expect.stringEquals(expected: <${expected}>", <${act
ual}>${msg}) fails`; |
177 if (expected == null || actual == null) { | 177 if (expected == null || actual == null) { |
178 Expect._fail(`${defaultMessage}`); | 178 dart.dcall(Expect._fail, `${defaultMessage}`); |
179 } | 179 } |
180 let left = 0; | 180 let left = 0; |
181 let right = 0; | 181 let right = 0; |
182 let eLen = expected[dartx.length]; | 182 let eLen = expected[dartx.length]; |
183 let aLen = actual[dartx.length]; | 183 let aLen = actual[dartx.length]; |
184 while (true) { | 184 while (true) { |
185 if (left == eLen || left == aLen || expected[dartx.get](left) != actual[
dartx.get](left)) { | 185 if (left == eLen || left == aLen || expected[dartx.get](left) != actual[
dartx.get](left)) { |
186 break; | 186 break; |
187 } | 187 } |
188 left = dart.notNull(left) + 1; | 188 left = dart.notNull(left) + 1; |
189 } | 189 } |
190 let eRem = dart.notNull(eLen) - dart.notNull(left); | 190 let eRem = dart.notNull(eLen) - dart.notNull(left); |
191 let aRem = dart.notNull(aLen) - dart.notNull(left); | 191 let aRem = dart.notNull(aLen) - dart.notNull(left); |
192 while (true) { | 192 while (true) { |
193 if (right == eRem || right == aRem || expected[dartx.get](dart.notNull(e
Len) - dart.notNull(right) - 1) != actual[dartx.get](dart.notNull(aLen) - dart.n
otNull(right) - 1)) { | 193 if (right == eRem || right == aRem || expected[dartx.get](dart.notNull(e
Len) - dart.notNull(right) - 1) != actual[dartx.get](dart.notNull(aLen) - dart.n
otNull(right) - 1)) { |
194 break; | 194 break; |
195 } | 195 } |
196 right = dart.notNull(right) + 1; | 196 right = dart.notNull(right) + 1; |
197 } | 197 } |
198 let leftSnippet = expected[dartx.substring](dart.notNull(left) < 10 ? 0 :
dart.notNull(left) - 10, left); | 198 let leftSnippet = dart.dcall(expected[dartx.substring], dart.notNull(left)
< 10 ? 0 : dart.notNull(left) - 10, left); |
199 let rightSnippetLength = dart.notNull(right) < 10 ? right : 10; | 199 let rightSnippetLength = dart.notNull(right) < 10 ? right : 10; |
200 let rightSnippet = expected[dartx.substring](dart.notNull(eLen) - dart.not
Null(right), dart.notNull(eLen) - dart.notNull(right) + dart.notNull(rightSnippe
tLength)); | 200 let rightSnippet = dart.dcall(expected[dartx.substring], dart.notNull(eLen
) - dart.notNull(right), dart.notNull(eLen) - dart.notNull(right) + dart.notNull
(rightSnippetLength)); |
201 let eSnippet = expected[dartx.substring](left, dart.notNull(eLen) - dart.n
otNull(right)); | 201 let eSnippet = dart.dcall(expected[dartx.substring], left, dart.notNull(eL
en) - dart.notNull(right)); |
202 let aSnippet = actual[dartx.substring](left, dart.notNull(aLen) - dart.not
Null(right)); | 202 let aSnippet = dart.dcall(actual[dartx.substring], left, dart.notNull(aLen
) - dart.notNull(right)); |
203 if (dart.notNull(eSnippet[dartx.length]) > 43) { | 203 if (dart.notNull(eSnippet[dartx.length]) > 43) { |
204 eSnippet = dart.notNull(eSnippet[dartx.substring](0, 20)) + "..." + dart
.notNull(eSnippet[dartx.substring](dart.notNull(eSnippet[dartx.length]) - 20)); | 204 eSnippet = dart.notNull(dart.dcall(eSnippet[dartx.substring], 0, 20)) +
"..." + dart.notNull(dart.dcall(eSnippet[dartx.substring], dart.notNull(eSnippet
[dartx.length]) - 20)); |
205 } | 205 } |
206 if (dart.notNull(aSnippet[dartx.length]) > 43) { | 206 if (dart.notNull(aSnippet[dartx.length]) > 43) { |
207 aSnippet = dart.notNull(aSnippet[dartx.substring](0, 20)) + "..." + dart
.notNull(aSnippet[dartx.substring](dart.notNull(aSnippet[dartx.length]) - 20)); | 207 aSnippet = dart.notNull(dart.dcall(aSnippet[dartx.substring], 0, 20)) +
"..." + dart.notNull(dart.dcall(aSnippet[dartx.substring], dart.notNull(aSnippet
[dartx.length]) - 20)); |
208 } | 208 } |
209 let leftLead = "..."; | 209 let leftLead = "..."; |
210 let rightTail = "..."; | 210 let rightTail = "..."; |
211 if (dart.notNull(left) <= 10) | 211 if (dart.notNull(left) <= 10) |
212 leftLead = ""; | 212 leftLead = ""; |
213 if (dart.notNull(right) <= 10) | 213 if (dart.notNull(right) <= 10) |
214 rightTail = ""; | 214 rightTail = ""; |
215 let diff = `\nDiff (${left}..${dart.notNull(eLen) - dart.notNull(right)}/$
{dart.notNull(aLen) - dart.notNull(right)}):\n` + `${leftLead}${leftSnippet}[ ${
eSnippet} ]${rightSnippet}${rightTail}\n` + `${leftLead}${leftSnippet}[ ${aSnipp
et} ]${rightSnippet}${rightTail}`; | 215 let diff = `\nDiff (${left}..${dart.notNull(eLen) - dart.notNull(right)}/$
{dart.notNull(aLen) - dart.notNull(right)}):\n` + `${leftLead}${leftSnippet}[ ${
eSnippet} ]${rightSnippet}${rightTail}\n` + `${leftLead}${leftSnippet}[ ${aSnipp
et} ]${rightSnippet}${rightTail}`; |
216 Expect._fail(`${defaultMessage}${diff}`); | 216 dart.dcall(Expect._fail, `${defaultMessage}${diff}`); |
217 } | 217 } |
218 static setEquals(expected, actual, reason) { | 218 static setEquals(expected, actual, reason) { |
219 if (reason === void 0) | 219 if (reason === void 0) |
220 reason = null; | 220 reason = null; |
221 let missingSet = core.Set.from(expected); | 221 let missingSet = core.Set.from(expected); |
222 missingSet.removeAll(actual); | 222 dart.dcall(missingSet.removeAll, actual); |
223 let extraSet = core.Set.from(actual); | 223 let extraSet = core.Set.from(actual); |
224 extraSet.removeAll(expected); | 224 dart.dcall(extraSet.removeAll, expected); |
225 if (dart.notNull(extraSet.isEmpty) && dart.notNull(missingSet.isEmpty)) | 225 if (dart.notNull(extraSet.isEmpty) && dart.notNull(missingSet.isEmpty)) |
226 return; | 226 return; |
227 let msg = Expect._getMessage(reason); | 227 let msg = dart.dcall(Expect._getMessage, reason); |
228 let sb = new core.StringBuffer(`Expect.setEquals(${msg}) fails`); | 228 let sb = new core.StringBuffer(`Expect.setEquals(${msg}) fails`); |
229 if (!dart.notNull(missingSet.isEmpty)) { | 229 if (!dart.notNull(missingSet.isEmpty)) { |
230 sb.write('\nExpected collection does not contain: '); | 230 dart.dcall(sb.write, '\nExpected collection does not contain: '); |
231 } | 231 } |
232 for (let val of missingSet) { | 232 for (let val of missingSet) { |
233 sb.write(`${val} `); | 233 dart.dcall(sb.write, `${val} `); |
234 } | 234 } |
235 if (!dart.notNull(extraSet.isEmpty)) { | 235 if (!dart.notNull(extraSet.isEmpty)) { |
236 sb.write('\nExpected collection should not contain: '); | 236 dart.dcall(sb.write, '\nExpected collection should not contain: '); |
237 } | 237 } |
238 for (let val of extraSet) { | 238 for (let val of extraSet) { |
239 sb.write(`${val} `); | 239 dart.dcall(sb.write, `${val} `); |
240 } | 240 } |
241 Expect._fail(dart.toString(sb)); | 241 dart.dcall(Expect._fail, dart.dcall(sb.toString)); |
242 } | 242 } |
243 static throws(f, check, reason) { | 243 static throws(f, check, reason) { |
244 if (check === void 0) | 244 if (check === void 0) |
245 check = null; | 245 check = null; |
246 if (reason === void 0) | 246 if (reason === void 0) |
247 reason = null; | 247 reason = null; |
248 let msg = reason == null ? "" : `(${reason})`; | 248 let msg = reason == null ? "" : `(${reason})`; |
249 if (!dart.is(f, _Nullary)) { | 249 if (!dart.is(f, _Nullary)) { |
250 Expect._fail(`Expect.throws${msg}: Function f not callable with zero arg
uments`); | 250 dart.dcall(Expect._fail, `Expect.throws${msg}: Function f not callable w
ith zero arguments`); |
251 } | 251 } |
252 try { | 252 try { |
253 f(); | 253 f(); |
254 } catch (e) { | 254 } catch (e) { |
255 let s = dart.stackTrace(e); | 255 let s = dart.stackTrace(e); |
256 if (check != null) { | 256 if (check != null) { |
257 if (!dart.notNull(dart.dcall(check, e))) { | 257 if (!dart.notNull(dart.dcall(check, e))) { |
258 Expect._fail(`Expect.throws${msg}: Unexpected '${e}'\n${s}`); | 258 dart.dcall(Expect._fail, `Expect.throws${msg}: Unexpected '${e}'\n${
s}`); |
259 } | 259 } |
260 } | 260 } |
261 return; | 261 return; |
262 } | 262 } |
263 | 263 |
264 Expect._fail(`Expect.throws${msg} fails: Did not throw`); | 264 dart.dcall(Expect._fail, `Expect.throws${msg} fails: Did not throw`); |
265 } | 265 } |
266 static _getMessage(reason) { | 266 static _getMessage(reason) { |
267 return reason == null ? "" : `, '${reason}'`; | 267 return reason == null ? "" : `, '${reason}'`; |
268 } | 268 } |
269 static _fail(message) { | 269 static _fail(message) { |
270 dart.throw(new ExpectException(message)); | 270 dart.throw(new ExpectException(message)); |
271 } | 271 } |
272 } | 272 } |
273 dart.setSignature(Expect, { | 273 dart.setSignature(Expect, { |
274 statics: () => ({ | 274 statics: () => ({ |
(...skipping 12 matching lines...) Expand all Loading... |
287 mapEquals: [dart.void, [core.Map, core.Map], [core.String]], | 287 mapEquals: [dart.void, [core.Map, core.Map], [core.String]], |
288 stringEquals: [dart.void, [core.String, core.String], [core.String]], | 288 stringEquals: [dart.void, [core.String, core.String], [core.String]], |
289 setEquals: [dart.void, [core.Iterable, core.Iterable], [core.String]], | 289 setEquals: [dart.void, [core.Iterable, core.Iterable], [core.String]], |
290 throws: [dart.void, [dart.functionType(dart.void, [])], [_CheckExceptionFn
, core.String]], | 290 throws: [dart.void, [dart.functionType(dart.void, [])], [_CheckExceptionFn
, core.String]], |
291 _getMessage: [core.String, [core.String]], | 291 _getMessage: [core.String, [core.String]], |
292 _fail: [dart.void, [core.String]] | 292 _fail: [dart.void, [core.String]] |
293 }), | 293 }), |
294 names: ['_truncateString', '_stringDifference', 'equals', 'isTrue', 'isFalse
', 'isNull', 'isNotNull', 'identical', 'fail', 'approxEquals', 'notEquals', 'lis
tEquals', 'mapEquals', 'stringEquals', 'setEquals', 'throws', '_getMessage', '_f
ail'] | 294 names: ['_truncateString', '_stringDifference', 'equals', 'isTrue', 'isFalse
', 'isNull', 'isNotNull', 'identical', 'fail', 'approxEquals', 'notEquals', 'lis
tEquals', 'mapEquals', 'stringEquals', 'setEquals', 'throws', '_getMessage', '_f
ail'] |
295 }); | 295 }); |
296 function _identical(a, b) { | 296 function _identical(a, b) { |
297 return core.identical(a, b); | 297 return dart.dcall(core.identical, a, b); |
298 } | 298 } |
299 dart.fn(_identical, core.bool, [dart.dynamic, dart.dynamic]); | 299 dart.fn(_identical, core.bool, [dart.dynamic, dart.dynamic]); |
300 let _CheckExceptionFn = dart.typedef('_CheckExceptionFn', () => dart.functionT
ype(core.bool, [dart.dynamic])); | 300 let _CheckExceptionFn = dart.typedef('_CheckExceptionFn', () => dart.functionT
ype(core.bool, [dart.dynamic])); |
301 let _Nullary = dart.typedef('_Nullary', () => dart.functionType(dart.dynamic,
[])); | 301 let _Nullary = dart.typedef('_Nullary', () => dart.functionType(dart.dynamic,
[])); |
302 class ExpectException extends core.Object { | 302 class ExpectException extends core.Object { |
303 ExpectException(message) { | 303 ExpectException(message) { |
304 this.message = message; | 304 this.message = message; |
305 } | 305 } |
306 toString() { | 306 toString() { |
307 return this.message; | 307 return this.message; |
(...skipping 24 matching lines...) Expand all Loading... |
332 dart.setSignature(AssumeDynamic, { | 332 dart.setSignature(AssumeDynamic, { |
333 constructors: () => ({AssumeDynamic: [AssumeDynamic, []]}) | 333 constructors: () => ({AssumeDynamic: [AssumeDynamic, []]}) |
334 }); | 334 }); |
335 // Exports: | 335 // Exports: |
336 exports.Expect = Expect; | 336 exports.Expect = Expect; |
337 exports.ExpectException = ExpectException; | 337 exports.ExpectException = ExpectException; |
338 exports.NoInline = NoInline; | 338 exports.NoInline = NoInline; |
339 exports.TrustTypeAnnotations = TrustTypeAnnotations; | 339 exports.TrustTypeAnnotations = TrustTypeAnnotations; |
340 exports.AssumeDynamic = AssumeDynamic; | 340 exports.AssumeDynamic = AssumeDynamic; |
341 }); | 341 }); |
OLD | NEW |