| OLD | NEW |
| 1 dart_library.library('unittest', null, /* Imports */[ | 1 dart_library.library('unittest', null, /* Imports */[ |
| 2 "dart/_runtime", | 2 "dart/_runtime", |
| 3 'matcher/matcher', | 3 'matcher/matcher', |
| 4 'dom/dom', | 4 'dom/dom', |
| 5 'dart/core', | 5 'dart/core', |
| 6 'dart/async', | 6 'dart/async', |
| 7 'matcher/src/interfaces', | 7 'matcher/src/interfaces', |
| 8 'matcher/src/util', | 8 'matcher/src/util', |
| 9 'matcher/src/description' | 9 'matcher/src/description' |
| 10 ], /* Lazy imports */[ | 10 ], /* Lazy imports */[ |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 constructors: () => ({TestFailure: [TestFailure, [core.String]]}) | 47 constructors: () => ({TestFailure: [TestFailure, [core.String]]}) |
| 48 }); | 48 }); |
| 49 const ErrorFormatter = dart.typedef('ErrorFormatter', () => dart.functionType(
core.String, [dart.dynamic, interfaces.Matcher, core.String, core.Map, core.bool
])); | 49 const ErrorFormatter = dart.typedef('ErrorFormatter', () => dart.functionType(
core.String, [dart.dynamic, interfaces.Matcher, core.String, core.Map, core.bool
])); |
| 50 function expect(actual, matcher, opts) { | 50 function expect(actual, matcher, opts) { |
| 51 let reason = opts && 'reason' in opts ? opts.reason : null; | 51 let reason = opts && 'reason' in opts ? opts.reason : null; |
| 52 let verbose = opts && 'verbose' in opts ? opts.verbose : false; | 52 let verbose = opts && 'verbose' in opts ? opts.verbose : false; |
| 53 let formatter = opts && 'formatter' in opts ? opts.formatter : null; | 53 let formatter = opts && 'formatter' in opts ? opts.formatter : null; |
| 54 matcher = util.wrapMatcher(matcher); | 54 matcher = util.wrapMatcher(matcher); |
| 55 let matchState = dart.map(); | 55 let matchState = dart.map(); |
| 56 try { | 56 try { |
| 57 if (dart.notNull(dart.as(dart.dsend(matcher, 'matches', actual, matchState
), core.bool))) | 57 if (dart.notNull(dart.as(dart.dsend(matcher, 'matches', actual, matchState
), core.bool))) return; |
| 58 return; | |
| 59 } catch (e) { | 58 } catch (e) { |
| 60 let trace = dart.stackTrace(e); | 59 let trace = dart.stackTrace(e); |
| 61 if (reason == null) { | 60 if (reason == null) { |
| 62 reason = `${typeof e == 'string' ? e : dart.toString(e)} at ${trace}`; | 61 reason = `${typeof e == 'string' ? e : dart.toString(e)} at ${trace}`; |
| 63 } | 62 } |
| 64 } | 63 } |
| 65 | 64 |
| 66 if (formatter == null) | 65 if (formatter == null) formatter = _defaultFailFormatter; |
| 67 formatter = _defaultFailFormatter; | |
| 68 fail(dart.dcall(formatter, actual, matcher, reason, matchState, verbose)); | 66 fail(dart.dcall(formatter, actual, matcher, reason, matchState, verbose)); |
| 69 } | 67 } |
| 70 dart.fn(expect, dart.void, [dart.dynamic, dart.dynamic], {reason: core.String,
verbose: core.bool, formatter: ErrorFormatter}); | 68 dart.fn(expect, dart.void, [dart.dynamic, dart.dynamic], {reason: core.String,
verbose: core.bool, formatter: ErrorFormatter}); |
| 71 function fail(message) { | 69 function fail(message) { |
| 72 return dart.throw(new TestFailure(message)); | 70 return dart.throw(new TestFailure(message)); |
| 73 } | 71 } |
| 74 dart.fn(fail, dart.void, [core.String]); | 72 dart.fn(fail, dart.void, [core.String]); |
| 75 function _defaultFailFormatter(actual, matcher, reason, matchState, verbose) { | 73 function _defaultFailFormatter(actual, matcher, reason, matchState, verbose) { |
| 76 let description = new description$.StringDescription(); | 74 let description = new description$.StringDescription(); |
| 77 description.add('Expected: ').addDescriptionOf(matcher).add('\n'); | 75 description.add('Expected: ').addDescriptionOf(matcher).add('\n'); |
| 78 description.add(' Actual: ').addDescriptionOf(actual).add('\n'); | 76 description.add(' Actual: ').addDescriptionOf(actual).add('\n'); |
| 79 let mismatchDescription = new description$.StringDescription(); | 77 let mismatchDescription = new description$.StringDescription(); |
| 80 matcher.describeMismatch(actual, mismatchDescription, matchState, verbose); | 78 matcher.describeMismatch(actual, mismatchDescription, matchState, verbose); |
| 81 if (dart.notNull(mismatchDescription.length) > 0) { | 79 if (dart.notNull(mismatchDescription.length) > 0) { |
| 82 description.add(` Which: ${mismatchDescription}\n`); | 80 description.add(` Which: ${mismatchDescription}\n`); |
| 83 } | 81 } |
| 84 if (reason != null) | 82 if (reason != null) description.add(reason).add('\n'); |
| 85 description.add(reason).add('\n'); | |
| 86 return dart.toString(description); | 83 return dart.toString(description); |
| 87 } | 84 } |
| 88 dart.fn(_defaultFailFormatter, core.String, [dart.dynamic, interfaces.Matcher,
core.String, core.Map, core.bool]); | 85 dart.fn(_defaultFailFormatter, core.String, [dart.dynamic, interfaces.Matcher,
core.String, core.Map, core.bool]); |
| 89 // Exports: | 86 // Exports: |
| 90 exports.group = group; | 87 exports.group = group; |
| 91 exports.test = test; | 88 exports.test = test; |
| 92 exports.TestFailure = TestFailure; | 89 exports.TestFailure = TestFailure; |
| 93 exports.ErrorFormatter = ErrorFormatter; | 90 exports.ErrorFormatter = ErrorFormatter; |
| 94 exports.expect = expect; | 91 exports.expect = expect; |
| 95 exports.fail = fail; | 92 exports.fail = fail; |
| 96 }); | 93 }); |
| OLD | NEW |