From ccb2460fa6bf8d9dbda3fa4bc8a8695bdfe8ea65 Mon Sep 17 00:00:00 2001 From: machakann Date: Sat, 17 Aug 2019 14:05:55 +0800 Subject: [PATCH] Add tests for `lsp#utils#byteindex()` --- test/.themisrc | 1 + test/lsp/utils.vimspec | 28 ++++++++++++++++++++++++++++ test/testfiles/multibyte.txt | 3 +++ 3 files changed, 32 insertions(+) create mode 100644 test/testfiles/multibyte.txt diff --git a/test/.themisrc b/test/.themisrc index 70fef823..d73cbf9d 100644 --- a/test/.themisrc +++ b/test/.themisrc @@ -1,2 +1,3 @@ +set encoding=utf-8 call themis#option('recursive', 1) call themis#helper('command').with(themis#helper('assert')) diff --git a/test/lsp/utils.vimspec b/test/lsp/utils.vimspec index 0e49ebd7..6ac5dc3c 100644 --- a/test/lsp/utils.vimspec +++ b/test/lsp/utils.vimspec @@ -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 diff --git a/test/testfiles/multibyte.txt b/test/testfiles/multibyte.txt new file mode 100644 index 00000000..eb30fd12 --- /dev/null +++ b/test/testfiles/multibyte.txt @@ -0,0 +1,3 @@ +a β c +δ +