github.com/kolbycrouch/elvish@v0.14.1-0.20210614162631-215b9ac1c423/pkg/edit/complete_getopt_test.go (about) 1 package edit 2 3 import ( 4 "testing" 5 6 "src.elv.sh/pkg/eval/vals" 7 ) 8 9 func TestCompleteGetopt(t *testing.T) { 10 f := setup() 11 defer f.Cleanup() 12 13 evals(f.Evaler, 14 `fn complete [@args]{ 15 opt-specs = [ [&short=a &long=all &desc="Show all"] 16 [&short=n &long=name &desc="Set name" &arg-required=$true 17 &completer= [_]{ put name1 name2 }] ] 18 arg-handlers = [ [_]{ put first1 first2 } 19 [_]{ put second1 second2 } ... ] 20 edit:complete-getopt $args $opt-specs $arg-handlers 21 }`, 22 `@arg1 = (complete '')`, 23 `@opts = (complete -)`, 24 `@long-opts = (complete --)`, 25 `@short-opt-arg = (complete -n '')`, 26 `@long-opt-arg = (complete --name '')`, 27 `@arg1-after-opt = (complete -a '')`, 28 `@arg2 = (complete arg1 '')`, 29 `@vararg = (complete arg1 arg2 '')`, 30 ) 31 testGlobals(t, f.Evaler, map[string]interface{}{ 32 "arg1": vals.MakeList("first1", "first2"), 33 "opts": vals.MakeList( 34 complexItem{Stem: "-a", Display: "-a (Show all)"}, 35 complexItem{Stem: "--all", Display: "--all (Show all)"}, 36 complexItem{Stem: "-n", Display: "-n (Set name)"}, 37 complexItem{Stem: "--name", Display: "--name (Set name)"}), 38 "long-opts": vals.MakeList( 39 complexItem{Stem: "--all", Display: "--all (Show all)"}, 40 complexItem{Stem: "--name", Display: "--name (Set name)"}), 41 "short-opt-arg": vals.MakeList("name1", "name2"), 42 "long-opt-arg": vals.MakeList("name1", "name2"), 43 "arg1-after-opt": vals.MakeList("first1", "first2"), 44 "arg2": vals.MakeList("second1", "second2"), 45 "vararg": vals.MakeList("second1", "second2"), 46 }) 47 }