elvish/pkg/eval/var_parse_test.go
Qi Xiao 6e36058d0a pkg/tt: Improve API.
- Use reflection to derive function name.

- Take test cases as variadic arguments, instead of requiring them to be wrapped
  in a Table.

- Support naming test cases.

- Run test cases as subtests with t.Run.
2024-01-11 15:42:43 +00:00

56 lines
1.2 KiB
Go

package eval_test
import (
"testing"
. "src.elv.sh/pkg/eval"
"src.elv.sh/pkg/tt"
)
func TestSplitSigil(t *testing.T) {
tt.Test(t, SplitSigil,
Args("").Rets("", ""),
Args("x").Rets("", "x"),
Args("@x").Rets("@", "x"),
Args("a:b").Rets("", "a:b"),
Args("@a:b").Rets("@", "a:b"),
)
}
func TestSplitQName(t *testing.T) {
tt.Test(t, SplitQName,
Args("").Rets("", ""),
Args("a").Rets("a", ""),
Args("a:").Rets("a:", ""),
Args("a:b").Rets("a:", "b"),
Args("a:b:").Rets("a:", "b:"),
Args("a:b:c").Rets("a:", "b:c"),
Args("a:b:c:").Rets("a:", "b:c:"),
)
}
func TestSplitQNameSegs(t *testing.T) {
tt.Test(t, SplitQNameSegs,
Args("").Rets([]string{}),
Args("a").Rets([]string{"a"}),
Args("a:").Rets([]string{"a:"}),
Args("a:b").Rets([]string{"a:", "b"}),
Args("a:b:").Rets([]string{"a:", "b:"}),
Args("a:b:c").Rets([]string{"a:", "b:", "c"}),
Args("a:b:c:").Rets([]string{"a:", "b:", "c:"}),
)
}
func TestSplitIncompleteQNameNs(t *testing.T) {
tt.Test(t, SplitIncompleteQNameNs,
Args("").Rets("", ""),
Args("a").Rets("", "a"),
Args("a:").Rets("a:", ""),
Args("a:b").Rets("a:", "b"),
Args("a:b:").Rets("a:b:", ""),
Args("a:b:c").Rets("a:b:", "c"),
Args("a:b:c:").Rets("a:b:c:", ""),
)
}