pkg.re/essentialkaos/ek@v12.36.0+incompatible/usage/completion/fish/fish_test.go (about)

     1  package fish
     2  
     3  // ////////////////////////////////////////////////////////////////////////////////// //
     4  //                                                                                    //
     5  //                         Copyright (c) 2021 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/usage"
    14  
    15  	. "pkg.re/essentialkaos/check.v1"
    16  )
    17  
    18  // ////////////////////////////////////////////////////////////////////////////////// //
    19  
    20  const _RESULT1 = `# Completion for test
    21  # This completion is automatically generated
    22  
    23  function __fish_test_no_command
    24    set cmd (commandline -opc)
    25    if [ (count $cmd) -eq 1 ]
    26      return 0
    27    end
    28    return 1
    29  end
    30  
    31  function __fish_test_using_command
    32    set cmd (commandline -opc)
    33    if [ (count $cmd) -gt 1 ]
    34      if [ $argv[1] = $cmd[2] ]
    35        return 0
    36      end
    37    end
    38    return 1
    39  end
    40  
    41  complete -f -n '__fish_test_no_command' -c test -l option-aaa -s a -d 'Test option A'
    42  complete -f -n '__fish_test_no_command' -c test -l option-bbb -s b -d 'Test option B'
    43  complete -f -n '__fish_test_no_command' -c test -l option-ccc -d 'Test option B'
    44  
    45  complete -f -n '__fish_test_no_command' -c test -a 'print' -d 'Print command'
    46  
    47  complete -f -n '__fish_test_no_command' -c test -a 'clean' -d 'Clean command'
    48  complete -f -n '__fish_test_using_command clean' -c test -l option-ddd -s e -d 'Test option D'
    49  complete -f -n '__fish_test_using_command clean' -c test -l option-eee -s d -d 'Test option E'
    50  
    51  
    52  `
    53  
    54  const _RESULT2 = `# Completion for test
    55  # This completion is automatically generated
    56  
    57  function __fish_test_no_command
    58    set cmd (commandline -opc)
    59    if [ (count $cmd) -eq 1 ]
    60      return 0
    61    end
    62    return 1
    63  end
    64  
    65  function __fish_test_using_command
    66    set cmd (commandline -opc)
    67    if [ (count $cmd) -gt 1 ]
    68      if [ $argv[1] = $cmd[2] ]
    69        return 0
    70      end
    71    end
    72    return 1
    73  end
    74  
    75  
    76  `
    77  
    78  // ////////////////////////////////////////////////////////////////////////////////// //
    79  
    80  func Test(t *testing.T) { TestingT(t) }
    81  
    82  type FishSuite struct{}
    83  
    84  // ////////////////////////////////////////////////////////////////////////////////// //
    85  
    86  var _ = Suite(&FishSuite{})
    87  
    88  // ////////////////////////////////////////////////////////////////////////////////// //
    89  
    90  func (s *FishSuite) TestGenerator(c *C) {
    91  	data := Generate(genTestUsageInfo(), "test")
    92  
    93  	c.Assert(data, Equals, _RESULT1)
    94  
    95  	data = Generate(usage.NewInfo(""), "test")
    96  
    97  	c.Assert(data, Equals, _RESULT2)
    98  }
    99  
   100  // ////////////////////////////////////////////////////////////////////////////////// //
   101  
   102  func genTestUsageInfo() *usage.Info {
   103  	info := usage.NewInfo("")
   104  
   105  	info.AddCommand("print", "Print command")
   106  	info.AddCommand("clean", "Clean command")
   107  
   108  	info.AddOption("a:option-aaa", "Test option A")
   109  	info.AddOption("b:option-bbb", "Test option B")
   110  	info.AddOption("option-ccc", "Test option B")
   111  
   112  	info.AddOption("e:option-ddd", "Test option D")
   113  	info.AddOption("d:option-eee", "Test option E")
   114  
   115  	info.BoundOptions("clean", "e:option-ddd", "d:option-eee", "option-hhh")
   116  
   117  	return info
   118  }