Files
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

52 lines
1.0 KiB
Go

package indexer
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestShlexSplit(t *testing.T) {
cases := []struct {
name string
in string
want []string
}{
{
name: "quoted include dir with embedded space",
in: `clang -I"a b/inc" -isystem /x -c f.c`,
want: []string{"clang", "-Ia b/inc", "-isystem", "/x", "-c", "f.c"},
},
{
name: "single quotes are literal",
in: `cc -D'NAME=a b' main.c`,
want: []string{"cc", "-DNAME=a b", "main.c"},
},
{
name: "backslash-escaped space outside quotes",
in: `cc -I/a\ b -c f.c`,
want: []string{"cc", "-I/a b", "-c", "f.c"},
},
{
name: "escaped quote inside double quotes",
in: `cc -DS="a\"b" f.c`,
want: []string{"cc", `-DS=a"b`, "f.c"},
},
{
name: "collapses runs of whitespace",
in: " cc \t -c f.c ",
want: []string{"cc", "-c", "f.c"},
},
{
name: "empty",
in: " ",
want: nil,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.want, shlexSplit(tc.in))
})
}
}