Skip to content

Minor testcase cleanups #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 7 additions & 40 deletions shellwords_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ var testcases = []struct {
line string
expected []string
}{
{``, []string{}},
{`""`, []string{``}},
{`''`, []string{``}},
{`var --bar=baz`, []string{`var`, `--bar=baz`}},
{`var --bar="baz"`, []string{`var`, `--bar=baz`}},
{`var "--bar=baz"`, []string{`var`, `--bar=baz`}},
Expand All @@ -25,10 +28,12 @@ var testcases = []struct {
{`var --"bar baz"`, []string{`var`, `--bar baz`}},
{`a "b"`, []string{`a`, `b`}},
{`a " b "`, []string{`a`, ` b `}},
{`a " "`, []string{`a`, ` `}}, // FAILS !
{`a " "`, []string{`a`, ` `}},
{`a 'b'`, []string{`a`, `b`}},
{`a ' b '`, []string{`a`, ` b `}},
{`a ' '`, []string{`a`, ` `}}, // FAILS !
{`a ' '`, []string{`a`, ` `}},
{"foo bar\\ ", []string{`foo`, `bar `}},
{`foo "" bar ''`, []string{`foo`, ``, `bar`, ``}},
}

func TestSimple(t *testing.T) {
Expand Down Expand Up @@ -59,44 +64,6 @@ func TestError(t *testing.T) {
}
}

func TestLastSpace(t *testing.T) {
args, err := Parse("foo bar\\ ")
if err != nil {
t.Fatal(err)
}
if len(args) != 2 {
t.Fatal("Should have two elements")
}
if args[0] != "foo" {
t.Fatal("1st element should be `foo`")
}
if args[1] != "bar " {
t.Fatal("1st element should be `bar `")
}
}

func TestEmptyArgs(t *testing.T) {
args, err := Parse(`foo "" bar ''`)
if err != nil {
t.Fatal(err)
}
if len(args) != 4 {
t.Fatal("Should have three elements")
}
if args[0] != "foo" {
t.Fatal("1st element should be `foo`")
}
if args[1] != "" {
t.Fatal("2nd element should be empty")
}
if args[2] != "bar" {
t.Fatal("3rd element should be `bar`")
}
if args[3] != "" {
t.Fatal("4th element should be empty")
}
}

func TestShellRun(t *testing.T) {
dir, err := os.Getwd()
if err != nil {
Expand Down