summaryrefslogtreecommitdiffstats
path: root/src/history_test.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-06-14 00:53:45 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-06-14 00:53:45 +0900
commit8e7164553f231ec7e76ce54693b1457872001333 (patch)
tree596fcee2ab9ecf4aea759a7098d56fb572ef9767 /src/history_test.go
parent3b5281179639811eb9a1e5fde8aeed1264f842ed (diff)
Add missing files from the previous commit
:(
Diffstat (limited to 'src/history_test.go')
-rw-r--r--src/history_test.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/history_test.go b/src/history_test.go
new file mode 100644
index 00000000..83e40297
--- /dev/null
+++ b/src/history_test.go
@@ -0,0 +1,53 @@
+package fzf
+
+import (
+ "testing"
+)
+
+func TestHistory(t *testing.T) {
+ maxHistory := 50
+
+ // Invalid arguments
+ for _, path := range []string{"/etc", "/proc", "/etc/sudoers"} {
+ if _, e := NewHistory(path, maxHistory); e == nil {
+ t.Error("Error expected for: " + path)
+ }
+ }
+ { // Append lines
+ h, _ := NewHistory("/tmp/fzf-history", maxHistory)
+ for i := 0; i < maxHistory+10; i++ {
+ h.append("foobar")
+ }
+ }
+ { // Read lines
+ h, _ := NewHistory("/tmp/fzf-history", maxHistory)
+ if len(h.lines) != maxHistory+1 {
+ t.Errorf("Expected: %d, actual: %d\n", maxHistory+1, len(h.lines))
+ }
+ for i := 0; i < maxHistory; i++ {
+ if h.lines[i] != "foobar" {
+ t.Error("Expected: foobar, actual: " + h.lines[i])
+ }
+ }
+ }
+ { // Append lines
+ h, _ := NewHistory("/tmp/fzf-history", maxHistory)
+ h.append("barfoo")
+ h.append("")
+ h.append("foobarbaz")
+ }
+ { // Read lines again
+ h, _ := NewHistory("/tmp/fzf-history", maxHistory)
+ if len(h.lines) != maxHistory+1 {
+ t.Errorf("Expected: %d, actual: %d\n", maxHistory+1, len(h.lines))
+ }
+ compare := func(idx int, exp string) {
+ if h.lines[idx] != exp {
+ t.Errorf("Expected: %s, actual: %s\n", exp, h.lines[idx])
+ }
+ }
+ compare(maxHistory-3, "foobar")
+ compare(maxHistory-2, "barfoo")
+ compare(maxHistory-1, "foobarbaz")
+ }
+}