1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-11-28 09:08:41 +02:00

add tests for MergesStatusFiles

This commit is contained in:
Anthony HAMON 2018-08-28 20:55:14 +02:00 committed by Anthony HAMON
parent 45fa257128
commit d6b4d4b063
2 changed files with 77 additions and 2 deletions

View File

@ -121,10 +121,10 @@ func (c *GitCommand) MergeStatusFiles(oldFiles, newFiles []File) []File {
return newFiles
}
appendedIndexes := make([]int, 0)
appendedIndexes := []int{}
// retain position of files we already could see
result := make([]File, 0)
result := []File{}
for _, oldFile := range oldFiles {
for newIndex, newFile := range newFiles {
if oldFile.Name == newFile.Name {

View File

@ -185,6 +185,81 @@ func TestGitCommandStashSave(t *testing.T) {
assert.NoError(t, gitCmd.StashSave("A stash message"))
}
func TestGitCommandMergeStatusFiles(t *testing.T) {
type scenario struct {
oldFiles []File
newFiles []File
test func([]File)
}
scenarios := []scenario{
{
[]File{},
[]File{
{
Name: "new_file.txt",
},
},
func(files []File) {
expected := []File{
{
Name: "new_file.txt",
},
}
assert.Len(t, files, 1)
assert.EqualValues(t, expected, files)
},
},
{
[]File{
{
Name: "new_file1.txt",
},
{
Name: "new_file2.txt",
},
{
Name: "new_file3.txt",
},
},
[]File{
{
Name: "new_file4.txt",
},
{
Name: "new_file5.txt",
},
{
Name: "new_file1.txt",
},
},
func(files []File) {
expected := []File{
{
Name: "new_file1.txt",
},
{
Name: "new_file4.txt",
},
{
Name: "new_file5.txt",
},
}
assert.Len(t, files, 3)
assert.EqualValues(t, expected, files)
},
},
}
for _, s := range scenarios {
gitCmd := newDummyGitCommand()
s.test(gitCmd.MergeStatusFiles(s.oldFiles, s.newFiles))
}
}
func TestGitCommandDiff(t *testing.T) {
gitCommand := newDummyGitCommand()
assert.NoError(t, test.GenerateRepo("lots_of_diffs.sh"))