コード例 #1
0
    def testParseCommand(self):
        c_parser = test_lib.InitCommandParser('ls foo')
        node = c_parser.ParseCommand()
        self.assertEqual(2, len(node.words))
        print(node)

        c_parser = test_lib.InitCommandParser('fun() { echo hi; }')
        node = c_parser.ParseCommand()
        print(node)
        self.assertEqual(command_e.ShFunction, node.tag)
コード例 #2
0
ファイル: cmd_exec_test.py プロジェクト: shamrin/oil
  def testBraceExpand(self):
    arena = test_lib.MakeArena('<cmd_exec_test.py>')
    c_parser = test_lib.InitCommandParser('echo _{a,b}_', arena=arena)
    node = c_parser._ParseCommandLine()
    print(node)

    ex = test_lib.InitExecutor(arena=arena)
コード例 #3
0
def _assert_ParseCommandListError(test, code_str):
    arena = test_lib.MakeArena('<cmd_parse_test>')
    c_parser = test_lib.InitCommandParser(code_str, arena=arena)

    try:
        node = c_parser._ParseCommandLine()
    except error.Parse as e:
        ui.PrettyPrintError(e, arena)
    else:
        print('UNEXPECTED:')
        node.PrettyPrint()
        test.fail("Expected %r to fail" % code_str)
コード例 #4
0
  def testShellFuncExecution(self):
    arena = test_lib.MakeArena('testShellFuncExecution')
    c_parser = test_lib.InitCommandParser("""\
    f() {
      COMPREPLY=(f1 f2)
    }
    """, arena=arena)
    func_node = c_parser.ParseLogicalLine()
    print(func_node)

    ex = test_lib.InitExecutor(arena=arena)

    a = completion.ShellFuncAction(ex, func_node)
    comp = self._MakeComp(['f'], 0, 'f')
    matches = list(a.Matches(comp))
    self.assertEqual(['f1', 'f2'], matches)
コード例 #5
0
ファイル: completion_test.py プロジェクト: sailfish009/oil
  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)
コード例 #6
0
def _assertParseMethod(test, code_str, method, expect_success=True):
    arena = test_lib.MakeArena('<cmd_parse_test>')
    c_parser = test_lib.InitCommandParser(code_str, arena=arena)
    m = getattr(c_parser, method)
    try:
        node = m()

    except error.Parse as e:
        ui.PrettyPrintError(e, arena)
        if expect_success:
            test.fail('%r failed' % code_str)
        node = None
    else:
        node.PrettyPrint()
        if not expect_success:
            test.fail('Expected %r to fail ' % code_str)

    return node
コード例 #7
0
ファイル: completion_test.py プロジェクト: o11c/oil
    def testShellFuncExecution(self):
        arena = test_lib.MakeArena('testShellFuncExecution')
        c_parser = test_lib.InitCommandParser("""\
    f() {
      COMPREPLY=(f1 f2)
    }
    """,
                                              arena=arena)
        func_node = c_parser.ParseLogicalLine()
        print(func_node)

        cmd_ev = test_lib.InitCommandEvaluator(arena=arena)

        comp_lookup = completion.Lookup()
        a = completion.ShellFuncAction(cmd_ev, func_node, comp_lookup)
        comp = self._CompApi(['f'], 0, 'f')
        matches = list(a.Matches(comp))
        self.assertEqual(['f1', 'f2'], matches)
コード例 #8
0
def _assertParseMethod(test, code_str, method, expect_success=True):
    arena = test_lib.MakeArena('<cmd_parse_test>')
    c_parser = test_lib.InitCommandParser(code_str, arena=arena)
    m = getattr(c_parser, method)
    try:
        if method == 'ParseSimpleCommand':
            node = m([])  # required cur_aliases arg
        else:
            node = m()

    except util.ParseError as e:
        ui.PrettyPrintError(e, arena, sys.stdout)
        if expect_success:
            test.fail('%r failed' % code_str)
        node = None
    else:
        ast_lib.PrettyPrint(node)
        if not expect_success:
            test.fail('Expected %r to fail ' % code_str)

    return node
コード例 #9
0
ファイル: process_test.py プロジェクト: grahamc/oil
def _CommandNode(code_str, arena):
  c_parser = test_lib.InitCommandParser(code_str, arena=arena)
  return c_parser.ParseLogicalLine()