Skip to content

Commit

Permalink
Add more ParseCommand tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Edznux committed Oct 25, 2018
1 parent 65ee524 commit e717710
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,56 @@ func TestParseCommands(t *testing.T) {
t.Fatalf("expected %s got %s", cmd, got)
}
})
t.Run("handles semicolon inside single quotes", func(t *testing.T) {
cmd := "set ticker.commands 'clear; net.show'"
commands := ParseCommands(cmd)
if l := len(commands); l != 1 {
t.Fatalf("expected 1 command, got %d", l)
}
// Expect double-quotes stripped
expected := "set ticker.commands clear; net.show"
if got := commands[0]; got != expected {
fmt.Println(got)
t.Fatalf("expected %s got %s", cmd, got)
}
})
t.Run("handles semicolon inside single quotes inside quote", func(t *testing.T) {
cmd := "set ticker.commands \"'clear; net.show'\""
commands := ParseCommands(cmd)
if l := len(commands); l != 1 {
t.Fatalf("expected 1 command, got %d", l)
}
// Expect double-quotes stripped
expected := "set ticker.commands 'clear; net.show'"
if got := commands[0]; got != expected {
fmt.Println(got)
t.Fatalf("expected %s got %s", cmd, got)
}
})
t.Run("handles semicolon inside quotes inside single quote", func(t *testing.T) {
cmd := "set ticker.commands '\"clear; net.show\"'"
commands := ParseCommands(cmd)
if l := len(commands); l != 1 {
t.Fatalf("expected 1 command, got %d", l)
}
// Expect double-quotes stripped
expected := "set ticker.commands \"clear; net.show\""
if got := commands[0]; got != expected {
fmt.Println(got)
t.Fatalf("expected %s got %s", cmd, got)
}
})
t.Run("handle mismatching quote", func(t *testing.T) {
cmd := "set ticker.commands \"clear; echo it's working ?\""
commands := ParseCommands(cmd)
if l := len(commands); l != 1 {
t.Fatalf("expected 1 command, got %d", l)
}
// Expect double-quotes stripped
expected := "set ticker.commands clear; echo it's working ?"
if got := commands[0]; got != expected {
fmt.Println(got)
t.Fatalf("expected %s got %s", cmd, got)
}
})
}

0 comments on commit e717710

Please sign in to comment.