From eb10ddfccc7623df769c839c95c475588f566bb2 Mon Sep 17 00:00:00 2001 From: Davyd McColl Date: Fri, 28 May 2021 13:39:15 +0200 Subject: [PATCH] :white_check_mark: add a test around ignoring whitespace --- pkg/commands/files_test.go | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/pkg/commands/files_test.go b/pkg/commands/files_test.go index 16583adc7..867b75e32 100644 --- a/pkg/commands/files_test.go +++ b/pkg/commands/files_test.go @@ -333,11 +333,12 @@ func TestGitCommandDiscardAllFileChanges(t *testing.T) { // TestGitCommandDiff is a function. func TestGitCommandDiff(t *testing.T) { type scenario struct { - testName string - command func(string, ...string) *exec.Cmd - file *models.File - plain bool - cached bool + testName string + command func(string, ...string) *exec.Cmd + file *models.File + plain bool + cached bool + ignoreWhitespace bool } scenarios := []scenario{ @@ -356,6 +357,7 @@ func TestGitCommandDiff(t *testing.T) { }, false, false, + false, }, { "cached", @@ -372,6 +374,7 @@ func TestGitCommandDiff(t *testing.T) { }, false, true, + false, }, { "plain", @@ -388,6 +391,7 @@ func TestGitCommandDiff(t *testing.T) { }, true, false, + false, }, { "File not tracked and file has no staged changes", @@ -404,6 +408,24 @@ func TestGitCommandDiff(t *testing.T) { }, false, false, + false, + }, + { + "Default case (ignore whitespace)", + func(cmd string, args ...string) *exec.Cmd { + assert.EqualValues(t, "git", cmd) + assert.EqualValues(t, []string{"diff", "--submodule", "--no-ext-diff", "--color=always", "-w", "--", "test.txt"}, args) + + return secureexec.Command("echo") + }, + &models.File{ + Name: "test.txt", + HasStagedChanges: false, + Tracked: true, + }, + false, + false, + true, }, } @@ -411,7 +433,7 @@ func TestGitCommandDiff(t *testing.T) { t.Run(s.testName, func(t *testing.T) { gitCmd := NewDummyGitCommand() gitCmd.OSCommand.Command = s.command - gitCmd.WorktreeFileDiff(s.file, s.plain, s.cached, false) + gitCmd.WorktreeFileDiff(s.file, s.plain, s.cached, s.ignoreWhitespace) }) } }