2019-11-03 02:32:11 +08:00
|
|
|
package cliedit
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-11-10 06:28:27 +08:00
|
|
|
"github.com/elves/elvish/eval/vals"
|
2019-11-03 02:32:11 +08:00
|
|
|
"github.com/elves/elvish/styled"
|
|
|
|
"github.com/elves/elvish/util"
|
|
|
|
)
|
|
|
|
|
2019-11-10 06:28:27 +08:00
|
|
|
func TestCompletionAddon(t *testing.T) {
|
2019-11-08 23:49:43 +08:00
|
|
|
f := setup()
|
|
|
|
defer f.Cleanup()
|
2019-11-04 22:07:28 +08:00
|
|
|
util.ApplyDir(util.Dir{"a": "", "b": ""})
|
2019-11-03 02:32:11 +08:00
|
|
|
|
2019-11-08 23:49:43 +08:00
|
|
|
feedInput(f.TTYCtrl, "echo \t")
|
2019-11-03 08:19:17 +08:00
|
|
|
wantBuf := bb().
|
2019-11-03 02:32:11 +08:00
|
|
|
WriteStyled(styled.MarkLines(
|
2019-11-03 08:01:02 +08:00
|
|
|
"~> echo a ", styles,
|
2019-11-03 08:14:01 +08:00
|
|
|
" gggg --",
|
2019-11-03 02:32:11 +08:00
|
|
|
"COMPLETING argument ", styles,
|
|
|
|
"mmmmmmmmmmmmmmmmmmm ")).
|
|
|
|
SetDotToCursor().
|
|
|
|
Newline().
|
|
|
|
WriteStyled(styled.MarkLines(
|
|
|
|
"a b", styles,
|
|
|
|
"# ",
|
|
|
|
)).
|
|
|
|
Buffer()
|
2019-11-08 23:49:43 +08:00
|
|
|
f.TTYCtrl.TestBuffer(t, wantBuf)
|
2019-11-03 02:32:11 +08:00
|
|
|
}
|
2019-11-10 06:28:27 +08:00
|
|
|
|
|
|
|
func TestCompleteFilename(t *testing.T) {
|
|
|
|
f := setup()
|
|
|
|
defer f.Cleanup()
|
|
|
|
util.ApplyDir(util.Dir{"d": util.Dir{"a": "", "b": ""}})
|
|
|
|
|
|
|
|
evals(f.Evaler, `@cands = (edit:complete-filename ls ./d/a)`)
|
|
|
|
wantCands := vals.MakeList(
|
2019-11-10 07:08:13 +08:00
|
|
|
complexItem{Stem: "./d/a", CodeSuffix: " "},
|
|
|
|
complexItem{Stem: "./d/b", CodeSuffix: " "})
|
2019-11-10 06:28:27 +08:00
|
|
|
if cands := getGlobal(f.Evaler, "cands"); !vals.Equal(cands, wantCands) {
|
|
|
|
t.Errorf("got cands %s, want %s",
|
|
|
|
vals.Repr(cands, vals.NoPretty), vals.Repr(wantCands, vals.NoPretty))
|
|
|
|
}
|
|
|
|
}
|
2019-11-10 07:08:13 +08:00
|
|
|
|
|
|
|
func TestComplexCandidate(t *testing.T) {
|
|
|
|
f := setup()
|
|
|
|
defer f.Cleanup()
|
|
|
|
|
|
|
|
evals(f.Evaler,
|
|
|
|
`cand = (edit:complex-candidate a/b/c &code-suffix=' ' &display-suffix='x')`,
|
|
|
|
// Identical to $cand.
|
|
|
|
`cand2 = (edit:complex-candidate a/b/c &code-suffix=' ' &display-suffix='x')`,
|
|
|
|
// Different from $cand.
|
|
|
|
`cand3 = (edit:complex-candidate a/b/c)`,
|
|
|
|
`kind = (kind-of $cand)`,
|
|
|
|
`@keys = (keys $cand)`,
|
|
|
|
`repr = (repr $cand)`,
|
|
|
|
`eq2 = (eq $cand $cand2)`,
|
|
|
|
`eq2h = [&$cand=$true][$cand2]`,
|
|
|
|
`eq3 = (eq $cand $cand3)`,
|
|
|
|
`stem code-suffix display-suffix = $cand[stem code-suffix display-suffix]`,
|
|
|
|
)
|
|
|
|
testGlobals(t, f.Evaler, map[string]interface{}{
|
|
|
|
"kind": "map",
|
|
|
|
"keys": vals.MakeList("stem", "code-suffix", "display-suffix"),
|
|
|
|
"repr": "(edit:complex-candidate a/b/c &code-suffix=' ' &display-suffix=x)",
|
|
|
|
"eq2": true,
|
|
|
|
"eq2h": true,
|
|
|
|
"eq3": false,
|
|
|
|
|
|
|
|
"stem": "a/b/c",
|
|
|
|
"code-suffix": " ",
|
|
|
|
"display-suffix": "x",
|
|
|
|
})
|
|
|
|
}
|