package app import ( "reflect" "testing" ) func TestQuestionCombinationRegionTermsFromIPRegion(t *testing.T) { got := questionCombinationRegionTermsFromIPRegion("中国|0|安徽省|合肥市|电信") want := []string{"合肥", "华东"} if !reflect.DeepEqual(got, want) { t.Fatalf("region terms = %#v, want %#v", got, want) } } func TestBuildQuestionCombinationFillFallback(t *testing.T) { description := "GEO 与 AI 搜索优化平台" got := buildQuestionCombinationFillFallback(&questionBrandContext{ BrandName: "GeoRankly", Description: &description, }, []string{"上海", "华东"}, QuestionCombinationFillRequest{}) if !reflect.DeepEqual(got.Region, []string{"上海", "华东"}) { t.Fatalf("region = %#v", got.Region) } wantPrefix := []string{"性价比高的", "口碑好的", "专业的", "靠谱的"} if !reflect.DeepEqual(got.Prefix, wantPrefix) { t.Fatalf("prefix fallback = %#v, want %#v", got.Prefix, wantPrefix) } wantCore := []string{"品牌词", "AI搜索", "获客", "中小企业"} if !reflect.DeepEqual(got.Core, wantCore) { t.Fatalf("core fallback = %#v, want %#v", got.Core, wantCore) } wantIndustry := []string{"GEO优化", "AI搜索优化", "品牌推广", "搜索营销"} if !reflect.DeepEqual(got.Industry, wantIndustry) { t.Fatalf("industry fallback = %#v, want %#v", got.Industry, wantIndustry) } if len(got.Prefix) != 4 || len(got.Industry) != 4 || len(got.Suffix) != 4 { t.Fatalf("expected four hot terms for non-region columns, got %#v", got) } wantSuffix := []string{"哪家好", "怎么选", "推荐", "避坑"} if !reflect.DeepEqual(got.Suffix, wantSuffix) { t.Fatalf("suffix fallback = %#v, want %#v", got.Suffix, wantSuffix) } } func TestNormalizeQuestionTextRemovesPunctuation(t *testing.T) { got := normalizeQuestionText(" 合肥全屋定制哪家好? ") if got != "合肥全屋定制哪家好" { t.Fatalf("normalizeQuestionText() = %q, want %q", got, "合肥全屋定制哪家好") } } func TestCompactQuestionCombinationTermsRemovesPunctuation(t *testing.T) { got := compactQuestionCombinationTerms([]string{"官网?", "怎么选?", "推荐!", "对比"}, 4) want := []string{"官网", "怎么选", "推荐", "对比"} if !reflect.DeepEqual(got, want) { t.Fatalf("compactQuestionCombinationTerms() = %#v, want %#v", got, want) } } func TestQuestionContainsExcludedEntityMatchesCompanyShortName(t *testing.T) { brandName := "安徽海翔家居用品销售有限公司" if !questionContainsExcludedEntity("安徽海翔家居全屋定制口碑怎么样", brandName, nil) { t.Fatal("expected candidate containing company short name to be excluded") } if questionContainsExcludedEntity("合肥全屋定制哪家好", brandName, nil) { t.Fatal("expected generic user search term to be allowed") } }