mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-04 22:34:39 +02:00
In go 1.22, loop variables are redeclared with each iteration of the loop, rather than simple updated on each iteration. This means that we no longer need to manually redeclare variables when they're closed over by a function.
81 lines
2.7 KiB
Go
81 lines
2.7 KiB
Go
package filetree
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestFilterAction(t *testing.T) {
|
|
scenarios := []struct {
|
|
name string
|
|
filter FileTreeDisplayFilter
|
|
files []*models.File
|
|
expected []*models.File
|
|
}{
|
|
{
|
|
name: "filter files with unstaged changes",
|
|
filter: DisplayUnstaged,
|
|
files: []*models.File{
|
|
{Name: "dir2/dir2/file4", ShortStatus: "M ", HasUnstagedChanges: true},
|
|
{Name: "dir2/file5", ShortStatus: "M ", HasStagedChanges: true},
|
|
{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true},
|
|
},
|
|
expected: []*models.File{
|
|
{Name: "dir2/dir2/file4", ShortStatus: "M ", HasUnstagedChanges: true},
|
|
{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true},
|
|
},
|
|
},
|
|
{
|
|
name: "filter files with staged changes",
|
|
filter: DisplayStaged,
|
|
files: []*models.File{
|
|
{Name: "dir2/dir2/file4", ShortStatus: "M ", HasStagedChanges: true},
|
|
{Name: "dir2/file5", ShortStatus: "M ", HasStagedChanges: false},
|
|
{Name: "file1", ShortStatus: "M ", HasStagedChanges: true},
|
|
},
|
|
expected: []*models.File{
|
|
{Name: "dir2/dir2/file4", ShortStatus: "M ", HasStagedChanges: true},
|
|
{Name: "file1", ShortStatus: "M ", HasStagedChanges: true},
|
|
},
|
|
},
|
|
{
|
|
name: "filter all files",
|
|
filter: DisplayAll,
|
|
files: []*models.File{
|
|
{Name: "dir2/dir2/file4", ShortStatus: "M ", HasUnstagedChanges: true},
|
|
{Name: "dir2/file5", ShortStatus: "M ", HasUnstagedChanges: true},
|
|
{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true},
|
|
},
|
|
expected: []*models.File{
|
|
{Name: "dir2/dir2/file4", ShortStatus: "M ", HasUnstagedChanges: true},
|
|
{Name: "dir2/file5", ShortStatus: "M ", HasUnstagedChanges: true},
|
|
{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true},
|
|
},
|
|
},
|
|
{
|
|
name: "filter conflicted files",
|
|
filter: DisplayConflicted,
|
|
files: []*models.File{
|
|
{Name: "dir2/dir2/file4", ShortStatus: "DU", HasMergeConflicts: true},
|
|
{Name: "dir2/file5", ShortStatus: "M ", HasUnstagedChanges: true},
|
|
{Name: "dir2/file6", ShortStatus: " M", HasStagedChanges: true},
|
|
{Name: "file1", ShortStatus: "UU", HasMergeConflicts: true, HasInlineMergeConflicts: true},
|
|
},
|
|
expected: []*models.File{
|
|
{Name: "dir2/dir2/file4", ShortStatus: "DU", HasMergeConflicts: true},
|
|
{Name: "file1", ShortStatus: "UU", HasMergeConflicts: true, HasInlineMergeConflicts: true},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, s := range scenarios {
|
|
t.Run(s.name, func(t *testing.T) {
|
|
mngr := &FileTree{getFiles: func() []*models.File { return s.files }, filter: s.filter}
|
|
result := mngr.getFilesForDisplay()
|
|
assert.EqualValues(t, s.expected, result)
|
|
})
|
|
}
|
|
}
|