def testShellFuncExecution(self): arena = test_lib.MakeArena('testShellFuncExecution') c_parser = test_lib.InitCommandParser("""\ f() { COMPREPLY=(f1 f2) } """, arena=arena) node = c_parser.ParseLogicalLine() proc = Proc(node.name, node.spids[1], proc_sig.Open(), node.body, [], True) cmd_ev = test_lib.InitCommandEvaluator(arena=arena) comp_lookup = completion.Lookup() a = completion.ShellFuncAction(cmd_ev, proc, comp_lookup) comp = self._CompApi(['f'], 0, 'f') matches = list(a.Matches(comp)) self.assertEqual(['f1', 'f2'], matches)
def Proc(self, pnode): # type: (PNode) -> proc_sig_t """ oil_proc: ['(' [proc_params] ')'] '{' """ typ = pnode.typ children = pnode.children assert typ == grammar_nt.oil_proc n = len(children) if n == 1: # proc f { sig = proc_sig.Open() # type: proc_sig_t elif n == 3: # proc f () { sig = proc_sig.Closed() # no params elif n == 4: # proc f [foo, bar='z', @args] { sig = self._ProcParams(children[1]) else: raise AssertionError(n) return sig