Skip to content
Myr

history_test.go

This file

Path

src/history_test.go

67 lines · 1.5 KiB · Go

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than 76efddd point at it.

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

lines 1–67why, one step back
1package fzf
23import (4 "os"5 "runtime"6 "testing"7)89func TestHistory(t *testing.T) {10 maxHistory := 501112 // Invalid arguments13 var paths []string14 if runtime.GOOS == "windows" {15 // GOPATH should exist, so we shouldn't be able to override it16 paths = []string{os.Getenv("GOPATH")}17 } else {18 paths = []string{"/etc", "/proc"}19 }2021 for _, path := range paths {22 if _, e := NewHistory(path, maxHistory); e == nil {23 t.Error("Error expected for: " + path)24 }25 }2627 f, _ := os.CreateTemp("", "fzf-history")28 f.Close()2930 { // Append lines31 h, _ := NewHistory(f.Name(), maxHistory)32 for i := 0; i < maxHistory+10; i++ {33 h.append("foobar")34 }35 }36 { // Read lines37 h, _ := NewHistory(f.Name(), maxHistory)38 if len(h.lines) != maxHistory+1 {39 t.Errorf("Expected: %d, actual: %d\n", maxHistory+1, len(h.lines))40 }41 for i := range maxHistory {42 if h.lines[i] != "foobar" {43 t.Error("Expected: foobar, actual: " + h.lines[i])44 }45 }46 }47 { // Append lines48 h, _ := NewHistory(f.Name(), maxHistory)49 h.append("barfoo")50 h.append("")51 h.append("foobarbaz")52 }53 { // Read lines again54 h, _ := NewHistory(f.Name(), maxHistory)55 if len(h.lines) != maxHistory+1 {56 t.Errorf("Expected: %d, actual: %d\n", maxHistory+1, len(h.lines))57 }58 compare := func(idx int, exp string) {59 if h.lines[idx] != exp {60 t.Errorf("Expected: %s, actual: %s\n", exp, h.lines[idx])61 }62 }63 compare(maxHistory-3, "foobar")64 compare(maxHistory-2, "barfoo")65 compare(maxHistory-1, "foobarbaz")66 }67}