mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-17 01:11:38 +03:00
fix: ensure file descriptors are closed + other bugs (#413)
This commit is contained in:
committed by
GitHub
parent
980780e48b
commit
2f7646105e
@@ -102,3 +102,16 @@ func CamelCaseToScreamingSnakeCase(s string) string {
|
||||
// Convert to uppercase
|
||||
return strings.ToUpper(snake)
|
||||
}
|
||||
|
||||
// GetFirstCharacter returns the first non-whitespace character of the string, correctly handling Unicode
|
||||
func GetFirstCharacter(str string) string {
|
||||
for _, c := range str {
|
||||
if unicode.IsSpace(c) {
|
||||
continue
|
||||
}
|
||||
return string(c)
|
||||
}
|
||||
|
||||
// Empty string case
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -103,3 +103,28 @@ func TestCamelCaseToSnakeCase(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetFirstCharacter(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{"empty string", "", ""},
|
||||
{"single character", "a", "a"},
|
||||
{"multiple characters", "hello", "h"},
|
||||
{"unicode character", "étoile", "é"},
|
||||
{"special character", "!test", "!"},
|
||||
{"number as first character", "123abc", "1"},
|
||||
{"whitespace as first character", " hello", "h"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := GetFirstCharacter(tt.input)
|
||||
if result != tt.expected {
|
||||
t.Errorf("GetFirstCharacter(%q) = %q, want %q", tt.input, result, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user