mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-21 12:16:54 +02:00
feat: add test cases
This commit is contained in:
parent
717913e64c
commit
ba0cc20e22
@ -2,6 +2,7 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
@ -139,6 +140,7 @@ func (c *OSCommand) PrepareSubProcess(cmdName string, commandArgs ...string) *ex
|
|||||||
|
|
||||||
// Quote wraps a message in platform-specific quotation marks
|
// Quote wraps a message in platform-specific quotation marks
|
||||||
func (c *OSCommand) Quote(message string) string {
|
func (c *OSCommand) Quote(message string) string {
|
||||||
|
fmt.Println(c.Platform.os)
|
||||||
message = strings.Replace(message, "`", "\\`", -1)
|
message = strings.Replace(message, "`", "\\`", -1)
|
||||||
if c.Platform.os == "linux" {
|
if c.Platform.os == "linux" {
|
||||||
if strings.ContainsRune(message, '\'') {
|
if strings.ContainsRune(message, '\'') {
|
||||||
|
@ -265,6 +265,30 @@ func TestOSCommandQuote(t *testing.T) {
|
|||||||
assert.EqualValues(t, expected, actual)
|
assert.EqualValues(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOSCommandQuoteSingleQuote(t *testing.T) {
|
||||||
|
osCommand := newDummyOSCommand()
|
||||||
|
|
||||||
|
osCommand.Platform.os = "linux"
|
||||||
|
|
||||||
|
actual := osCommand.Quote("hello 'test'")
|
||||||
|
|
||||||
|
expected := osCommand.Platform.escapedQuote + "hello 'test'" + osCommand.Platform.escapedQuote
|
||||||
|
|
||||||
|
assert.EqualValues(t, expected, actual)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOSCommandQuoteDoubleQuote(t *testing.T) {
|
||||||
|
osCommand := newDummyOSCommand()
|
||||||
|
|
||||||
|
osCommand.Platform.os = "linux"
|
||||||
|
|
||||||
|
actual := osCommand.Quote(`hello "test"`)
|
||||||
|
|
||||||
|
expected := osCommand.Platform.escapedQuote + "hello \"test\"" + osCommand.Platform.escapedQuote
|
||||||
|
|
||||||
|
assert.EqualValues(t, expected, actual)
|
||||||
|
}
|
||||||
|
|
||||||
func TestOSCommandUnquote(t *testing.T) {
|
func TestOSCommandUnquote(t *testing.T) {
|
||||||
osCommand := newDummyOSCommand()
|
osCommand := newDummyOSCommand()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user