(msg, f, expect)
| 15 | } |
| 16 | |
| 17 | function asmAssert(msg, f, expect) { |
| 18 | f = explode(f); |
| 19 | var hasOwn = {}.hasOwnProperty; |
| 20 | |
| 21 | if (expect.pass) { |
| 22 | return function(test) { |
| 23 | var report; |
| 24 | test.doesNotThrow(function() { report = validate(f); }, "validation threw"); |
| 25 | try { |
| 26 | if (!report) |
| 27 | return; |
| 28 | var types = expect.types, |
| 29 | singleExport = expect.export, |
| 30 | exports = expect.exports; |
| 31 | if (types) { |
| 32 | for (var key in types) { |
| 33 | if (!hasOwn.call(types, key)) |
| 34 | continue; |
| 35 | var expectedType = types[key], |
| 36 | actualType = report.getFunction(key); |
| 37 | test.ok(actualType, msg + ": function " + key + " not found"); |
| 38 | test.ok(actualType.equals(expectedType), msg + ": " + key + " : " + actualType + ", expected " + expectedType); |
| 39 | } |
| 40 | } |
| 41 | if (singleExport) { |
| 42 | test.ok(report.isSingleExport(), msg + ": expected single export, got multiple"); |
| 43 | var actualExport = report.getExport(); |
| 44 | test.equal(actualExport, singleExport, msg + ": expected single export " + singleExport + ", got " + actualExport); |
| 45 | } |
| 46 | if (exports) { |
| 47 | for (var key in exports) { |
| 48 | if (!hasOwn.call(exports, key)) |
| 49 | continue; |
| 50 | var actualExport = report.getExport(key); |
| 51 | test.ok(actualExport, msg + ": function " + key + " not found"); |
| 52 | test.equal(actualExport, exports[key], msg + ": expected export " + key + " to map to " + exports[key] + ", got " + actualExport); |
| 53 | } |
| 54 | } |
| 55 | } catch (e) { |
| 56 | test.ok(false, msg + ": validation failed: " + e); |
| 57 | } finally { |
| 58 | test.done(); |
| 59 | } |
| 60 | } |
| 61 | } else { |
| 62 | return function(test) { |
| 63 | test.throws(function() { validate(f); }, |
| 64 | function(e) { |
| 65 | return e instanceof ValidationError; |
| 66 | }, |
| 67 | msg + ": should fail to validate"); |
| 68 | test.done(); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | asmAssert.one = function(msg, f, expect) { |
| 74 | return asmAssert(msg, |
no test coverage detected