(expected, found)
| 44 | } |
| 45 | |
| 46 | static buildMessage(expected, found) { |
| 47 | function hex(ch) { |
| 48 | return ch.codePointAt(0).toString(16).toUpperCase(); |
| 49 | } |
| 50 | |
| 51 | const nonPrintable = Object.prototype.hasOwnProperty.call(RegExp.prototype, "unicode") |
| 52 | ? new RegExp("[\\p{C}\\p{Mn}\\p{Mc}]", "gu") |
| 53 | : null; |
| 54 | function unicodeEscape(s) { |
| 55 | if (nonPrintable) { |
| 56 | return s.replace(nonPrintable, ch => "\\u{" + hex(ch) + "}"); |
| 57 | } |
| 58 | return s; |
| 59 | } |
| 60 | |
| 61 | function literalEscape(s) { |
| 62 | return unicodeEscape(s |
| 63 | .replace(/\\/g, "\\\\") |
| 64 | .replace(/"/g, "\\\"") |
| 65 | .replace(/\0/g, "\\0") |
| 66 | .replace(/\t/g, "\\t") |
| 67 | .replace(/\n/g, "\\n") |
| 68 | .replace(/\r/g, "\\r") |
| 69 | .replace(/[\x00-\x0F]/g, ch => "\\x0" + hex(ch)) |
| 70 | .replace(/[\x10-\x1F\x7F-\x9F]/g, ch => "\\x" + hex(ch))); |
| 71 | } |
| 72 | |
| 73 | function classEscape(s) { |
| 74 | return unicodeEscape(s |
| 75 | .replace(/\\/g, "\\\\") |
| 76 | .replace(/\]/g, "\\]") |
| 77 | .replace(/\^/g, "\\^") |
| 78 | .replace(/-/g, "\\-") |
| 79 | .replace(/\0/g, "\\0") |
| 80 | .replace(/\t/g, "\\t") |
| 81 | .replace(/\n/g, "\\n") |
| 82 | .replace(/\r/g, "\\r") |
| 83 | .replace(/[\x00-\x0F]/g, ch => "\\x0" + hex(ch)) |
| 84 | .replace(/[\x10-\x1F\x7F-\x9F]/g, ch => "\\x" + hex(ch))); |
| 85 | } |
| 86 | |
| 87 | const DESCRIBE_EXPECTATION_FNS = { |
| 88 | literal(expectation) { |
| 89 | return "\"" + literalEscape(expectation.text) + "\""; |
| 90 | }, |
| 91 | |
| 92 | class(expectation) { |
| 93 | const escapedParts = expectation.parts.map( |
| 94 | part => (Array.isArray(part) |
| 95 | ? classEscape(part[0]) + "-" + classEscape(part[1]) |
| 96 | : classEscape(part)) |
| 97 | ); |
| 98 | |
| 99 | return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]" + (expectation.unicode ? "u" : ""); |
| 100 | }, |
| 101 | |
| 102 | any() { |
| 103 | return "any character"; |
no outgoing calls
no test coverage detected