| 820 | }; |
| 821 | |
| 822 | function internalMatch(string, regexp, message, fn) { |
| 823 | if (!isRegExp(regexp)) { |
| 824 | throw new ERR_INVALID_ARG_TYPE( |
| 825 | 'regexp', 'RegExp', regexp, |
| 826 | ); |
| 827 | } |
| 828 | const match = fn === Assert.prototype.match; |
| 829 | if (typeof string !== 'string' || |
| 830 | RegExpPrototypeExec(regexp, string) !== null !== match) { |
| 831 | |
| 832 | const generatedMessage = message.length === 0; |
| 833 | |
| 834 | // 'The input was expected to not match the regular expression ' + |
| 835 | message[0] ||= (typeof string !== 'string' ? |
| 836 | 'The "string" argument must be of type string. Received type ' + |
| 837 | `${typeof string} (${inspect(string)})` : |
| 838 | (match ? |
| 839 | 'The input did not match the regular expression ' : |
| 840 | 'The input was expected to not match the regular expression ') + |
| 841 | `${inspect(regexp)}. Input:\n\n${inspect(string)}\n`); |
| 842 | innerFail({ |
| 843 | actual: string, |
| 844 | expected: regexp, |
| 845 | message, |
| 846 | operator: fn.name, |
| 847 | stackStartFn: fn, |
| 848 | diff: this?.[kOptions]?.diff, |
| 849 | generatedMessage: generatedMessage, |
| 850 | }); |
| 851 | } |
| 852 | } |
| 853 | |
| 854 | /** |
| 855 | * Expects the `string` input to match the regular expression. |