mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-10 17:51:58 -07:00
This change improves sort ordering for aligned tabular input. Given the following input: apple juice 100 apple pie 200 fzf --nth=2 will now prefer the one with pie. Before this change fzf compared "juice " and "pie ", both of which have the same length.
43 lines
778 B
Go
43 lines
778 B
Go
package util
|
|
|
|
import "testing"
|
|
|
|
func TestMax(t *testing.T) {
|
|
if Max(-2, 5, 1, 4, 3) != 5 {
|
|
t.Error("Invalid result")
|
|
}
|
|
}
|
|
|
|
func TestContrain(t *testing.T) {
|
|
if Constrain(-3, -1, 3) != -1 {
|
|
t.Error("Expected", -1)
|
|
}
|
|
if Constrain(2, -1, 3) != 2 {
|
|
t.Error("Expected", 2)
|
|
}
|
|
|
|
if Constrain(5, -1, 3) != 3 {
|
|
t.Error("Expected", 3)
|
|
}
|
|
}
|
|
|
|
func TestTrimLen(t *testing.T) {
|
|
check := func(str string, exp int) {
|
|
trimmed := TrimLen([]rune(str))
|
|
if trimmed != exp {
|
|
t.Errorf("Invalid TrimLen result for '%s': %d (expected %d)",
|
|
str, trimmed, exp)
|
|
}
|
|
}
|
|
check("hello", 5)
|
|
check("hello ", 5)
|
|
check("hello ", 5)
|
|
check(" hello", 5)
|
|
check(" hello", 5)
|
|
check(" hello ", 5)
|
|
check(" hello ", 5)
|
|
check("h o", 5)
|
|
check(" h o ", 5)
|
|
check(" ", 0)
|
|
}
|