Skip to content

Commit 0568fb7

Browse files
committed
Test(isLength): Relocate length validation tests
1 parent d13cf14 commit 0568fb7

File tree

2 files changed

+99
-97
lines changed

2 files changed

+99
-97
lines changed

test/validators.test.js

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -5591,32 +5591,6 @@ describe('Validators', () => {
55915591
});
55925592
});
55935593

5594-
it('should validate strings by length (deprecated api)', () => {
5595-
test({
5596-
validator: 'isLength',
5597-
args: [2],
5598-
valid: ['abc', 'de', 'abcd'],
5599-
invalid: ['', 'a'],
5600-
});
5601-
test({
5602-
validator: 'isLength',
5603-
args: [2, 3],
5604-
valid: ['abc', 'de'],
5605-
invalid: ['', 'a', 'abcd'],
5606-
});
5607-
test({
5608-
validator: 'isLength',
5609-
args: [2, 3],
5610-
valid: ['干𩸽', '𠮷野家'],
5611-
invalid: ['', '𠀋', '千竈通り'],
5612-
});
5613-
test({
5614-
validator: 'isLength',
5615-
args: [0, 0],
5616-
valid: [''],
5617-
invalid: ['a', 'ab'],
5618-
});
5619-
});
56205594

56215595
it('should validate isLocale codes', () => {
56225596
test({
@@ -5695,77 +5669,6 @@ describe('Validators', () => {
56955669
});
56965670
});
56975671

5698-
it('should validate strings by length', () => {
5699-
test({
5700-
validator: 'isLength',
5701-
args: [{ min: 2 }],
5702-
valid: ['abc', 'de', 'abcd'],
5703-
invalid: ['', 'a'],
5704-
});
5705-
test({
5706-
validator: 'isLength',
5707-
args: [{ min: 2, max: 3 }],
5708-
valid: ['abc', 'de'],
5709-
invalid: ['', 'a', 'abcd'],
5710-
});
5711-
test({
5712-
validator: 'isLength',
5713-
args: [{ min: 2, max: 3 }],
5714-
valid: ['干𩸽', '𠮷野家'],
5715-
invalid: ['', '𠀋', '千竈通り'],
5716-
});
5717-
test({
5718-
validator: 'isLength',
5719-
args: [{ max: 3 }],
5720-
valid: ['abc', 'de', 'a', ''],
5721-
invalid: ['abcd'],
5722-
});
5723-
test({
5724-
validator: 'isLength',
5725-
args: [{ max: 6, discreteLengths: 5 }],
5726-
valid: ['abcd', 'vfd', 'ff', '', 'k'],
5727-
invalid: ['abcdefgh', 'hfjdksks'],
5728-
});
5729-
test({
5730-
validator: 'isLength',
5731-
args: [{ min: 2, max: 6, discreteLengths: 5 }],
5732-
valid: ['bsa', 'vfvd', 'ff'],
5733-
invalid: ['', ' ', 'hfskdunvc'],
5734-
});
5735-
test({
5736-
validator: 'isLength',
5737-
args: [{ min: 1, discreteLengths: 2 }],
5738-
valid: [' ', 'hello', 'bsa'],
5739-
invalid: [''],
5740-
});
5741-
test({
5742-
validator: 'isLength',
5743-
args: [{ max: 0 }],
5744-
valid: [''],
5745-
invalid: ['a', 'ab'],
5746-
});
5747-
test({
5748-
validator: 'isLength',
5749-
args: [{ min: 5, max: 10, discreteLengths: [2, 6, 8, 9] }],
5750-
valid: ['helloguy', 'shopping', 'validator', 'length'],
5751-
invalid: ['abcde', 'abcdefg'],
5752-
});
5753-
test({
5754-
validator: 'isLength',
5755-
args: [{ discreteLengths: '9' }],
5756-
valid: ['a', 'abcd', 'abcdefghijkl'],
5757-
invalid: [],
5758-
});
5759-
test({
5760-
validator: 'isLength',
5761-
valid: ['a', '', 'asds'],
5762-
});
5763-
test({
5764-
validator: 'isLength',
5765-
args: [{ max: 8 }],
5766-
valid: ['👩🦰👩👩👦👦🏳️🌈', '⏩︎⏩︎⏪︎⏪︎⏭︎⏭︎⏮︎⏮︎'],
5767-
});
5768-
});
57695672

57705673
it('should validate strings by byte length', () => {
57715674
test({

test/validators/isLength.test.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,103 @@ describe('isLength', () => {
4242
valid: ['test\uFE0F\uFE0F\uFE0F\uFE0F\uFE0F\uFE0F'],
4343
});
4444
});
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+
});
45144
});

0 commit comments

Comments
 (0)