|
| 1 | +// Currently in sync with Node.js test/parallel/test-assert.js |
| 2 | +// https://github.com/nodejs/node/commit/2a871df3dfb8ea663ef5e1f8f62701ec51384ecb |
| 3 | + |
| 4 | +'use strict'; |
| 5 | + |
| 6 | +require('../common'); |
| 7 | +const assert = require('assert'); |
| 8 | + |
| 9 | +// Multiple assert.match() tests. |
| 10 | +{ |
| 11 | + assert.throws( |
| 12 | + () => assert.match(/abc/, 'string'), |
| 13 | + { |
| 14 | + code: 'ERR_INVALID_ARG_TYPE', |
| 15 | + message: 'The "regexp" argument must be an instance of RegExp. ' + |
| 16 | + "Received type string ('string')" |
| 17 | + } |
| 18 | + ); |
| 19 | + assert.throws( |
| 20 | + () => assert.match('string', /abc/), |
| 21 | + { |
| 22 | + actual: 'string', |
| 23 | + expected: /abc/, |
| 24 | + operator: 'match', |
| 25 | + message: 'The input did not match the regular expression /abc/. ' + |
| 26 | + "Input:\n\n'string'\n", |
| 27 | + generatedMessage: true |
| 28 | + } |
| 29 | + ); |
| 30 | + assert.throws( |
| 31 | + () => assert.match('string', /abc/, 'foobar'), |
| 32 | + { |
| 33 | + actual: 'string', |
| 34 | + expected: /abc/, |
| 35 | + operator: 'match', |
| 36 | + message: 'foobar', |
| 37 | + generatedMessage: false |
| 38 | + } |
| 39 | + ); |
| 40 | + const errorMessage = new RangeError('foobar'); |
| 41 | + assert.throws( |
| 42 | + () => assert.match('string', /abc/, errorMessage), |
| 43 | + errorMessage |
| 44 | + ); |
| 45 | + assert.throws( |
| 46 | + () => assert.match({ abc: 123 }, /abc/), |
| 47 | + { |
| 48 | + actual: { abc: 123 }, |
| 49 | + expected: /abc/, |
| 50 | + operator: 'match', |
| 51 | + message: 'The "string" argument must be of type string. ' + |
| 52 | + 'Received type object ({ abc: 123 })', |
| 53 | + generatedMessage: true |
| 54 | + } |
| 55 | + ); |
| 56 | + assert.match('I will pass', /pass$/); |
| 57 | +} |
| 58 | + |
| 59 | +// Multiple assert.doesNotMatch() tests. |
| 60 | +{ |
| 61 | + assert.throws( |
| 62 | + () => assert.doesNotMatch(/abc/, 'string'), |
| 63 | + { |
| 64 | + code: 'ERR_INVALID_ARG_TYPE', |
| 65 | + message: 'The "regexp" argument must be an instance of RegExp. ' + |
| 66 | + "Received type string ('string')" |
| 67 | + } |
| 68 | + ); |
| 69 | + assert.throws( |
| 70 | + () => assert.doesNotMatch('string', /string/), |
| 71 | + { |
| 72 | + actual: 'string', |
| 73 | + expected: /string/, |
| 74 | + operator: 'doesNotMatch', |
| 75 | + message: 'The input was expected to not match the regular expression ' + |
| 76 | + "/string/. Input:\n\n'string'\n", |
| 77 | + generatedMessage: true |
| 78 | + } |
| 79 | + ); |
| 80 | + assert.throws( |
| 81 | + () => assert.doesNotMatch('string', /string/, 'foobar'), |
| 82 | + { |
| 83 | + actual: 'string', |
| 84 | + expected: /string/, |
| 85 | + operator: 'doesNotMatch', |
| 86 | + message: 'foobar', |
| 87 | + generatedMessage: false |
| 88 | + } |
| 89 | + ); |
| 90 | + const errorMessage = new RangeError('foobar'); |
| 91 | + assert.throws( |
| 92 | + () => assert.doesNotMatch('string', /string/, errorMessage), |
| 93 | + errorMessage |
| 94 | + ); |
| 95 | + assert.throws( |
| 96 | + () => assert.doesNotMatch({ abc: 123 }, /abc/), |
| 97 | + { |
| 98 | + actual: { abc: 123 }, |
| 99 | + expected: /abc/, |
| 100 | + operator: 'doesNotMatch', |
| 101 | + message: 'The "string" argument must be of type string. ' + |
| 102 | + 'Received type object ({ abc: 123 })', |
| 103 | + generatedMessage: true |
| 104 | + } |
| 105 | + ); |
| 106 | + assert.doesNotMatch('I will pass', /different$/); |
| 107 | +} |
0 commit comments