package cmd

import "testing"

func TestParseCreateName(t *testing.T) {
	t.Run("simple repo name", func(t *testing.T) {
		org, repo, isOrg, err := parseCreateName("myrepo")
		if err != nil {
			t.Fatalf("unexpected error: %v", err)
		}
		if org != "" || repo != "myrepo" || isOrg {
			t.Errorf("got (%q, %q, %v), want (%q, %q, %v)", org, repo, isOrg, "", "myrepo", false)
		}
	})

	t.Run("org/repo name", func(t *testing.T) {
		org, repo, isOrg, err := parseCreateName("myorg/myrepo")
		if err != nil {
			t.Fatalf("unexpected error: %v", err)
		}
		if org != "myorg" || repo != "myrepo" || !isOrg {
			t.Errorf("got (%q, %q, %v), want (%q, %q, %v)", org, repo, isOrg, "myorg", "myrepo", true)
		}
	})

	t.Run("empty string", func(t *testing.T) {
		_, _, _, err := parseCreateName("")
		if err == nil {
			t.Error("expected error for empty string, got nil")
		}
	})

	t.Run("slash only", func(t *testing.T) {
		_, _, _, err := parseCreateName("/")
		if err == nil {
			t.Error("expected error for '/', got nil")
		}
	})

	t.Run("empty repo after slash", func(t *testing.T) {
		_, _, _, err := parseCreateName("org/")
		if err == nil {
			t.Error("expected error for 'org/', got nil")
		}
	})

	t.Run("empty org before slash", func(t *testing.T) {
		_, _, _, err := parseCreateName("/repo")
		if err == nil {
			t.Error("expected error for '/repo', got nil")
		}
	})
}
