2021-03-21 06:58:15 +02:00
|
|
|
package filetree
|
2020-11-15 01:45:55 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-03-21 06:58:15 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
2020-11-15 01:45:55 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-03-14 10:38:59 +02:00
|
|
|
func TestCompress(t *testing.T) {
|
2020-11-15 01:45:55 +02:00
|
|
|
scenarios := []struct {
|
|
|
|
name string
|
2021-03-31 14:26:53 +02:00
|
|
|
root *FileNode
|
|
|
|
expected *FileNode
|
2020-11-15 01:45:55 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "nil node",
|
|
|
|
root: nil,
|
2021-03-14 10:38:59 +02:00
|
|
|
expected: nil,
|
2020-11-15 01:45:55 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "leaf node",
|
2021-03-31 14:26:53 +02:00
|
|
|
root: &FileNode{
|
2021-03-21 01:46:43 +02:00
|
|
|
Path: "",
|
2021-03-31 14:26:53 +02:00
|
|
|
Children: []*FileNode{
|
2021-03-21 06:58:15 +02:00
|
|
|
{File: &models.File{Name: "test", ShortStatus: " M", HasStagedChanges: true}, Path: "test"},
|
2020-11-15 01:45:55 +02:00
|
|
|
},
|
|
|
|
},
|
2021-03-31 14:26:53 +02:00
|
|
|
expected: &FileNode{
|
2021-03-21 01:46:43 +02:00
|
|
|
Path: "",
|
2021-03-31 14:26:53 +02:00
|
|
|
Children: []*FileNode{
|
2021-03-21 06:58:15 +02:00
|
|
|
{File: &models.File{Name: "test", ShortStatus: " M", HasStagedChanges: true}, Path: "test"},
|
2021-03-14 10:38:59 +02:00
|
|
|
},
|
|
|
|
},
|
2020-11-15 01:45:55 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "big example",
|
2021-03-31 14:26:53 +02:00
|
|
|
root: &FileNode{
|
2021-03-21 01:46:43 +02:00
|
|
|
Path: "",
|
2021-03-31 14:26:53 +02:00
|
|
|
Children: []*FileNode{
|
2020-11-15 01:45:55 +02:00
|
|
|
{
|
2021-03-14 10:38:59 +02:00
|
|
|
Path: "dir1",
|
2021-03-31 14:26:53 +02:00
|
|
|
Children: []*FileNode{
|
2020-11-15 01:45:55 +02:00
|
|
|
{
|
2021-03-21 06:58:15 +02:00
|
|
|
File: &models.File{Name: "file2", ShortStatus: "M ", HasUnstagedChanges: true},
|
2021-03-14 10:38:59 +02:00
|
|
|
Path: "dir1/file2",
|
2020-11-15 01:45:55 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-03-14 10:38:59 +02:00
|
|
|
Path: "dir2",
|
2021-03-31 14:26:53 +02:00
|
|
|
Children: []*FileNode{
|
2020-11-15 01:45:55 +02:00
|
|
|
{
|
2021-03-21 06:58:15 +02:00
|
|
|
File: &models.File{Name: "file3", ShortStatus: " M", HasStagedChanges: true},
|
2021-03-14 10:38:59 +02:00
|
|
|
Path: "dir2/file3",
|
2020-11-15 01:45:55 +02:00
|
|
|
},
|
|
|
|
{
|
2021-03-21 06:58:15 +02:00
|
|
|
File: &models.File{Name: "file4", ShortStatus: "M ", HasUnstagedChanges: true},
|
2021-03-14 10:38:59 +02:00
|
|
|
Path: "dir2/file4",
|
2020-11-15 01:45:55 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-03-14 11:23:06 +02:00
|
|
|
{
|
|
|
|
Path: "dir3",
|
2021-03-31 14:26:53 +02:00
|
|
|
Children: []*FileNode{
|
2021-03-14 11:23:06 +02:00
|
|
|
{
|
|
|
|
Path: "dir3/dir3-1",
|
2021-03-31 14:26:53 +02:00
|
|
|
Children: []*FileNode{
|
2021-03-14 11:23:06 +02:00
|
|
|
{
|
2021-03-21 06:58:15 +02:00
|
|
|
File: &models.File{Name: "file5", ShortStatus: "M ", HasUnstagedChanges: true},
|
2021-03-14 11:23:06 +02:00
|
|
|
Path: "dir3/dir3-1/file5",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-11-15 01:45:55 +02:00
|
|
|
{
|
2021-03-21 06:58:15 +02:00
|
|
|
File: &models.File{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true},
|
2021-03-14 10:38:59 +02:00
|
|
|
Path: "file1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-03-31 14:26:53 +02:00
|
|
|
expected: &FileNode{
|
2021-03-21 01:46:43 +02:00
|
|
|
Path: "",
|
2021-03-31 14:26:53 +02:00
|
|
|
Children: []*FileNode{
|
2021-03-14 10:38:59 +02:00
|
|
|
{
|
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,
|
2021-03-14 10:38:59 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Path: "dir2",
|
2021-03-31 14:26:53 +02:00
|
|
|
Children: []*FileNode{
|
2021-03-14 10:38:59 +02:00
|
|
|
{
|
2021-03-21 06:58:15 +02:00
|
|
|
File: &models.File{Name: "file3", ShortStatus: " M", HasStagedChanges: true},
|
2021-03-14 10:38:59 +02:00
|
|
|
Path: "dir2/file3",
|
|
|
|
},
|
|
|
|
{
|
2021-03-21 06:58:15 +02:00
|
|
|
File: &models.File{Name: "file4", ShortStatus: "M ", HasUnstagedChanges: true},
|
2021-03-14 10:38:59 +02:00
|
|
|
Path: "dir2/file4",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-03-14 11:23:06 +02:00
|
|
|
{
|
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-14 11:23:06 +02:00
|
|
|
},
|
2021-03-14 10:38:59 +02:00
|
|
|
{
|
2021-03-21 06:58:15 +02:00
|
|
|
File: &models.File{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true},
|
2021-03-14 10:38:59 +02:00
|
|
|
Path: "file1",
|
2020-11-15 01:45:55 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range scenarios {
|
|
|
|
s := s
|
|
|
|
t.Run(s.name, func(t *testing.T) {
|
2021-03-14 10:38:59 +02:00
|
|
|
s.root.Compress()
|
|
|
|
assert.EqualValues(t, s.expected, s.root)
|
2020-11-15 01:45:55 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|