More tests for rg arg parsing
This commit is contained in:
parent
716a048e6c
commit
23d2293296
@ -119,7 +119,7 @@ func parse_args(args ...string) (delegate_to_rg bool, sanitized_args []string, k
|
||||
if with_equals {
|
||||
sanitized_args = append(sanitized_args, "--"+key+"="+val)
|
||||
} else {
|
||||
sanitized_args = append(sanitized_args, key, val)
|
||||
sanitized_args = append(sanitized_args, "--"+key, val)
|
||||
}
|
||||
}
|
||||
switch key {
|
||||
|
||||
@ -4,7 +4,10 @@ package hyperlinked_grep
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"kitty/tools/utils/shlex"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
@ -64,4 +67,24 @@ func TestRgArgParsing(t *testing.T) {
|
||||
check_kitten_opts(true, true, true, "--no-heading", "--pretty")
|
||||
check_kitten_opts(true, true, true, "--no-heading", "--heading")
|
||||
|
||||
check_args := func(args, expected string) {
|
||||
a, err := shlex.Split(args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, actual, _, err := parse_args(a...)
|
||||
if err != nil {
|
||||
t.Fatalf("error when parsing: %#v: %s", args, err)
|
||||
}
|
||||
ex, err := shlex.Split(expected)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if diff := cmp.Diff(ex, actual); diff != "" {
|
||||
t.Fatalf("args not correct for %s\n%s", args, diff)
|
||||
}
|
||||
}
|
||||
check_args("--count --max-depth 10 --XxX yyy abcd", "--count --max-depth 10 --XxX yyy abcd")
|
||||
check_args("--max-depth=10 --kitten hyperlink=none abcd", "--max-depth=10 abcd")
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user