| OLD | NEW |
| (Empty) |
| 1 dart_library.library('unittest', null, /* Imports */[ | |
| 2 'dart_sdk', | |
| 3 'matcher' | |
| 4 ], function(exports, dart_sdk, matcher) { | |
| 5 'use strict'; | |
| 6 const core = dart_sdk.core; | |
| 7 const async = dart_sdk.async; | |
| 8 const js = dart_sdk.js; | |
| 9 const dart = dart_sdk.dart; | |
| 10 const dartx = dart_sdk.dartx; | |
| 11 const src__util = matcher.src__util; | |
| 12 const src__interfaces = matcher.src__interfaces; | |
| 13 const src__description = matcher.src__description; | |
| 14 const src__numeric_matchers = matcher.src__numeric_matchers; | |
| 15 const src__error_matchers = matcher.src__error_matchers; | |
| 16 const src__core_matchers = matcher.src__core_matchers; | |
| 17 const src__iterable_matchers = matcher.src__iterable_matchers; | |
| 18 const src__string_matchers = matcher.src__string_matchers; | |
| 19 const src__operator_matchers = matcher.src__operator_matchers; | |
| 20 const src__map_matchers = matcher.src__map_matchers; | |
| 21 const unittest = Object.create(null); | |
| 22 dart.defineLazy(unittest, { | |
| 23 get _wrapAsync() { | |
| 24 return dart.fn((f, id) => { | |
| 25 if (id === void 0) id = null; | |
| 26 return f; | |
| 27 }, core.Function, [core.Function], [dart.dynamic]); | |
| 28 }, | |
| 29 set _wrapAsync(_) {} | |
| 30 }); | |
| 31 const _matcher = Symbol('_matcher'); | |
| 32 unittest.Throws = class Throws extends src__interfaces.Matcher { | |
| 33 Throws(matcher) { | |
| 34 if (matcher === void 0) matcher = null; | |
| 35 this[_matcher] = matcher; | |
| 36 super.Matcher(); | |
| 37 } | |
| 38 matches(item, matchState) { | |
| 39 if (!dart.is(item, core.Function) && !dart.is(item, async.Future)) return
false; | |
| 40 if (dart.is(item, async.Future)) { | |
| 41 let done = dart.dcall(unittest._wrapAsync, dart.fn(fn => dart.dcall(fn))
); | |
| 42 item.then(dart.dynamic)(dart.fn(value => { | |
| 43 dart.dcall(done, dart.fn(() => { | |
| 44 unittest.fail(`Expected future to fail, but succeeded with '${value}
'.`); | |
| 45 })); | |
| 46 }), {onError: dart.fn((error, trace) => { | |
| 47 dart.dcall(done, dart.fn(() => { | |
| 48 if (this[_matcher] == null) return; | |
| 49 let reason = null; | |
| 50 if (trace != null) { | |
| 51 let stackTrace = dart.toString(trace); | |
| 52 stackTrace = ` ${stackTrace[dartx.replaceAll]("\n", "\n ")}`; | |
| 53 reason = `Actual exception trace:\n${stackTrace}`; | |
| 54 } | |
| 55 unittest.expect(error, this[_matcher], {reason: dart.as(reason, co
re.String)}); | |
| 56 })); | |
| 57 })}); | |
| 58 return true; | |
| 59 } | |
| 60 try { | |
| 61 dart.dcall(item); | |
| 62 return false; | |
| 63 } catch (e) { | |
| 64 let s = dart.stackTrace(e); | |
| 65 if (this[_matcher] == null || dart.notNull(this[_matcher].matches(e, mat
chState))) { | |
| 66 return true; | |
| 67 } else { | |
| 68 src__util.addStateInfo(matchState, dart.map({exception: e, stack: s}))
; | |
| 69 return false; | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 } | |
| 74 describe(description) { | |
| 75 if (this[_matcher] == null) { | |
| 76 return description.add("throws"); | |
| 77 } else { | |
| 78 return description.add('throws ').addDescriptionOf(this[_matcher]); | |
| 79 } | |
| 80 } | |
| 81 describeMismatch(item, mismatchDescription, matchState, verbose) { | |
| 82 if (!dart.is(item, core.Function) && !dart.is(item, async.Future)) { | |
| 83 return mismatchDescription.add('is not a Function or Future'); | |
| 84 } else if (this[_matcher] == null || matchState[dartx.get]('exception') ==
null) { | |
| 85 return mismatchDescription.add('did not throw'); | |
| 86 } else { | |
| 87 mismatchDescription.add('threw ').addDescriptionOf(matchState[dartx.get]
('exception')); | |
| 88 if (dart.notNull(verbose)) { | |
| 89 mismatchDescription.add(' at ').add(dart.toString(matchState[dartx.get
]('stack'))); | |
| 90 } | |
| 91 return mismatchDescription; | |
| 92 } | |
| 93 } | |
| 94 }; | |
| 95 dart.setSignature(unittest.Throws, { | |
| 96 constructors: () => ({Throws: [unittest.Throws, [], [src__interfaces.Matcher
]]}), | |
| 97 methods: () => ({ | |
| 98 matches: [core.bool, [dart.dynamic, core.Map]], | |
| 99 describe: [src__interfaces.Description, [src__interfaces.Description]] | |
| 100 }) | |
| 101 }); | |
| 102 unittest.throws = dart.const(new unittest.Throws()); | |
| 103 unittest.throwsA = function(matcher) { | |
| 104 return new unittest.Throws(src__util.wrapMatcher(matcher)); | |
| 105 }; | |
| 106 dart.fn(unittest.throwsA, src__interfaces.Matcher, [dart.dynamic]); | |
| 107 unittest.group = function(name, body) { | |
| 108 return js.context.callMethod('suite', dart.list([name, body], core.Object)); | |
| 109 }; | |
| 110 dart.fn(unittest.group, dart.void, [core.String, dart.functionType(dart.void,
[])]); | |
| 111 unittest.test = function(name, body, opts) { | |
| 112 let skip = opts && 'skip' in opts ? opts.skip : null; | |
| 113 if (skip != null) { | |
| 114 core.print(`SKIP ${name}: ${skip}`); | |
| 115 return; | |
| 116 } | |
| 117 let result = dart.as(js.context.callMethod('test', dart.list([name, dart.fn(
done => { | |
| 118 function _finishTest(f) { | |
| 119 if (dart.is(f, async.Future)) { | |
| 120 f.then(dart.dynamic)(_finishTest); | |
| 121 } else { | |
| 122 done.apply([]); | |
| 123 } | |
| 124 } | |
| 125 dart.fn(_finishTest); | |
| 126 _finishTest(body()); | |
| 127 }, dart.dynamic, [js.JsFunction])], core.Object)), js.JsObject); | |
| 128 result.set('async', 1); | |
| 129 }; | |
| 130 dart.fn(unittest.test, dart.void, [core.String, dart.functionType(dart.dynamic
, [])], {skip: core.String}); | |
| 131 unittest.TestFailure = class TestFailure extends core.Object { | |
| 132 TestFailure(message) { | |
| 133 this.message = message; | |
| 134 } | |
| 135 toString() { | |
| 136 return this.message; | |
| 137 } | |
| 138 }; | |
| 139 dart.setSignature(unittest.TestFailure, { | |
| 140 constructors: () => ({TestFailure: [unittest.TestFailure, [core.String]]}) | |
| 141 }); | |
| 142 unittest.TestCase = class TestCase extends core.Object { | |
| 143 get isComplete() { | |
| 144 return !dart.notNull(this.enabled) || this.result != null; | |
| 145 } | |
| 146 }; | |
| 147 unittest.ErrorFormatter = dart.typedef('ErrorFormatter', () => dart.functionTy
pe(core.String, [dart.dynamic, src__interfaces.Matcher, core.String, core.Map, c
ore.bool])); | |
| 148 unittest.expect = function(actual, matcher, opts) { | |
| 149 let reason = opts && 'reason' in opts ? opts.reason : null; | |
| 150 let verbose = opts && 'verbose' in opts ? opts.verbose : false; | |
| 151 let formatter = opts && 'formatter' in opts ? opts.formatter : null; | |
| 152 matcher = src__util.wrapMatcher(matcher); | |
| 153 let matchState = dart.map(); | |
| 154 try { | |
| 155 if (dart.notNull(dart.as(dart.dsend(matcher, 'matches', actual, matchState
), core.bool))) return; | |
| 156 } catch (e) { | |
| 157 let trace = dart.stackTrace(e); | |
| 158 if (reason == null) { | |
| 159 reason = `${typeof e == 'string' ? e : dart.toString(e)} at ${trace}`; | |
| 160 } | |
| 161 } | |
| 162 | |
| 163 if (formatter == null) formatter = unittest._defaultFailFormatter; | |
| 164 unittest.fail(dart.dcall(formatter, actual, matcher, reason, matchState, ver
bose)); | |
| 165 }; | |
| 166 dart.fn(unittest.expect, dart.void, [dart.dynamic, dart.dynamic], {reason: cor
e.String, verbose: core.bool, formatter: unittest.ErrorFormatter}); | |
| 167 unittest.fail = function(message) { | |
| 168 return dart.throw(new unittest.TestFailure(message)); | |
| 169 }; | |
| 170 dart.fn(unittest.fail, dart.void, [core.String]); | |
| 171 unittest._defaultFailFormatter = function(actual, matcher, reason, matchState,
verbose) { | |
| 172 let description = new src__description.StringDescription(); | |
| 173 description.add('Expected: ').addDescriptionOf(matcher).add('\n'); | |
| 174 description.add(' Actual: ').addDescriptionOf(actual).add('\n'); | |
| 175 let mismatchDescription = new src__description.StringDescription(); | |
| 176 matcher.describeMismatch(actual, mismatchDescription, matchState, verbose); | |
| 177 if (dart.notNull(mismatchDescription.length) > 0) { | |
| 178 description.add(` Which: ${mismatchDescription}\n`); | |
| 179 } | |
| 180 if (reason != null) description.add(reason).add('\n'); | |
| 181 return description.toString(); | |
| 182 }; | |
| 183 dart.fn(unittest._defaultFailFormatter, core.String, [dart.dynamic, src__inter
faces.Matcher, core.String, core.Map, core.bool]); | |
| 184 unittest.useHtmlConfiguration = function(isLayoutTest) { | |
| 185 if (isLayoutTest === void 0) isLayoutTest = false; | |
| 186 }; | |
| 187 dart.fn(unittest.useHtmlConfiguration, dart.void, [], [core.bool]); | |
| 188 dart.export(unittest, src__numeric_matchers, 'isPositive'); | |
| 189 dart.export(unittest, src__error_matchers, 'isRangeError'); | |
| 190 dart.export(unittest, src__error_matchers, 'isStateError'); | |
| 191 unittest.equals = src__core_matchers.equals; | |
| 192 unittest.CustomMatcher = src__core_matchers.CustomMatcher; | |
| 193 unittest.inOpenClosedRange = src__numeric_matchers.inOpenClosedRange; | |
| 194 unittest.pairwiseCompare = src__iterable_matchers.pairwiseCompare; | |
| 195 unittest.equalsIgnoringCase = src__string_matchers.equalsIgnoringCase; | |
| 196 dart.export(unittest, src__error_matchers, 'isUnimplementedError'); | |
| 197 unittest.hasLength = src__core_matchers.hasLength; | |
| 198 unittest.StringDescription = src__description.StringDescription; | |
| 199 unittest.allOf = src__operator_matchers.allOf; | |
| 200 dart.export(unittest, src__numeric_matchers, 'isNegative'); | |
| 201 unittest.isInstanceOf$ = src__core_matchers.isInstanceOf$; | |
| 202 unittest.isInstanceOf = src__core_matchers.isInstanceOf; | |
| 203 dart.export(unittest, src__core_matchers, 'isNaN'); | |
| 204 unittest.lessThan = src__numeric_matchers.lessThan; | |
| 205 dart.export(unittest, src__core_matchers, 'isNotEmpty'); | |
| 206 unittest.greaterThanOrEqualTo = src__numeric_matchers.greaterThanOrEqualTo; | |
| 207 unittest.endsWith = src__string_matchers.endsWith; | |
| 208 dart.export(unittest, src__error_matchers, 'isConcurrentModificationError'); | |
| 209 unittest.containsValue = src__map_matchers.containsValue; | |
| 210 dart.export(unittest, src__core_matchers, 'isFalse'); | |
| 211 dart.export(unittest, src__core_matchers, 'isTrue'); | |
| 212 unittest.Matcher = src__interfaces.Matcher; | |
| 213 unittest.lessThanOrEqualTo = src__numeric_matchers.lessThanOrEqualTo; | |
| 214 unittest.matches = src__string_matchers.matches; | |
| 215 dart.export(unittest, src__core_matchers, 'returnsNormally'); | |
| 216 unittest.TypeMatcher = src__core_matchers.TypeMatcher; | |
| 217 unittest.inExclusiveRange = src__numeric_matchers.inExclusiveRange; | |
| 218 unittest.equalsIgnoringWhitespace = src__string_matchers.equalsIgnoringWhitesp
ace; | |
| 219 unittest.isIn = src__core_matchers.isIn; | |
| 220 dart.export(unittest, src__core_matchers, 'isNotNaN'); | |
| 221 dart.export(unittest, src__numeric_matchers, 'isNonZero'); | |
| 222 unittest.startsWith = src__string_matchers.startsWith; | |
| 223 dart.export(unittest, src__error_matchers, 'isNullThrownError'); | |
| 224 dart.export(unittest, src__core_matchers, 'isEmpty'); | |
| 225 unittest.anyOf = src__operator_matchers.anyOf; | |
| 226 unittest.unorderedMatches = src__iterable_matchers.unorderedMatches; | |
| 227 dart.export(unittest, src__numeric_matchers, 'isZero'); | |
| 228 dart.export(unittest, src__core_matchers, 'isList'); | |
| 229 unittest.escape = src__util.escape; | |
| 230 dart.export(unittest, src__error_matchers, 'isCyclicInitializationError'); | |
| 231 unittest.anyElement = src__iterable_matchers.anyElement; | |
| 232 dart.export(unittest, src__core_matchers, 'anything'); | |
| 233 unittest.contains = src__core_matchers.contains; | |
| 234 dart.export(unittest, src__error_matchers, 'isUnsupportedError'); | |
| 235 dart.export(unittest, src__numeric_matchers, 'isNonPositive'); | |
| 236 unittest.isNot = src__operator_matchers.isNot; | |
| 237 unittest.same = src__core_matchers.same; | |
| 238 unittest.inClosedOpenRange = src__numeric_matchers.inClosedOpenRange; | |
| 239 unittest.predicate = src__core_matchers.predicate; | |
| 240 dart.export(unittest, src__core_matchers, 'isNotNull'); | |
| 241 unittest.wrapMatcher = src__util.wrapMatcher; | |
| 242 dart.export(unittest, src__error_matchers, 'isNoSuchMethodError'); | |
| 243 unittest.unorderedEquals = src__iterable_matchers.unorderedEquals; | |
| 244 unittest.everyElement = src__iterable_matchers.everyElement; | |
| 245 unittest.addStateInfo = src__util.addStateInfo; | |
| 246 dart.export(unittest, src__error_matchers, 'isArgumentError'); | |
| 247 dart.export(unittest, src__error_matchers, 'isException'); | |
| 248 unittest.inInclusiveRange = src__numeric_matchers.inInclusiveRange; | |
| 249 unittest.containsPair = src__map_matchers.containsPair; | |
| 250 dart.export(unittest, src__error_matchers, 'isFormatException'); | |
| 251 unittest.orderedEquals = src__iterable_matchers.orderedEquals; | |
| 252 unittest.collapseWhitespace = src__string_matchers.collapseWhitespace; | |
| 253 unittest.greaterThan = src__numeric_matchers.greaterThan; | |
| 254 dart.export(unittest, src__numeric_matchers, 'isNonNegative'); | |
| 255 dart.export(unittest, src__core_matchers, 'isNull'); | |
| 256 dart.export(unittest, src__core_matchers, 'isMap'); | |
| 257 unittest.stringContainsInOrder = src__string_matchers.stringContainsInOrder; | |
| 258 unittest.closeTo = src__numeric_matchers.closeTo; | |
| 259 unittest.Description = src__interfaces.Description; | |
| 260 // Exports: | |
| 261 exports.unittest = unittest; | |
| 262 }); | |
| OLD | NEW |