package nvidia

import "testing"

func TestParseNVSwitchComponent_NormalizesDuplicatedPrefixInSlot(t *testing.T) {
	comp := Component{
		ComponentID: "NVSWITCHNVSWITCH1",
		Properties: []Property{
			{ID: "VendorID", Value: "10de"},
			{ID: "DeviceID", Value: "22a3"},
			{ID: "Vendor", Value: "NVIDIA Corporation"},
			{ID: "PCIID", Value: "0000:06:00.0"},
			{ID: "PCISpeed", Value: "16GT/s"},
			{ID: "PCIWidth", Value: "x2"},
			{ID: "VBIOS_version", Value: "96.10.6D.00.01"},
		},
	}

	device := parseNVSwitchComponent(comp)
	if device == nil {
		t.Fatal("expected non-nil NVSwitch device")
	}

	if device.Slot != "NVSWITCH1" {
		t.Fatalf("expected normalized slot NVSWITCH1, got %q", device.Slot)
	}

	if device.BDF != "0000:06:00.0" {
		t.Fatalf("expected BDF 0000:06:00.0, got %q", device.BDF)
	}

	if device.DeviceClass != "NVSwitch" {
		t.Fatalf("expected device class NVSwitch, got %q", device.DeviceClass)
	}
}
