"use strict";
/**
 * Tests for editor-monitor parser (Feature #2)
 * Focus on title-to-state parsing — no PowerShell/active window required.
 */
Object.defineProperty(exports, "__esModule", { value: true });
const editor_monitor_1 = require("../walls/07-runtime/watcher/editor-monitor");
describe('parseTitleToState', () => {
    describe('VS Code titles', () => {
        it('parses standard VS Code title with file, project, and editor name', () => {
            const s = (0, editor_monitor_1.parseTitleToState)('auth.ts - my-app - Visual Studio Code', 'Code', 'my-app', '/tmp');
            expect(s).not.toBeNull();
            expect(s.editorName).toBe('vscode');
            expect(s.project).toBe('my-app');
            expect(s.isDirty).toBe(false);
            expect(s.language).toBe('typescript');
        });
        it('detects dirty marker (●) at the start of filename', () => {
            const s = (0, editor_monitor_1.parseTitleToState)('● auth.ts - my-app - Visual Studio Code', 'Code', 'my-app');
            expect(s).not.toBeNull();
            expect(s.isDirty).toBe(true);
        });
        it('resolves file basename to actual path when it exists in fileBaseDir', () => {
            const s = (0, editor_monitor_1.parseTitleToState)('package.json - test - Visual Studio Code', 'Code', 'test', 'C:\\Users\\ss\\Downloads\\Pulse Project\\Fivo-Cell');
            expect(s).not.toBeNull();
            // Should find the actual file in the project root
            expect(s.filePath.toLowerCase()).toContain('package.json');
        });
    });
    describe('Cursor titles', () => {
        it('parses Cursor em-dash format with project', () => {
            const s = (0, editor_monitor_1.parseTitleToState)('login.tsx — my-app — Cursor', 'Cursor', 'my-app');
            expect(s).not.toBeNull();
            expect(s.editorName).toBe('cursor');
            expect(s.project).toBe('my-app');
        });
    });
    describe('Windsurf titles', () => {
        it('parses Windsurf format', () => {
            const s = (0, editor_monitor_1.parseTitleToState)('index.html - landing - Windsurf', 'windsurf', 'landing');
            expect(s).not.toBeNull();
            expect(s.editorName).toBe('windsurf');
        });
    });
    describe('Process name detection', () => {
        it('maps "Code" to vscode', () => {
            const s = (0, editor_monitor_1.parseTitleToState)('foo.py - proj - Visual Studio Code', 'Code', 'proj');
            expect(s.editorName).toBe('vscode');
            expect(s.language).toBe('python');
        });
        it('maps "Code - Insiders" to vscode-insiders', () => {
            const s = (0, editor_monitor_1.parseTitleToState)('foo.js - proj - Visual Studio Code', 'Code - Insiders', 'proj');
            expect(s.editorName).toBe('vscode-insiders');
        });
        it('maps "OpenCode" to opencode', () => {
            const s = (0, editor_monitor_1.parseTitleToState)('main.go - proj - Visual Studio Code', 'OpenCode', 'proj');
            expect(s.editorName).toBe('opencode');
        });
    });
    describe('Edge cases', () => {
        it('returns null for non-editor process', () => {
            const s = (0, editor_monitor_1.parseTitleToState)('Some random window title', 'chrome', 'proj');
            expect(s).toBeNull();
        });
        it('returns null for empty title', () => {
            const s = (0, editor_monitor_1.parseTitleToState)('', 'Code', 'proj');
            expect(s).toBeNull();
        });
        it('returns null for app without a file (just app name)', () => {
            const s = (0, editor_monitor_1.parseTitleToState)('OpenCode', 'OpenCode', 'proj');
            expect(s).toBeNull();
        });
        it('accepts full file path as title when it has an extension', () => {
            const s = (0, editor_monitor_1.parseTitleToState)('/home/user/project/src/auth.ts', 'Code', 'project');
            expect(s).not.toBeNull();
            expect(s.filePath).toBe('/home/user/project/src/auth.ts');
            expect(s.language).toBe('typescript');
        });
        it('accepts Windows path with backslashes', () => {
            const s = (0, editor_monitor_1.parseTitleToState)('C:\\Users\\me\\project\\auth.ts', 'Code', 'project');
            expect(s).not.toBeNull();
            expect(s.filePath).toContain('auth.ts');
        });
    });
    describe('Language detection', () => {
        const cases = [
            ['foo.ts', 'typescript'],
            ['foo.tsx', 'tsx'],
            ['foo.js', 'javascript'],
            ['foo.py', 'python'],
            ['foo.go', 'go'],
            ['foo.rs', 'rust'],
            ['foo.java', 'java'],
            ['foo.md', 'markdown'],
            ['foo.json', 'json'],
            ['foo.yaml', 'yaml'],
            ['foo.yml', 'yaml'],
            ['foo.sh', 'bash'],
            ['foo.sql', 'sql'],
        ];
        for (const [file, lang] of cases) {
            it(`detects ${lang} for ${file}`, () => {
                const s = (0, editor_monitor_1.parseTitleToState)(`${file} - proj - Visual Studio Code`, 'Code', 'proj');
                expect(s.language).toBe(lang);
            });
        }
    });
});
//# sourceMappingURL=cross-memory-editor-monitor.test.js.map