Add more ParseCommand tests

This commit is contained in:
Edznux 2018-10-25 18:46:13 +02:00
commit e7177107a7

View file

@ -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)
}
})
}