1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/gui/filetree/file_node_test.go

126 lines
2.8 KiB
Go
Raw Normal View History

2021-03-21 06:58:15 +02:00
package filetree
import (
"testing"
2021-03-21 06:58:15 +02:00
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/stretchr/testify/assert"
)
func TestCompress(t *testing.T) {
scenarios := []struct {
name string
root *FileNode
expected *FileNode
}{
{
name: "nil node",
root: nil,
expected: nil,
},
{
name: "leaf node",
root: &FileNode{
2021-03-21 01:46:43 +02:00
Path: "",
Children: []*FileNode{
2021-03-21 06:58:15 +02:00
{File: &models.File{Name: "test", ShortStatus: " M", HasStagedChanges: true}, Path: "test"},
},
},
expected: &FileNode{
2021-03-21 01:46:43 +02:00
Path: "",
Children: []*FileNode{
2021-03-21 06:58:15 +02:00
{File: &models.File{Name: "test", ShortStatus: " M", HasStagedChanges: true}, Path: "test"},
},
},
},
{
name: "big example",
root: &FileNode{
2021-03-21 01:46:43 +02:00
Path: "",
Children: []*FileNode{
{
Path: "dir1",
Children: []*FileNode{
{
2021-03-21 06:58:15 +02:00
File: &models.File{Name: "file2", ShortStatus: "M ", HasUnstagedChanges: true},
Path: "dir1/file2",
},
},
},
{
Path: "dir2",
Children: []*FileNode{
{
2021-03-21 06:58:15 +02:00
File: &models.File{Name: "file3", ShortStatus: " M", HasStagedChanges: true},
Path: "dir2/file3",
},
{
2021-03-21 06:58:15 +02:00
File: &models.File{Name: "file4", ShortStatus: "M ", HasUnstagedChanges: true},
Path: "dir2/file4",
},
},
},
{
Path: "dir3",
Children: []*FileNode{
{
Path: "dir3/dir3-1",
Children: []*FileNode{
{
2021-03-21 06:58:15 +02:00
File: &models.File{Name: "file5", ShortStatus: "M ", HasUnstagedChanges: true},
Path: "dir3/dir3-1/file5",
},
},
},
},
},
{
2021-03-21 06:58:15 +02:00
File: &models.File{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true},
Path: "file1",
},
},
},
expected: &FileNode{
2021-03-21 01:46:43 +02:00
Path: "",
Children: []*FileNode{
{
2021-03-21 02:00:00 +02:00
Path: "dir1/file2",
2021-03-21 06:58:15 +02:00
File: &models.File{Name: "file2", ShortStatus: "M ", HasUnstagedChanges: true},
2021-03-21 02:00:00 +02:00
CompressionLevel: 1,
},
{
Path: "dir2",
Children: []*FileNode{
{
2021-03-21 06:58:15 +02:00
File: &models.File{Name: "file3", ShortStatus: " M", HasStagedChanges: true},
Path: "dir2/file3",
},
{
2021-03-21 06:58:15 +02:00
File: &models.File{Name: "file4", ShortStatus: "M ", HasUnstagedChanges: true},
Path: "dir2/file4",
},
},
},
{
2021-03-21 02:00:00 +02:00
Path: "dir3/dir3-1/file5",
2021-03-21 06:58:15 +02:00
File: &models.File{Name: "file5", ShortStatus: "M ", HasUnstagedChanges: true},
2021-03-21 02:00:00 +02:00
CompressionLevel: 2,
},
{
2021-03-21 06:58:15 +02:00
File: &models.File{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true},
Path: "file1",
},
},
},
},
}
for _, s := range scenarios {
s := s
t.Run(s.name, func(t *testing.T) {
s.root.Compress()
assert.EqualValues(t, s.expected, s.root)
})
}
}