test: подключить vitest и покрыть утилиты юнит-тестами

This commit is contained in:
kewldan
2026-07-13 01:09:33 +03:00
parent 758a645dff
commit 42788e842d
9 changed files with 527 additions and 3 deletions

View File

@@ -0,0 +1,28 @@
import { describe, expect, it } from 'vitest';
import { sanitizeSurrogates } from './sanitizeSurrogates';
describe('sanitizeSurrogates', () => {
it('returns surrogate-free strings unchanged', () => {
expect(sanitizeSurrogates('')).toBe('');
expect(sanitizeSurrogates('https://host/sub/uuid#remark')).toBe('https://host/sub/uuid#remark');
});
it('keeps valid surrogate pairs intact', () => {
expect(sanitizeSurrogates('server 😀 name')).toBe('server 😀 name');
});
it('replaces a lone high surrogate', () => {
expect(sanitizeSurrogates('abc\uD83D')).toBe('abc<62>');
expect(sanitizeSurrogates('\uD83Dxyz')).toBe('<27>xyz');
});
it('replaces a lone low surrogate', () => {
expect(sanitizeSurrogates('abc\uDE00def')).toBe('abc<62>def');
});
it('makes a truncated-emoji string safe for encodeURI', () => {
const broken = 'remark \uD83D truncated';
expect(() => encodeURI(broken)).toThrow();
expect(() => encodeURI(sanitizeSurrogates(broken))).not.toThrow();
});
});