pkg.re/essentialkaos/ek.v11@v12.41.0+incompatible/usage/completion/zsh/zsh_test.go (about) 1 package zsh 2 3 // ////////////////////////////////////////////////////////////////////////////////// // 4 // // 5 // Copyright (c) 2022 ESSENTIAL KAOS // 6 // Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> // 7 // // 8 // ////////////////////////////////////////////////////////////////////////////////// // 9 10 import ( 11 "testing" 12 13 "pkg.re/essentialkaos/ek.v12/options" 14 "pkg.re/essentialkaos/ek.v12/usage" 15 16 . "pkg.re/essentialkaos/check.v1" 17 ) 18 19 // ////////////////////////////////////////////////////////////////////////////////// // 20 21 const _RESULT = `#compdef test 22 23 # This completion is automatically generated 24 25 typeset -A opt_args 26 27 _test() { 28 _arguments \ 29 '(-a --option-aaa=)'{-a,--option-aaa=}'[Test option A]' \ 30 '(-b --option-bbb)'{-b,--option-bbb}'[Test option B]' \ 31 '(--option-ccc=)'--option-ccc'[Test option C]' \ 32 '1: :_test_cmds' \ 33 '*:: :->cmd_args' && ret=0 34 35 case $state in 36 cmd_args) 37 case $words[1] in 38 clean) 39 _arguments \ 40 '(-d --option-ddd)'{-d,--option-ddd}'[Test option D]' \ 41 '(-e --option-eee= -d --option-ddd --option-ccc)'{-e,--option-eee=}'[Test option E]' \ 42 ;; 43 esac 44 ;; 45 esac 46 47 _files -g "*.txt" 48 } 49 50 _test_cmds() { 51 local -a commands 52 commands=( 53 'print:Print command' 54 'clean:Clean command' 55 ) 56 _describe 'command' commands 57 } 58 59 _test "$@" 60 ` 61 62 // ////////////////////////////////////////////////////////////////////////////////// // 63 64 func Test(t *testing.T) { TestingT(t) } 65 66 type ZSHSuite struct{} 67 68 // ////////////////////////////////////////////////////////////////////////////////// // 69 70 var _ = Suite(&ZSHSuite{}) 71 72 // ////////////////////////////////////////////////////////////////////////////////// // 73 74 func (s *ZSHSuite) TestGenerator(c *C) { 75 data := Generate(genTestUsageInfo(), genTestOptions(), "test", "*.txt") 76 c.Assert(data, Equals, _RESULT) 77 } 78 79 func (s *ZSHSuite) TestAuxi(c *C) { 80 info := usage.NewInfo("") 81 82 c.Assert(genCommandsHandlers(info, nil), Equals, "") 83 c.Assert(genCommandsFunc(info), Equals, "") 84 85 c.Assert(genFilesHandler(info, nil), Equals, "") 86 87 info = usage.NewInfo("", "files") 88 89 c.Assert(genFilesHandler(info, []string{"*.txt"}), Equals, " _files -g \"*.txt\"") 90 c.Assert(genFilesHandler(info, nil), Equals, " _files") 91 } 92 93 // ////////////////////////////////////////////////////////////////////////////////// // 94 95 func genTestOptions() options.Map { 96 return options.Map{ 97 "a:option-aaa": {}, 98 "b:option-bbb": {Type: options.BOOL}, 99 "option-ccc": {}, 100 "e:option-eee": {Conflicts: "d:option-ddd option-ccc"}, 101 "d:option-ddd": {Type: options.BOOL}, 102 } 103 } 104 105 func genTestUsageInfo() *usage.Info { 106 info := usage.NewInfo("", "fileā¦") 107 108 info.AddCommand("print", "Print command") 109 info.AddCommand("clean", "Clean command") 110 111 info.AddOption("a:option-aaa", "Test option A") 112 info.AddOption("b:option-bbb", "Test option B", "?bbb") 113 info.AddOption("option-ccc", "Test option C") 114 115 info.AddOption("d:option-ddd", "Test option D") 116 info.AddOption("e:option-eee", "Test option E") 117 118 info.BoundOptions("clean", "d:option-ddd", "e:option-eee", "unknown") 119 120 return info 121 }