TKGASXMX2K7TH7H4PECN7LX2AYAGHYDHOVY7WFBEHFUTNKPX3MWAC }}func TestSegmentMatchesFilters(t *testing.T) {// Create test segments with various labelsseg := &Segment{Labels: []*Label{{Species: "Kiwi", Filter: "model-1.0", CallType: "Duet"},{Species: "Morepork", Filter: "model-2.0", CallType: ""},},}tests := []struct {name stringfilter stringspecies stringcallType stringwant bool}{{"no filters", "", "", "", true},{"filter only match", "model-1.0", "", "", true},{"filter only no match", "model-3.0", "", "", false},{"species only match", "", "Kiwi", "", true},{"species only no match", "", "Tomtit", "", false},{"calltype only match", "", "", "Duet", true},{"calltype only no match", "", "", "Male", false},{"filter+species match", "model-1.0", "Kiwi", "", true},{"filter+species+calltype match", "model-1.0", "Kiwi", "Duet", true},{"filter match species miss", "model-1.0", "Morepork", "", false},{"all miss", "model-3.0", "Tomtit", "Male", false},}for _, tt := range tests {t.Run(tt.name, func(t *testing.T) {got := seg.SegmentMatchesFilters(tt.filter, tt.species, tt.callType)if got != tt.want {t.Errorf("SegmentMatchesFilters(%q, %q, %q) = %v, want %v",tt.filter, tt.species, tt.callType, got, tt.want)}})}}func TestParseSpeciesCallType(t *testing.T) {tests := []struct {input stringspecies stringcallType string}{{"", "", ""},{"Kiwi", "Kiwi", ""},{"Kiwi+Duet", "Kiwi", "Duet"},{"GSK+Female", "GSK", "Female"},{"Species+With+Multiple+Plus", "Species", "With+Multiple+Plus"},}for _, tt := range tests {t.Run(tt.input, func(t *testing.T) {species, callType := ParseSpeciesCallType(tt.input)if species != tt.species || callType != tt.callType {t.Errorf("ParseSpeciesCallType(%q) = (%q, %q), want (%q, %q)",tt.input, species, callType, tt.species, tt.callType)}})
}// SegmentMatchesFilters returns true if the segment has any label matching all filter criteria.// All non-empty parameters must match for a label to be considered a match.func (s *Segment) SegmentMatchesFilters(filter, species, callType string) bool {if filter == "" && species == "" && callType == "" {return true // No filters, match all}for _, label := range s.Labels {if filter != "" && label.Filter != filter {continue}if species != "" && label.Species != species {continue}if callType != "" && label.CallType != callType {continue}return true}return false
// ParseSpeciesCallType parses a species string with optional calltype into separate values.// Format: "Species" or "Species+CallType" (e.g., "Kiwi" or "Kiwi+Duet").func ParseSpeciesCallType(s string) (species, callType string) {if s == "" {return "", ""}if idx := strings.Index(s, "+"); idx >= 0 {return s[:idx], s[idx+1:]}return s, ""}
var speciesName, callType stringif input.Species != "" {if strings.Contains(input.Species, "+") {parts := strings.SplitN(input.Species, "+", 2)speciesName = parts[0]callType = parts[1]} else {speciesName = input.Species}}
speciesName, callType := utils.ParseSpeciesCallType(input.Species)
// segmentMatchesFilters checks if a segment matches the filter criteriafunc segmentMatchesFilters(seg *utils.Segment, filter, speciesName, callType string) bool {if filter == "" && speciesName == "" {return true // No filters, match all}for _, label := range seg.Labels {filterMatch := filter == "" || label.Filter == filterspeciesMatch := speciesName == "" || label.Species == speciesNamecallTypeMatch := callType == "" || label.CallType == callTypeif filterMatch && speciesMatch && callTypeMatch {return true}}return false}
for _, label := range seg.Labels {if s.Config.Filter != "" && label.Filter != s.Config.Filter {continue}if s.Config.Species != "" && label.Species != s.Config.Species {continue}if s.Config.CallType != "" && label.CallType != s.Config.CallType {continue}return true}return false
return seg.SegmentMatchesFilters(s.Config.Filter, s.Config.Species, s.Config.CallType)
var speciesName, callType stringif species != "" {if strings.Contains(species, "+") {parts := strings.SplitN(species, "+", 2)speciesName = parts[0]callType = parts[1]} else {speciesName = species}}
speciesName, callType := utils.ParseSpeciesCallType(species)