github.com/mithrandie/csvq@v1.18.1/lib/terminal/terminal_readline_test.go (about) 1 //go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || windows 2 3 package terminal 4 5 import ( 6 "path/filepath" 7 "testing" 8 ) 9 10 var historyFilePathTests = []struct { 11 Filename string 12 Expect string 13 JoinHomeDir bool 14 Error string 15 }{ 16 { 17 Filename: ".zsh_history", 18 Expect: ".zsh_history", 19 JoinHomeDir: true, 20 }, 21 { 22 Filename: filepath.Join("~", ".zsh_history"), 23 Expect: ".zsh_history", 24 JoinHomeDir: true, 25 }, 26 { 27 Filename: filepath.Join(TestDir, "zsh_history"), 28 Expect: filepath.Join(TestDir, "zsh_history"), 29 }, 30 } 31 32 func TestHistoryFilePath(t *testing.T) { 33 for _, v := range historyFilePathTests { 34 result, err := HistoryFilePath(v.Filename) 35 if err != nil { 36 if len(v.Error) < 1 { 37 t.Errorf("unexpected error %q for %q", err, v.Filename) 38 } else if err.Error() != v.Error { 39 t.Errorf("error %q, want error %q for %q", err, v.Error, v.Filename) 40 } 41 continue 42 } 43 if 0 < len(v.Error) { 44 t.Errorf("no error, want error %q for %q", v.Error, v.Filename) 45 continue 46 } 47 48 expect := v.Expect 49 if v.JoinHomeDir { 50 expect = filepath.Join(HomeDir, expect) 51 } 52 if result != expect { 53 t.Errorf("filepath = %q, want %q for %q", result, expect, v.Filename) 54 } 55 } 56 }