package ssh

import (
	"testing"
)

func TestProcessOutputBasicOSC7(t *testing.T) {
	tracker := NewCWDTracker()
	input := []byte("hello\033]7;file://myhost/home/user\033\\world")
	cleaned, cwd := tracker.ProcessOutput(input)
	if string(cleaned) != "helloworld" {
		t.Errorf("cleaned = %q", string(cleaned))
	}
	if cwd != "/home/user" {
		t.Errorf("cwd = %q", cwd)
	}
}

func TestProcessOutputBELTerminator(t *testing.T) {
	tracker := NewCWDTracker()
	input := []byte("output\033]7;file://host/tmp\007more")
	cleaned, cwd := tracker.ProcessOutput(input)
	if string(cleaned) != "outputmore" {
		t.Errorf("cleaned = %q", string(cleaned))
	}
	if cwd != "/tmp" {
		t.Errorf("cwd = %q", cwd)
	}
}

func TestProcessOutputNoOSC7(t *testing.T) {
	tracker := NewCWDTracker()
	input := []byte("just normal output")
	cleaned, cwd := tracker.ProcessOutput(input)
	if string(cleaned) != "just normal output" {
		t.Errorf("cleaned = %q", string(cleaned))
	}
	if cwd != "" {
		t.Errorf("cwd should be empty, got %q", cwd)
	}
}

func TestProcessOutputMultipleOSC7(t *testing.T) {
	tracker := NewCWDTracker()
	input := []byte("\033]7;file://h/dir1\033\\text\033]7;file://h/dir2\033\\end")
	cleaned, cwd := tracker.ProcessOutput(input)
	if string(cleaned) != "textend" {
		t.Errorf("cleaned = %q", string(cleaned))
	}
	if cwd != "/dir2" {
		t.Errorf("cwd = %q, want /dir2", cwd)
	}
}

func TestGetCWDPersists(t *testing.T) {
	tracker := NewCWDTracker()
	tracker.ProcessOutput([]byte("\033]7;file://h/home/user\033\\"))
	if tracker.GetCWD() != "/home/user" {
		t.Errorf("GetCWD = %q", tracker.GetCWD())
	}
}

func TestShellIntegrationCommand(t *testing.T) {
	cmd := ShellIntegrationCommand("bash")
	if cmd == "" {
		t.Error("bash command should not be empty")
	}
	cmd = ShellIntegrationCommand("zsh")
	if cmd == "" {
		t.Error("zsh command should not be empty")
	}
}
