Add tests for lsp#utils#byteindex()

This commit is contained in:
machakann
2019-08-17 14:05:55 +08:00
parent 83a3a2b004
commit ccb2460fa6
3 changed files with 32 additions and 0 deletions

View File

@@ -1,2 +1,3 @@
set encoding=utf-8
call themis#option('recursive', 1)
call themis#helper('command').with(themis#helper('assert'))

View File

@@ -81,4 +81,32 @@ Describe lsp#utils
endfor
End
End
Describe lsp#utils#byteindex
It should return the byte-index from the given character-index on a buffer
call setline(1, ['a β c', 'δ', ''])
Assert lsp#utils#byteindex('%', 1, 0) == 1
Assert lsp#utils#byteindex('%', 1, 1) == 2
Assert lsp#utils#byteindex('%', 1, 2) == 3
Assert lsp#utils#byteindex('%', 1, 3) == 5
Assert lsp#utils#byteindex('%', 1, 4) == 6
Assert lsp#utils#byteindex('%', 1, 5) == 7
Assert lsp#utils#byteindex('%', 2, 0) == 1
Assert lsp#utils#byteindex('%', 2, 1) == 3
Assert lsp#utils#byteindex('%', 3, 0) == 1
%delete
End
It should return the byte-index from the given character-index in an unloaded file
Assert lsp#utils#byteindex('./test/testfiles/multibyte.txt', 1, 0) == 1
Assert lsp#utils#byteindex('./test/testfiles/multibyte.txt', 1, 1) == 2
Assert lsp#utils#byteindex('./test/testfiles/multibyte.txt', 1, 2) == 3
Assert lsp#utils#byteindex('./test/testfiles/multibyte.txt', 1, 3) == 5
Assert lsp#utils#byteindex('./test/testfiles/multibyte.txt', 1, 4) == 6
Assert lsp#utils#byteindex('./test/testfiles/multibyte.txt', 1, 5) == 7
Assert lsp#utils#byteindex('./test/testfiles/multibyte.txt', 2, 0) == 1
Assert lsp#utils#byteindex('./test/testfiles/multibyte.txt', 2, 1) == 3
Assert lsp#utils#byteindex('./test/testfiles/multibyte.txt', 3, 0) == 1
End
End
End

View File

@@ -0,0 +1,3 @@
a β c
δ