|
| 1 | +import { describe, expect, test } from 'vitest'; |
| 2 | + |
| 3 | +import { REGEX_REVERSE_DOMAIN_ID } from '../../utils/regex'; |
| 4 | + |
| 5 | +describe('reverseDomainIdRegex', () => { |
| 6 | + const regex = REGEX_REVERSE_DOMAIN_ID; |
| 7 | + |
| 8 | + test.each([ |
| 9 | + // valid examples |
| 10 | + ['com.example', true], |
| 11 | + ['org.my-app', true], |
| 12 | + ['net.service1', true], |
| 13 | + ['a.b', true], |
| 14 | + ['A.B1', true], |
| 15 | + ['abc.def-ghi', true], |
| 16 | + ['MyCompany.MyApp', true], |
| 17 | + |
| 18 | + // invalid examples |
| 19 | + ['a', false], // only one segment |
| 20 | + ['com.', false], // ends with a dot |
| 21 | + ['.example', false], // starts with a dot |
| 22 | + ['com..example', false], // double dots |
| 23 | + ['com.-example', false], // segment starts with dash |
| 24 | + ['com.exa-', false], // segment ends with dash |
| 25 | + ['1com.example', false], // first segment starts with digit |
| 26 | + ['com.exa$mple', false], // invalid character |
| 27 | + ['com.exa mple', false], // space not allowed |
| 28 | + ['com..example', false], // empty segment |
| 29 | + ])('validates "%s"', (input, expected) => { |
| 30 | + expect(regex.test(input)).toBe(expected); |
| 31 | + }); |
| 32 | +}); |
0 commit comments