Sha256: 5fbce1ac841f6ec11f79512662533d2ae6c32100ae165a1d2edf639ba8eff6df

Contents?: true

Size: 1.49 KB

Versions: 87

Compression:

Stored size: 1.49 KB

Contents

package fzf

import (
	"io/ioutil"
	"os"
	"runtime"
	"testing"
)

func TestHistory(t *testing.T) {
	maxHistory := 50

	// Invalid arguments
	var paths []string
	if runtime.GOOS == "windows" {
		// GOPATH should exist, so we shouldn't be able to override it
		paths = []string{os.Getenv("GOPATH")}
	} else {
		paths = []string{"/etc", "/proc"}
	}

	for _, path := range paths {
		if _, e := NewHistory(path, maxHistory); e == nil {
			t.Error("Error expected for: " + path)
		}
	}

	f, _ := ioutil.TempFile("", "fzf-history")
	f.Close()

	{ // Append lines
		h, _ := NewHistory(f.Name(), maxHistory)
		for i := 0; i < maxHistory+10; i++ {
			h.append("foobar")
		}
	}
	{ // Read lines
		h, _ := NewHistory(f.Name(), 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(f.Name(), maxHistory)
		h.append("barfoo")
		h.append("")
		h.append("foobarbaz")
	}
	{ // Read lines again
		h, _ := NewHistory(f.Name(), 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")
	}
}

Version data entries

87 entries across 87 versions & 1 rubygems

Version Path
doing-2.1.88 lib/helpers/fzf/src/history_test.go
doing-2.1.87 lib/helpers/fzf/src/history_test.go
doing-2.1.86 lib/helpers/fzf/src/history_test.go
doing-2.1.85 lib/helpers/fzf/src/history_test.go
doing-2.1.84 lib/helpers/fzf/src/history_test.go
doing-2.1.83 lib/helpers/fzf/src/history_test.go
doing-2.1.82 lib/helpers/fzf/src/history_test.go
doing-2.1.81 lib/helpers/fzf/src/history_test.go
doing-2.1.80 lib/helpers/fzf/src/history_test.go
doing-2.1.79 lib/helpers/fzf/src/history_test.go
doing-2.1.78 lib/helpers/fzf/src/history_test.go
doing-2.1.77 lib/helpers/fzf/src/history_test.go
doing-2.1.76 lib/helpers/fzf/src/history_test.go
doing-2.1.75 lib/helpers/fzf/src/history_test.go
doing-2.1.74 lib/helpers/fzf/src/history_test.go
doing-2.1.73 lib/helpers/fzf/src/history_test.go
doing-2.1.72 lib/helpers/fzf/src/history_test.go
doing-2.1.69 lib/helpers/fzf/src/history_test.go
doing-2.1.68 lib/helpers/fzf/src/history_test.go
doing-2.1.66 lib/helpers/fzf/src/history_test.go