|
| 1 | +import test from '../testFunctions'; |
| 2 | + |
| 3 | +describe('isLength', () => { |
| 4 | + it('should return false for a string with length greater than the max', () => { |
| 5 | + test({ |
| 6 | + validator: 'isLength', |
| 7 | + args: [{ max: 3 }], |
| 8 | + invalid: ['test'], |
| 9 | + }); |
| 10 | + }); |
| 11 | + |
| 12 | + it('should return true for a string with length equal to the max', () => { |
| 13 | + test({ |
| 14 | + validator: 'isLength', |
| 15 | + args: [{ max: 4 }], |
| 16 | + valid: ['test'], |
| 17 | + }); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should correctly calculate the length of a string with presentation sequences', () => { |
| 21 | + test({ |
| 22 | + validator: 'isLength', |
| 23 | + args: [{ max: 4 }], |
| 24 | + valid: ['test\uFE0F'], |
| 25 | + }); |
| 26 | + |
| 27 | + test({ |
| 28 | + validator: 'isLength', |
| 29 | + args: [{ min: 5, max: 5 }], |
| 30 | + valid: ['test\uFE0F\uFE0F'], |
| 31 | + }); |
| 32 | + |
| 33 | + test({ |
| 34 | + validator: 'isLength', |
| 35 | + args: [{ min: 5, max: 5 }], |
| 36 | + valid: ['\uFE0Ftest'], |
| 37 | + }); |
| 38 | + |
| 39 | + test({ |
| 40 | + validator: 'isLength', |
| 41 | + args: [{ min: 9, max: 9 }], |
| 42 | + valid: ['test\uFE0F\uFE0F\uFE0F\uFE0F\uFE0F\uFE0F'], |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should validate strings by length (deprecated api)', () => { |
| 47 | + test({ |
| 48 | + validator: 'isLength', |
| 49 | + args: [2], |
| 50 | + valid: ['abc', 'de', 'abcd'], |
| 51 | + invalid: ['', 'a'], |
| 52 | + }); |
| 53 | + test({ |
| 54 | + validator: 'isLength', |
| 55 | + args: [2, 3], |
| 56 | + valid: ['abc', 'de'], |
| 57 | + invalid: ['', 'a', 'abcd'], |
| 58 | + }); |
| 59 | + test({ |
| 60 | + validator: 'isLength', |
| 61 | + args: [2, 3], |
| 62 | + valid: ['干𩸽', '𠮷野家'], |
| 63 | + invalid: ['', '𠀋', '千竈通り'], |
| 64 | + }); |
| 65 | + test({ |
| 66 | + validator: 'isLength', |
| 67 | + args: [0, 0], |
| 68 | + valid: [''], |
| 69 | + invalid: ['a', 'ab'], |
| 70 | + }); |
| 71 | + }); |
| 72 | + |
| 73 | + it('should validate strings by length', () => { |
| 74 | + test({ |
| 75 | + validator: 'isLength', |
| 76 | + args: [{ min: 2 }], |
| 77 | + valid: ['abc', 'de', 'abcd'], |
| 78 | + invalid: ['', 'a'], |
| 79 | + }); |
| 80 | + test({ |
| 81 | + validator: 'isLength', |
| 82 | + args: [{ min: 2, max: 3 }], |
| 83 | + valid: ['abc', 'de'], |
| 84 | + invalid: ['', 'a', 'abcd'], |
| 85 | + }); |
| 86 | + test({ |
| 87 | + validator: 'isLength', |
| 88 | + args: [{ min: 2, max: 3 }], |
| 89 | + valid: ['干𩸽', '𠮷野家'], |
| 90 | + invalid: ['', '𠀋', '千竈通り'], |
| 91 | + }); |
| 92 | + test({ |
| 93 | + validator: 'isLength', |
| 94 | + args: [{ max: 3 }], |
| 95 | + valid: ['abc', 'de', 'a', ''], |
| 96 | + invalid: ['abcd'], |
| 97 | + }); |
| 98 | + test({ |
| 99 | + validator: 'isLength', |
| 100 | + args: [{ max: 6, discreteLengths: 5 }], |
| 101 | + valid: ['abcd', 'vfd', 'ff', '', 'k'], |
| 102 | + invalid: ['abcdefgh', 'hfjdksks'], |
| 103 | + }); |
| 104 | + test({ |
| 105 | + validator: 'isLength', |
| 106 | + args: [{ min: 2, max: 6, discreteLengths: 5 }], |
| 107 | + valid: ['bsa', 'vfvd', 'ff'], |
| 108 | + invalid: ['', ' ', 'hfskdunvc'], |
| 109 | + }); |
| 110 | + test({ |
| 111 | + validator: 'isLength', |
| 112 | + args: [{ min: 1, discreteLengths: 2 }], |
| 113 | + valid: [' ', 'hello', 'bsa'], |
| 114 | + invalid: [''], |
| 115 | + }); |
| 116 | + test({ |
| 117 | + validator: 'isLength', |
| 118 | + args: [{ max: 0 }], |
| 119 | + valid: [''], |
| 120 | + invalid: ['a', 'ab'], |
| 121 | + }); |
| 122 | + test({ |
| 123 | + validator: 'isLength', |
| 124 | + args: [{ min: 5, max: 10, discreteLengths: [2, 6, 8, 9] }], |
| 125 | + valid: ['helloguy', 'shopping', 'validator', 'length'], |
| 126 | + invalid: ['abcde', 'abcdefg'], |
| 127 | + }); |
| 128 | + test({ |
| 129 | + validator: 'isLength', |
| 130 | + args: [{ discreteLengths: '9' }], |
| 131 | + valid: ['a', 'abcd', 'abcdefghijkl'], |
| 132 | + invalid: [], |
| 133 | + }); |
| 134 | + test({ |
| 135 | + validator: 'isLength', |
| 136 | + valid: ['a', '', 'asds'], |
| 137 | + }); |
| 138 | + test({ |
| 139 | + validator: 'isLength', |
| 140 | + args: [{ max: 8 }], |
| 141 | + valid: ['👩🦰👩👩👦👦🏳️🌈', '⏩︎⏩︎⏪︎⏪︎⏭︎⏭︎⏮︎⏮︎'], |
| 142 | + }); |
| 143 | + }); |
| 144 | +}); |
0 commit comments