scriptencoding utf-8
Describe basic_asterisk

    Before all
        let lines = [
        \     '1.asterisk 2.asterisk 3.asterisk'
        \   , '4.Asterisk 5.AsteRisK 6.Asterisk'
        \   , ''
        \   , '7.アスタリスク 8.アスタリスクです 9.アスタリスク?'
        \   , '.* .* .*'
        \   , '.* asterisk asterisk'
        \ ]
        call g:Add_lines(lines)
    End

    Before each
        call cursor([1, 1])
        normal! 2l
    End

    After all
        :1,$ delete
    End

    Context *
        It search forward with \<\>
            let @/ = ''
            normal *
            Assert Equals(@/, '\<asterisk\>')
        End
        It search forward the 1th occurrence of the word
            normal *
            normal! 2h
            Assert Equals(g:Get_pos_char(), '2')
        End
        It search forward the 2th occurrence of the word
            normal 2*
            normal! 2h
            Assert Equals(g:Get_pos_char(), '3')
        End
        It search forward in the middle of word
            normal! l
            normal *
            normal! 2h
            Assert Equals(g:Get_pos_char(), '2')
        End
        It search forward multibyte word
            normal! 3j
            normal *
            normal! B
            Assert Equals(g:Get_pos_char(), '8')
        End
        It throws the error if there are no <cword>
            normal! 2j
            Throws /E348: No string under cursor/ :normal *
        End

        Context regular expression handling
          It use regular expression characters under cursor if there are no keyword word after them
            normal! 4j0
            normal *
            Assert Equals(@/, '\.\*')
          End
          It do not use regular expression characters under cursor if there are keyword words after them
            normal! 5j0
            normal *
            Assert Equals(@/, '\<asterisk\>')
          End
        End

    End

    Context g*
        It search forward without \<\>
            let @/ = ''
            normal g*
            Assert Equals(@/, 'asterisk')
        End
        It search forward the 1th occurrence of the word
            normal g*
            normal! 2h
            Assert Equals(g:Get_pos_char(), '2')
        End
        It search forward the 2th occurrence of the word
            normal 2*
            normal! 2h
            Assert Equals(g:Get_pos_char(), '3')
        End
        It search forward in the middle of word
            normal! l
            normal g*
            normal! 2h
            Assert Equals(g:Get_pos_char(), '2')
        End
        It throws the error if there are no <cword>
            normal! 2j
            Throws /E348: No string under cursor/ :normal g*
        End
        It search forward with the first keyword after the cursor
            normal! h
            normal *
            normal! 2h
            Assert Equals(g:Get_pos_char(), '2')
        End
        It search forward with ignorecase
            set ignorecase nosmartcase
            normal! j
            normal *
            normal! 2h
            Assert Equals(g:Get_pos_char(), '5')
            set ignorecase& smartcase&
        End
        It search forward with smartcase
            set ignorecase smartcase
            normal! j
            normal *
            normal! 2h
            Assert Equals(g:Get_pos_char(), '6')
            set ignorecase& smartcase&
        End
    End

    Context #
        It search backward with \<\>
            let @/ = ''
            normal #
            Assert Equals(@/, '\<asterisk\>')
        End
        It search backward the 1th occurrence of the word
            normal! $b
            normal #
            normal! 2h
            Assert Equals(g:Get_pos_char(), '2')
        End
        It search backward the 2th occurrence of the word
            normal! $b
            normal 2#
            normal! 2h
            Assert Equals(g:Get_pos_char(), '1')
        End
        It search backward at the end of word
            normal! $
            normal #
            normal! 2h
            Assert Equals(g:Get_pos_char(), '2')
        End
        It search backward in the middle of word
            normal! $h
            normal #
            normal! 2h
            Assert Equals(g:Get_pos_char(), '2')
        End
        It search backward with the first keyword after the cursor
            normal! $bh
            normal #
            normal! 2h
            Assert Equals(g:Get_pos_char(), '2')
        End
    End

    Context g#
        It search backward with \<\>
            let @/ = ''
            normal g#
            Assert Equals(@/, 'asterisk')
        End
    End

End
