text_spec.lua 810 B

12345678910111213141516171819202122232425262728293031
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local clear = n.clear
  4. local eq = t.eq
  5. describe('vim.text', function()
  6. before_each(clear)
  7. describe('hexencode() and hexdecode()', function()
  8. it('works', function()
  9. local cases = {
  10. { 'Hello world!', '48656C6C6F20776F726C6421' },
  11. { '😂', 'F09F9882' },
  12. }
  13. for _, v in ipairs(cases) do
  14. local input, output = unpack(v)
  15. eq(output, vim.text.hexencode(input))
  16. eq(input, vim.text.hexdecode(output))
  17. end
  18. end)
  19. it('works with very large strings', function()
  20. local input, output = string.rep('😂', 2 ^ 16), string.rep('F09F9882', 2 ^ 16)
  21. eq(output, vim.text.hexencode(input))
  22. eq(input, vim.text.hexdecode(output))
  23. end)
  24. end)
  25. end)