Skip to content
Myr

reader_test.go

This file

Path

src/reader_test.go

56 lines · 1.1 KiB · Go

Last changed by

Not known.

History of this file

Take it

1package fzf23import (4	"testing"56	"github.com/junegunn/fzf/src/util"7)89func TestReadFromCommand(t *testing.T) {10	strs := []string{}11	eb := util.NewEventBox()12	reader := Reader{13		pusher:   func(s []byte) bool { strs = append(strs, string(s)); return true },14		eventBox: eb}1516	// Check EventBox17	if eb.Peek(EvtReadNew) {18		t.Error("EvtReadNew should not be set yet")19	}2021	// Normal command22	reader.readFromCommand(`echo abc && echo def`)23	if len(strs) != 2 || strs[0] != "abc" || strs[1] != "def" {24		t.Errorf("%s", strs)25	}2627	// Check EventBox again28	if !eb.Peek(EvtReadNew) {29		t.Error("EvtReadNew should be set yet")30	}3132	// Wait should return immediately33	eb.Wait(func(events *util.Events) {34		if _, found := (*events)[EvtReadNew]; !found {35			t.Errorf("%s", events)36		}37		events.Clear()38	})3940	// EventBox is cleared41	if eb.Peek(EvtReadNew) {42		t.Error("EvtReadNew should not be set yet")43	}4445	// Failing command46	reader.readFromCommand(`no-such-command`)47	strs = []string{}48	if len(strs) > 0 {49		t.Errorf("%s", strs)50	}5152	// Check EventBox again53	if eb.Peek(EvtReadNew) {54		t.Error("Command failed. EvtReadNew should be set")55	}56}