import { describe, expect, it } from 'vitest';
import { isReservedSlug, isValidSlug, normalizeSlug, validateSlug } from '../../content/slug.js';
describe('normalizeSlug', () => {
    it('lowercases and hyphenates arbitrary input', () => {
        expect(normalizeSlug('My First Post!')).toBe('my-first-post');
        expect(normalizeSlug('Hello___World')).toBe('hello-world');
        expect(normalizeSlug('  spaced  out  ')).toBe('spaced-out');
    });
    it('strips diacritics', () => {
        expect(normalizeSlug('Café Crème')).toBe('cafe-creme');
    });
    it('collapses repeated separators and trims hyphens', () => {
        expect(normalizeSlug('--a--b--')).toBe('a-b');
        expect(normalizeSlug('!!!')).toBe('');
    });
    it('returns empty for nullish input', () => {
        expect(normalizeSlug(null)).toBe('');
        expect(normalizeSlug(undefined)).toBe('');
    });
});
describe('isValidSlug', () => {
    it('accepts canonical slugs', () => {
        expect(isValidSlug('my-page')).toBe(true);
        expect(isValidSlug('post123')).toBe(true);
        expect(isValidSlug('a')).toBe(true);
    });
    it('rejects malformed slugs', () => {
        expect(isValidSlug('My-Page')).toBe(false); // uppercase
        expect(isValidSlug('my_page')).toBe(false); // underscore
        expect(isValidSlug('-leading')).toBe(false);
        expect(isValidSlug('trailing-')).toBe(false);
        expect(isValidSlug('double--hyphen')).toBe(false);
        expect(isValidSlug('has space')).toBe(false);
        expect(isValidSlug('')).toBe(false);
    });
    it('every normalized non-empty slug is valid', () => {
        for (const input of ['My First Post!', 'Hello___World', 'Café', 'a1 b2 c3']) {
            const normalized = normalizeSlug(input);
            if (normalized)
                expect(isValidSlug(normalized)).toBe(true);
        }
    });
});
describe('isReservedSlug', () => {
    it('flags route-shadowing slugs case-insensitively', () => {
        expect(isReservedSlug('admin')).toBe(true);
        expect(isReservedSlug('API')).toBe(true);
        expect(isReservedSlug('sitemap.xml')).toBe(true);
        expect(isReservedSlug('my-page')).toBe(false);
    });
});
describe('validateSlug', () => {
    it('allows empty/absent (URL presence is enforced elsewhere)', () => {
        expect(validateSlug(null)).toBeNull();
        expect(validateSlug(undefined)).toBeNull();
        expect(validateSlug('   ')).toBeNull();
    });
    it('accepts a valid slug', () => {
        expect(validateSlug('my-page')).toBeNull();
    });
    it('rejects a malformed slug with a helpful message', () => {
        expect(validateSlug('My Page')).toMatch(/lowercase letters/);
    });
    it('rejects a reserved slug', () => {
        expect(validateSlug('admin')).toMatch(/reserved/);
    });
});
//# sourceMappingURL=slug.test.js.map