mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 02:36:57 -07:00
Add more ParseCommand tests
This commit is contained in:
parent
65ee524bf5
commit
e7177107a7
1 changed files with 52 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue