package ucca

import "testing"

func TestFilterByKnowledgeSpace(t *testing.T) {
	results := []LegalSearchResult{
		{CitationUnit: "Art. 13 DSGVO", RegulationCode: "DSGVO"},
		{CitationUnit: "EU Mdr", RegulationCode: "EU MDR"},
		{CitationUnit: "UStG § 14", RegulationCode: "USTG"},
		{CitationUnit: "DSK OH Telemedien", RegulationCode: "DSK OH TELEMEDIEN"},
		{CitationUnit: "eIDAS", RegulationCode: "EIDAS"},
	}
	out := FilterByKnowledgeSpace(results, "datenschutz", 10)
	for _, r := range out {
		if KnowledgeSpaceOf(r.RegulationCode) != "datenschutz" {
			t.Errorf("off-domain leaked into scoped result: %s (%s)", r.CitationUnit, r.RegulationCode)
		}
	}
	if len(out) != 2 { // Art. 13 DSGVO + DSK OH Telemedien
		t.Errorf("expected 2 datenschutz hits, got %d", len(out))
	}
	// domain with no hits -> fall back to input (never strand the answer)
	if len(FilterByKnowledgeSpace(results, "maschinen", 10)) != len(results) {
		t.Errorf("no-hit domain should fall back to full input")
	}
}
