parent
34c341c88c
commit
e1c8101d29
2 changed files with 15 additions and 16 deletions
|
|
@ -134,8 +134,8 @@ func (s *service) ExtractTags(content []byte) ([]string, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deduplicate and normalize tags
|
// Deduplicate tags while preserving original case
|
||||||
return uniqueLowercase(tags), nil
|
return uniquePreserveCase(tags), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExtractProperties computes boolean properties about the content.
|
// ExtractProperties computes boolean properties about the content.
|
||||||
|
|
@ -334,8 +334,8 @@ func (s *service) ExtractAll(content []byte) (*ExtractedData, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deduplicate and normalize tags
|
// Deduplicate tags while preserving original case
|
||||||
data.Tags = uniqueLowercase(data.Tags)
|
data.Tags = uniquePreserveCase(data.Tags)
|
||||||
|
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
@ -372,16 +372,15 @@ func (s *service) RenameTag(content []byte, oldTag, newTag string) (string, erro
|
||||||
return mdRenderer.Render(root, content), nil
|
return mdRenderer.Render(root, content), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// uniqueLowercase returns unique lowercase strings from input.
|
// uniquePreserveCase returns unique strings from input while preserving case.
|
||||||
func uniqueLowercase(strs []string) []string {
|
func uniquePreserveCase(strs []string) []string {
|
||||||
seen := make(map[string]bool)
|
seen := make(map[string]struct{})
|
||||||
var result []string
|
var result []string
|
||||||
|
|
||||||
for _, s := range strs {
|
for _, s := range strs {
|
||||||
lower := strings.ToLower(s)
|
if _, exists := seen[s]; !exists {
|
||||||
if !seen[lower] {
|
seen[s] = struct{}{}
|
||||||
seen[lower] = true
|
result = append(result, s)
|
||||||
result = append(result, lower)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -223,7 +223,7 @@ func TestExtractTags(t *testing.T) {
|
||||||
name: "duplicate tags",
|
name: "duplicate tags",
|
||||||
content: "#work is important. #Work #WORK",
|
content: "#work is important. #Work #WORK",
|
||||||
withExt: true,
|
withExt: true,
|
||||||
expected: []string{"work"}, // Deduplicated and lowercased
|
expected: []string{"work", "Work", "WORK"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "tags with hyphens and underscores",
|
name: "tags with hyphens and underscores",
|
||||||
|
|
@ -315,7 +315,7 @@ func TestExtractTags(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUniqueLowercase(t *testing.T) {
|
func TestUniquePreserveCase(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
input []string
|
input []string
|
||||||
|
|
@ -334,18 +334,18 @@ func TestUniqueLowercase(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "duplicates",
|
name: "duplicates",
|
||||||
input: []string{"tag", "TAG", "Tag"},
|
input: []string{"tag", "TAG", "Tag"},
|
||||||
expected: []string{"tag"},
|
expected: []string{"tag", "TAG", "Tag"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "mixed",
|
name: "mixed",
|
||||||
input: []string{"Work", "work", "Important", "work"},
|
input: []string{"Work", "work", "Important", "work"},
|
||||||
expected: []string{"work", "important"},
|
expected: []string{"Work", "work", "Important"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
result := uniqueLowercase(tt.input)
|
result := uniquePreserveCase(tt.input)
|
||||||
assert.ElementsMatch(t, tt.expected, result)
|
assert.ElementsMatch(t, tt.expected, result)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue