Skip to content

Commit

Permalink
Increment history after selecting entry
Browse files Browse the repository at this point in the history
  • Loading branch information
gjhenrique committed Jan 25, 2023
1 parent ad1b320 commit 851401e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func (l *Launcher) ProcessEntries(entries []*sh.Entry) error {
return err
}

l.historyStore.IncrementEntry(m.Key, []byte(entry.Id))

return nil
}

Expand Down
25 changes: 25 additions & 0 deletions launcher/launcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,31 @@ func TestLaunch(t *testing.T) {
require.NoError(t, err)
}

func TestLaunchWithHistory(t *testing.T) {
workspace := test.SetupWorkspace(t)
defer workspace.RemoveWorkspace()

randomFile := workspace.RandomFile(t)
script := workspace.WriteScript(t, fmt.Sprintf("echo -en $1 > %s", randomFile))

m := mockMode(script, "", "test")
m[0].HistoryEnabled = true
l := createLauncher(m, workspace.CacheDir, workspace)

entries := []*sh.Entry{{ModeKey: "test", Id: "b", Text: "b"}}
err := l.ProcessEntries(entries)
require.NoError(t, err)

script2 := workspace.WriteScript(t, "echo -en \"a\\nb\\nc\\nd\"")
m[0].Exec = fmt.Sprintf("bash %s", script2)

entries, err = l.ListEntries("")
require.NoError(t, err)

require.Len(t, entries, 4)
require.Equal(t, *entries[0], sh.Entry{ModeKey: "test", Id: "b", Text: "b"})
}

func TestLaunchWithNoMatch(t *testing.T) {
workspace := test.SetupWorkspace(t)
defer workspace.RemoveWorkspace()
Expand Down

0 comments on commit 851401e

Please sign in to comment.