|
| 1 | +import { socialHandleRegex, handleRegex } from '../../src/common/object'; |
| 2 | + |
| 3 | +describe('Unicode regex patterns', () => { |
| 4 | + it('socialHandleRegex supports Unicode with optional @ prefix', () => { |
| 5 | + // Valid Unicode handles |
| 6 | + expect(socialHandleRegex.test('@José')).toBe(true); |
| 7 | + expect(socialHandleRegex.test('François-dev')).toBe(true); |
| 8 | + expect(socialHandleRegex.test('北京')).toBe(true); |
| 9 | + expect(socialHandleRegex.test('user_123')).toBe(true); |
| 10 | + expect(socialHandleRegex.test('@' + 'a'.repeat(39))).toBe(true); |
| 11 | + |
| 12 | + // Invalid handles |
| 13 | + expect(socialHandleRegex.test('')).toBe(false); |
| 14 | + expect(socialHandleRegex.test('a'.repeat(40))).toBe(false); |
| 15 | + expect(socialHandleRegex.test('has space')).toBe(false); |
| 16 | + expect(socialHandleRegex.test('bad!char')).toBe(false); |
| 17 | + }); |
| 18 | + |
| 19 | + it('handleRegex supports Unicode without hyphens', () => { |
| 20 | + // Valid handles (3-39 chars, no hyphens) |
| 21 | + expect(handleRegex.test('abc')).toBe(true); |
| 22 | + expect(handleRegex.test('@user_name')).toBe(true); |
| 23 | + expect(handleRegex.test('Jöhn123')).toBe(true); |
| 24 | + expect(handleRegex.test('@' + 'a'.repeat(39))).toBe(true); |
| 25 | + |
| 26 | + // Invalid handles |
| 27 | + expect(handleRegex.test('ab')).toBe(false); // too short |
| 28 | + expect(handleRegex.test('François-dev')).toBe(false); // has hyphen |
| 29 | + expect(handleRegex.test('bad handle')).toBe(false); // has space |
| 30 | + expect(handleRegex.test('a'.repeat(40))).toBe(false); // too long |
| 31 | + }); |
| 32 | +}); |
0 commit comments