<commit_before>let mapleader = '\'
source plugin/jedi.vim
source test/utils.vim

describe 'goto_simple'
    before
        new  " open a new split
        set filetype=python
        put =[
        \   'def a(): pass',
        \   'b = a',
        \   'c = b',
        \ ]
        normal! ggdd
        normal! G$
        Expect line('.') == 3
    end

    after
        bd!
    end

    it 'goto_definitions'
        silent normal \d
        Expect line('.') == 1
        "Expect col('.') == 5  " not working yet.
    end

    it 'goto_assignments'
        silent normal \g
        Expect line('.') == 2
        Expect col('.') == 1

        " cursor before `=` means that it stays there.
        silent normal \g
        Expect line('.') == 2
        Expect col('.') == 1

        " going to the last line changes it.
        normal! $
        silent normal \g
        Expect line('.') == 1
        Expect col('.') == 5
    end
end


describe 'goto_with_tabs'
    before
        set filetype=python
    end

    after
        bd!
        bd!
    end

    it 'follow_import'
        put = ['import subprocess', 'subprocess']
        silent normal G\g
        Expect getline('.') == 'import subprocess'
        Expect line('.') == 2
        Expect col('.') == 8

        silent normal G\d
        Expect g:current_buffer_is_module('subprocess') == 1
        Expect line('.') == 1
        Expect col('.') == 1
        Expect tabpagenr('$') == 2
        tabprevious
        Expect bufname('%') == ''
    end

    it 'multi_definitions'
        put = ['import tokenize']
        silent normal G$\d
        Expect g:current_buffer_is_module('tokenize') == 0
        Expect g:current_buffer_is_module('token') == 0
        execute "normal \<CR>"
        Expect tabpagenr('$') == 2
        Expect g:current_buffer_is_module('token') == 1

        bd
        silent normal G$\d
        execute "normal j\<CR>"
        Expect tabpagenr('$') == 2
        Expect g:current_buffer_is_module('tokenize') == 1
    end
end


describe 'goto_with_buffers'
    before
        set filetype=python
        let g:jedi#use_tabs_not_buffers = 0
    end

    after
        bd!
        bd!
        set nohidden
    end

    it 'no_new_tabs'
        put = ['import os']
        normal G$
        call jedi#goto_assignments()
        python jedi_vim.goto()
        Expect g:current_buffer_is_module('os') == 0
        " Without hidden, it's not possible to open a new buffer, when the old
        " one is not saved.
        set hidden
        call jedi#goto_assignments()
        Expect g:current_buffer_is_module('os') == 1
        Expect tabpagenr('$') == 1
        Expect line('.') == 1
        Expect col('.') == 1
    end

    it 'multi_definitions'
        set hidden
        put = ['import tokenize']
        silent normal G$\d
        Expect g:current_buffer_is_module('tokenize') == 0
        Expect g:current_buffer_is_module('token') == 0
        execute "normal \<CR>"
        Expect tabpagenr('$') == 1
        Expect g:current_buffer_is_module('token') == 1

        bd
        silent normal G$\d
        execute "normal j\<CR>"
        Expect tabpagenr('$') == 1
        Expect g:current_buffer_is_module('tokenize') == 1
    end
end



describe 'goto_with_splits'
    before
        set filetype=python
        let g:jedi#use_splits_not_buffers = 'left'
    end
<commit_msg>added tests for checking other goto will perform in only one window, no other split buffer will be opened accidentially<commit_after>let mapleader = '\'
source plugin/jedi.vim
source test/utils.vim

describe 'goto_simple'
    before
        new  " open a new split
        set filetype=python
        put =[
        \   'def a(): pass',
        \   'b = a',
        \   'c = b',
        \ ]
        normal! ggdd
        normal! G$
        Expect line('.') == 3
    end

    after
        bd!
    end

    it 'goto_definitions'
        silent normal \d
        Expect line('.') == 1
        "Expect col('.') == 5  " not working yet.
    end

    it 'goto_assignments'
        silent normal \g
        Expect line('.') == 2
        Expect col('.') == 1

        " cursor before `=` means that it stays there.
        silent normal \g
        Expect line('.') == 2
        Expect col('.') == 1

        " going to the last line changes it.
        normal! $
        silent normal \g
        Expect line('.') == 1
        Expect col('.') == 5
    end
end


describe 'goto_with_tabs'
    before
        set filetype=python
    end

    after
        bd!
        bd!
    end

    it 'follow_import'
        put = ['import subprocess', 'subprocess']
        silent normal G\g
        Expect getline('.') == 'import subprocess'
        Expect line('.') == 2
        Expect col('.') == 8

        silent normal G\d
        Expect g:current_buffer_is_module('subprocess') == 1
        Expect line('.') == 1
        Expect col('.') == 1
        Expect tabpagenr('$') == 2
        Expect winnr('$') == 1
        tabprevious
        Expect bufname('%') == ''
    end

    it 'multi_definitions'
        put = ['import tokenize']
        silent normal G$\d
        Expect g:current_buffer_is_module('tokenize') == 0
        Expect g:current_buffer_is_module('token') == 0
        execute "normal \<CR>"
        Expect tabpagenr('$') == 2
        Expect winnr('$') == 1
        Expect g:current_buffer_is_module('token') == 1

        bd
        silent normal G$\d
        execute "normal j\<CR>"
        Expect tabpagenr('$') == 2
        Expect winnr('$') == 1
        Expect g:current_buffer_is_module('tokenize') == 1
    end
end


describe 'goto_with_buffers'
    before
        set filetype=python
        let g:jedi#use_tabs_not_buffers = 0
    end

    after
        bd!
        bd!
        set nohidden
    end

    it 'no_new_tabs'
        put = ['import os']
        normal G$
        call jedi#goto_assignments()
        python jedi_vim.goto()
        Expect g:current_buffer_is_module('os') == 0
        " Without hidden, it's not possible to open a new buffer, when the old
        " one is not saved.
        set hidden
        call jedi#goto_assignments()
        Expect g:current_buffer_is_module('os') == 1
        Expect winnr('$') == 1
        Expect tabpagenr('$') == 1
        Expect line('.') == 1
        Expect col('.') == 1
    end

    it 'multi_definitions'
        set hidden
        put = ['import tokenize']
        silent normal G$\d
        Expect g:current_buffer_is_module('tokenize') == 0
        Expect g:current_buffer_is_module('token') == 0
        execute "normal \<CR>"
        Expect tabpagenr('$') == 1
        Expect winnr('$') == 1
        Expect g:current_buffer_is_module('token') == 1

        bd
        silent normal G$\d
        execute "normal j\<CR>"
        Expect tabpagenr('$') == 1
        Expect winnr('$') == 1
        Expect g:current_buffer_is_module('tokenize') == 1
    end
end



describe 'goto_with_splits'
    before
        set filetype=python
        let g:jedi#use_splits_not_buffers = 'left'
    end

{'fraction_non_alphanumeric': 0.12008547008547009, 'fraction_numerical': 0.010256410256410256, 'mean_word_length': 1.775098814229249, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2827054', 'n_tokens_mistral': 2248, 'n_tokens_neox': 2149, 'n_words': 625}