mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
added test for text view split line
This commit is contained in:
parent
bd8940ae0a
commit
d0b5c6c854
@ -93,14 +93,17 @@ func (t *TextView) readInputLoop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func splitLine(line string, lineSize int) []string {
|
func splitLine(line string, lineSize int) []string {
|
||||||
|
if line == "" {
|
||||||
|
return []string{}
|
||||||
|
}
|
||||||
|
|
||||||
var lines []string
|
var lines []string
|
||||||
for {
|
for {
|
||||||
if len(line) < lineSize {
|
if len(line) <= lineSize {
|
||||||
lines = append(lines, line)
|
lines = append(lines, line)
|
||||||
return lines
|
return lines
|
||||||
}
|
}
|
||||||
lines = append(lines, line[:lineSize])
|
lines = append(lines, line[:lineSize])
|
||||||
line = line[lineSize:]
|
line = line[lineSize:]
|
||||||
}
|
}
|
||||||
return lines
|
|
||||||
}
|
}
|
||||||
|
35
widgets/view_test.go
Normal file
35
widgets/view_test.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package widgets
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestSplitEmptyLine(t *testing.T) {
|
||||||
|
|
||||||
|
result := splitLine("", 5)
|
||||||
|
if len(result) != 0 {
|
||||||
|
t.Errorf("expected: 0 lines, got: %d", len(result))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSplitLineShorterThanLimit(t *testing.T) {
|
||||||
|
|
||||||
|
result := splitLine("hello", 7)
|
||||||
|
if len(result) != 1 {
|
||||||
|
t.Errorf("expected: 0 lines, got: %d", len(result))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSplitLineLongerThanLimit(t *testing.T) {
|
||||||
|
|
||||||
|
result := splitLine("hello", 3)
|
||||||
|
if len(result) != 2 {
|
||||||
|
t.Errorf("expected: 0 lines, got: %d", len(result))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSplitLineSameAsLimit(t *testing.T) {
|
||||||
|
|
||||||
|
result := splitLine("hello", 5)
|
||||||
|
if len(result) != 1 {
|
||||||
|
t.Errorf("expected: 0 lines, got: %d", len(result))
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user