| 1 |
package commands_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"strings" |
| 5 |
"testing" |
| 6 |
|
| 7 |
"git.sr.ht/~rjarry/aerc/commands" |
| 8 |
) |
| 9 |
|
| 10 |
func TestCommands_Operand(t *testing.T) { |
| 11 |
tests := []struct { |
| 12 |
args []string |
| 13 |
spec string |
| 14 |
want string |
| 15 |
}{ |
| 16 |
{ |
| 17 |
args: []string{"cmd", "-a", "-b", "arg1", "-c", "bla"}, |
| 18 |
spec: "ab:c", |
| 19 |
want: "cmdbla", |
| 20 |
}, |
| 21 |
{ |
| 22 |
args: []string{"cmd", "-a", "-b", "arg1", "-c", "--", "bla"}, |
| 23 |
spec: "ab:c", |
| 24 |
want: "bla", |
| 25 |
}, |
| 26 |
{ |
| 27 |
args: []string{"cmd", "-a", "-b", "arg1", "-c", "bla"}, |
| 28 |
spec: "ab:c:", |
| 29 |
want: "cmd", |
| 30 |
}, |
| 31 |
{ |
| 32 |
args: nil, |
| 33 |
spec: "ab:c:", |
| 34 |
want: "", |
| 35 |
}, |
| 36 |
} |
| 37 |
for i, test := range tests { |
| 38 |
arg := strings.Join(commands.Operands(test.args, test.spec), "") |
| 39 |
if arg != test.want { |
| 40 |
t.Errorf("failed test %d: want '%s', got '%s'", i, |
| 41 |
test.want, arg) |
| 42 |
} |
| 43 |
} |
| 44 |
} |