
# Copyright (C) 2012-2016 - <NAME> <<EMAIL>>
# This program is Free Software see LICENSE file for details

import re
import sys

import jedi

from commands.goto import Goto
from handlers.jedi_handler import JediHandler

src = 'import re; re.compile'
PYTHON3 = sys.version_info >= (3, 0)


class TestGoto(object):
    """Goto test suite
    """

    def test_goto_command(self):
        Goto(self._check_goto, 0, jedi.Script(src))

    def test_goto_handler(self):
        data = {'source': src, 'line': 1, 'offset': 21}
        handler = JediHandler('goto', data, 0, 0, self._check_goto)
        handler.run()

    def _check_goto(self, result):
        assert result['success'] is True
        assert len(result['goto']) == 1
        if PYTHON3:
            assert result['goto'][0][0] == re.__file__
        else:
            file_name = re.__file__
            if '.pyc' in file_name:
                assert result['goto'][0][0] == file_name[:-1]
            else:
                assert result['goto'][0][0] == file_name
