mirror of
https://github.com/ManyakRus/starter.git
synced 2025-11-26 23:10:42 +02:00
сделал msg.ParseMode = "HTML"
This commit is contained in:
@@ -1215,3 +1215,18 @@ func MassFrom_Map[C constraints.Ordered, V any](Map map[C]V) []V {
|
|||||||
|
|
||||||
return Otvet
|
return Otvet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Substring - take at most last n characters, from start index
|
||||||
|
func Substring(input string, StartIndex int, length int) string {
|
||||||
|
asRunes := []rune(input)
|
||||||
|
|
||||||
|
if StartIndex >= len(asRunes) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if StartIndex+length > len(asRunes) {
|
||||||
|
length = len(asRunes) - StartIndex
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(asRunes[StartIndex : StartIndex+length])
|
||||||
|
}
|
||||||
|
|||||||
@@ -1206,3 +1206,25 @@ func TestStringDateTime(t *testing.T) {
|
|||||||
t.Errorf("Test case 2 failed. Expected: %s, Got: %s", expectedResult2, result2)
|
t.Errorf("Test case 2 failed. Expected: %s, Got: %s", expectedResult2, result2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSubstring(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
input string
|
||||||
|
startIndex int
|
||||||
|
length int
|
||||||
|
expected string
|
||||||
|
description string
|
||||||
|
}{
|
||||||
|
{"hello", 0, 2, "he", "Getting the first 2 characters"},
|
||||||
|
{"world", 2, 3, "rld", "Getting characters from index 2 to 4"},
|
||||||
|
{"test", 5, 2, "", "Start index beyond the length of the string"},
|
||||||
|
{"", 0, 2, "", "Empty input string"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
result := Substring(test.input, test.startIndex, test.length)
|
||||||
|
if result != test.expected {
|
||||||
|
t.Errorf("Test case failed: %s. Expected: %s, but got: %s", test.description, test.expected, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user