summaryrefslogtreecommitdiff
path: root/dot-oh-my-zsh/custom/plugins/fzf/src/util/util_test.go
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2024-06-03 19:56:39 +0800
committerlittleblack111 <littleblack11111@gmail.com>2024-06-03 19:56:39 +0800
commitca968c4e5040f1ff4b5b5e12d9312360d807dcc1 (patch)
tree9900920e8f566794560c1519678e344351d2803b /dot-oh-my-zsh/custom/plugins/fzf/src/util/util_test.go
parent5f3deaff0bf006a1a353e57b82ad48c0e8f143bc (diff)
added submodules, change . -> dot (see man stow --dotfiles)
Diffstat (limited to 'dot-oh-my-zsh/custom/plugins/fzf/src/util/util_test.go')
-rw-r--r--dot-oh-my-zsh/custom/plugins/fzf/src/util/util_test.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/dot-oh-my-zsh/custom/plugins/fzf/src/util/util_test.go b/dot-oh-my-zsh/custom/plugins/fzf/src/util/util_test.go
new file mode 100644
index 00000000..20bdb92a
--- /dev/null
+++ b/dot-oh-my-zsh/custom/plugins/fzf/src/util/util_test.go
@@ -0,0 +1,66 @@
+package util
+
+import "testing"
+
+func TestMax(t *testing.T) {
+ if Max(-2, 5) != 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 TestOnce(t *testing.T) {
+ o := Once(false)
+ if o() {
+ t.Error("Expected: false")
+ }
+ if o() {
+ t.Error("Expected: false")
+ }
+
+ o = Once(true)
+ if !o() {
+ t.Error("Expected: true")
+ }
+ if o() {
+ t.Error("Expected: false")
+ }
+}
+
+func TestRunesWidth(t *testing.T) {
+ for _, args := range [][]int{
+ {100, 5, -1},
+ {3, 4, 3},
+ {0, 1, 0},
+ } {
+ width, overflowIdx := RunesWidth([]rune("hello"), 0, 0, args[0])
+ if width != args[1] {
+ t.Errorf("Expected width: %d, actual: %d", args[1], width)
+ }
+ if overflowIdx != args[2] {
+ t.Errorf("Expected overflow index: %d, actual: %d", args[2], overflowIdx)
+ }
+ }
+}
+
+func TestTruncate(t *testing.T) {
+ truncated, width := Truncate("가나다라마", 7)
+ if string(truncated) != "가나다" {
+ t.Errorf("Expected: 가나다, actual: %s", string(truncated))
+ }
+ if width != 6 {
+ t.Errorf("Expected: 6, actual: %d", width)
+ }
+}