import { describe, it, expect } from 'vitest' import { testRegex, explainRegex } from '../src/utils/regex-tester.js' describe('regex-tester', () => { it('finds simple matches', () => { const result = testRegex({ pattern: '\\d+', flags: 'g', text: 'abc 123 def 456' }) expect(result.valid).toBe(true) expect(result.matches.length).toBe(2) expect(result.matches[0].full).toBe('123') expect(result.matches[1].full).toBe('456') }) it('captures groups', () => { const result = testRegex({ pattern: '(\\w+)=(\\d+)', flags: 'g', text: 'a=1,b=2' }) expect(result.valid).toBe(true) expect(result.matches[0].groups).toEqual(['a', '1']) }) it('reports invalid regex', () => { const result = testRegex({ pattern: '[', flags: '', text: 'test' }) expect(result.valid).toBe(false) expect(result.error).toBeDefined() }) it('shows replace preview', () => { const result = testRegex({ pattern: '\\d+', flags: 'g', text: 'abc 123', replacement: 'XXX', }) expect(result.replacePreview).toBe('abc XXX') }) it('explains patterns', () => { const exp = explainRegex('\\d+') expect(exp).toContain('\\d') }) })