def test_strip_tokens(self):
     cmds = mock_commands()
     completer = Completer(cmds, None)
     self.assertEqual(completer._strip_options(['cd', 'x']), ['cd', 'x'])
     self.assertEqual(completer._strip_options(['cd', '-l']), ['cd'])
     self.assertEqual(completer._strip_options(['cd', '--long', 'x']),
                      ['cd'])
    def test_cmd_completion(self):
        line = ''
        cmds = mock_commands()

        current = ItemMock([], [])
        completer = Completer(cmds, current)
        self.assertEqual(completer.complete(line, '', 0), 'cd')
        self.assertEqual(completer.complete(line, '', 1), 'ls')
        self.assertEqual(completer.complete(line, '', 2), None)
    def test_cmd_completion(self):
        line = ''
        cmds = mock_commands()

        current = ItemMock([], [])
        completer = Completer(cmds, current)
        self.assertEqual(completer.complete(line, '', 0), 'cd')
        self.assertEqual(completer.complete(line, '', 1), 'ls')
        self.assertEqual(completer.complete(line, '', 2), None)
    def test_multi_path_completion(self):
        line = 'ls a/b/c'
        cmds = mock_commands()
        conts = ['container']
        leaves = ['leaf']

        current = ItemMock(conts, leaves)
        completer = Completer(cmds, current)
        completer._next_item = MockNextItem(conts, leaves)
        self.assertEqual(completer.complete(line, 'co', 0), 'container/')
        self.assertEqual(completer.complete(line, 'co', 1), None)
    def test_leaf_with_spaces_completion(self):
        line = 'ls '
        cmds = mock_commands()
        conts = ['container']
        leaves = ['le af']

        current = ItemMock(conts, leaves)
        completer = Completer(cmds, current)
        completer._next_item = MockNextItem(conts, leaves)
        self.assertEqual(completer.complete(line, 'le', 0), 'le\\ af')
        self.assertEqual(completer.complete(line, 'le', 1), None)
    def test_multi_path_completion(self):
        line = 'ls a/b/c'
        cmds = mock_commands()
        conts = ['container']
        leaves = ['leaf']

        current = ItemMock(conts, leaves)
        completer = Completer(cmds, current)
        completer._next_item = MockNextItem(conts, leaves)
        self.assertEqual(completer.complete(line, 'co', 0), 'container/')
        self.assertEqual(completer.complete(line, 'co', 1), None)
    def test_leaf_with_spaces_completion(self):
        line = 'ls '
        cmds = mock_commands()
        conts = ['container']
        leaves = ['le af']

        current = ItemMock(conts, leaves)
        completer = Completer(cmds, current)
        completer._next_item = MockNextItem(conts, leaves)
        self.assertEqual(completer.complete(line, 'le', 0), 'le\\ af')
        self.assertEqual(completer.complete(line, 'le', 1), None)
    def test_option_completion(self):
        line = 'ls '
        cmds = mock_commands()
        conts = ['container']
        leaves = ['leaf']

        current = ItemMock(conts, leaves)
        completer = Completer(cmds, current)
        completer._next_item = MockNextItem(conts, leaves)
        self.assertEqual(completer.complete(line, '-', 0), '--long')
        self.assertEqual(completer.complete(line, '-', 1), '-l')
        self.assertEqual(completer.complete(line, '-', 2), None)
    def test_option_completion(self):
        line = 'ls '
        cmds = mock_commands()
        conts = ['container']
        leaves = ['leaf']

        current = ItemMock(conts, leaves)
        completer = Completer(cmds, current)
        completer._next_item = MockNextItem(conts, leaves)
        self.assertEqual(completer.complete(line, '-', 0), '--long')
        self.assertEqual(completer.complete(line, '-', 1), '-l')
        self.assertEqual(completer.complete(line, '-', 2), None)
 def test_strip_tokens(self):
     cmds = mock_commands()
     completer = Completer(cmds, None)
     self.assertEqual(completer._strip_options(['cd', 'x']), ['cd', 'x'])
     self.assertEqual(completer._strip_options(['cd', '-l']), ['cd'])
     self.assertEqual(completer._strip_options(['cd', '--long', 'x']), ['cd'])