package knowledge import ( "strings" "testing" ) func TestPatrolTagFromQuestionPreservesSearchPhrase(t *testing.T) { got := PatrolTagFromQuestion("化療後皮膚敏感要換什麼沐浴乳") if got != "化療後皮膚敏感要換什麼沐浴乳" { t.Fatalf("expected preserved question, got %q", got) } } func TestAnchorPatrolTagToProductInjectsCategory(t *testing.T) { in := PatrolTagInput{ ProductName: "天然洗衣精", MatchTags: []string{"洗衣精", "衣物清潔"}, } got := AnchorPatrolTagToProduct("敏感肌 推薦", in) if got == "敏感肌 推薦" { t.Fatal("expected product category to be injected into generic tag") } if !strings.Contains(got, "洗衣") { t.Fatalf("expected laundry anchor in %q", got) } } func TestAnchorPatrolTagToProductPrefersValueAnchor(t *testing.T) { in := PatrolTagInput{ ProductName: "抗敏無香洗衣精", ProductFeatures: "完全無香、抗敏、適合化療族群", MatchTags: []string{"無香", "洗衣精"}, } got := AnchorPatrolTagToProduct("皮膚癢 推薦", in) if !strings.Contains(got, "無香") { t.Fatalf("expected value anchor in %q", got) } if !strings.Contains(got, "洗衣精") { t.Fatalf("expected product form in %q", got) } } func TestPatrolTagFromQuestionCompressesGenericLabel(t *testing.T) { got := PatrolTagFromQuestion("敏感肌保養") if got == "敏感肌保養" { t.Fatal("expected compression for generic short label") } if got == "" { t.Fatal("expected non-empty tag") } }