aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/base64_spec.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2023-11-29 22:40:31 +0000
committerJosh Rahm <joshuarahm@gmail.com>2023-11-29 22:40:31 +0000
commit339e2d15cc26fe86988ea06468d912a46c8d6f29 (patch)
treea6167fc8fcfc6ae2dc102f57b2473858eac34063 /test/functional/lua/base64_spec.lua
parent067dc73729267c0262438a6fdd66e586f8496946 (diff)
parent4a8bf24ac690004aedf5540fa440e788459e5e34 (diff)
downloadrneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.tar.gz
rneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.tar.bz2
rneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.zip
Merge remote-tracking branch 'upstream/master' into fix_repeatcmdline
Diffstat (limited to 'test/functional/lua/base64_spec.lua')
-rw-r--r--test/functional/lua/base64_spec.lua105
1 files changed, 105 insertions, 0 deletions
diff --git a/test/functional/lua/base64_spec.lua b/test/functional/lua/base64_spec.lua
new file mode 100644
index 0000000000..f0d112c23e
--- /dev/null
+++ b/test/functional/lua/base64_spec.lua
@@ -0,0 +1,105 @@
+local helpers = require('test.functional.helpers')(after_each)
+local clear = helpers.clear
+local exec_lua = helpers.exec_lua
+local eq = helpers.eq
+local pcall_err = helpers.pcall_err
+local matches = helpers.matches
+
+describe('vim.base64', function()
+ before_each(clear)
+
+ local function encode(s)
+ return exec_lua([[return vim.base64.encode(...)]], s)
+ end
+
+ local function decode(s)
+ return exec_lua([[return vim.base64.decode(...)]], s)
+ end
+
+ it('works', function()
+ local values = {
+ '',
+ 'Many hands make light work.',
+ [[
+ Call me Ishmael. Some years ago—never mind how long precisely—having little or no money in
+ my purse, and nothing particular to interest me on shore, I thought I would sail about a
+ little and see the watery part of the world.
+ ]],
+ [[
+ It is a truth universally acknowledged, that a single man in possession of a good fortune,
+ must be in want of a wife.
+ ]],
+ 'Happy families are all alike; every unhappy family is unhappy in its own way.',
+ 'ЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюя',
+ 'ÅÍÎÏ˝ÓÔÒÚÆ☃',
+ '𐐜 𐐔𐐇𐐝𐐀𐐡𐐇𐐓 𐐙𐐊𐐡𐐝𐐓/𐐝𐐇𐐗𐐊𐐤𐐔 𐐒𐐋𐐗 𐐒𐐌 𐐜 𐐡𐐀𐐖𐐇𐐤𐐓𐐝 𐐱𐑂 𐑄 𐐔𐐇𐐝𐐀𐐡𐐇𐐓 𐐏𐐆𐐅𐐤𐐆𐐚𐐊𐐡𐐝𐐆𐐓𐐆',
+ '👨‍👩‍👦 👨‍👩‍👧‍👦 👨‍👨‍👦 👩‍👩‍👧 👨‍👦 👨‍👧‍👦 👩‍👦 👩‍👧‍👦',
+ 'مُنَاقَشَةُ سُبُلِ اِسْتِخْدَامِ اللُّغَةِ فِي النُّظُمِ الْقَائِمَةِ وَفِيم يَخُصَّ التَّطْبِيقَاتُ الْحاسُوبِيَّةُ،',
+ [[
+ Ṱ̺̺̕o͞ ̷i̲̬͇̪͙n̝̗͕v̟̜̘̦͟o̶̙̰̠kè͚̮̺̪̹̱̤ ̖t̝͕̳̣̻̪͞h̼͓̲̦̳̘̲e͇̣̰̦̬͎ ̢̼̻̱̘h͚͎͙̜̣̲ͅi̦̲̣̰̤v̻͍e̺̭̳̪̰-m̢iͅn̖̺̞̲̯̰d̵̼̟͙̩̼̘̳ ̞̥̱̳̭r̛̗̘e͙p͠r̼̞̻̭̗e̺̠̣͟s̘͇̳͍̝͉e͉̥̯̞̲͚̬͜ǹ̬͎͎̟̖͇̤t͍̬̤͓̼̭͘ͅi̪̱n͠g̴͉ ͏͉ͅc̬̟h͡a̫̻̯͘o̫̟̖͍̙̝͉s̗̦̲.̨̹͈̣
+ ̡͓̞ͅI̗̘̦͝n͇͇͙v̮̫ok̲̫̙͈i̖͙̭̹̠̞n̡̻̮̣̺g̲͈͙̭͙̬͎ ̰t͔̦h̞̲e̢̤ ͍̬̲͖f̴̘͕̣è͖ẹ̥̩l͖͔͚i͓͚̦͠n͖͍̗͓̳̮g͍ ̨o͚̪͡f̘̣̬ ̖̘͖̟͙̮c҉͔̫͖͓͇͖ͅh̵̤̣͚͔á̗̼͕ͅo̼̣̥s̱͈̺̖̦̻͢.̛̖̞̠̫̰
+ ̗̺͖̹̯͓Ṯ̤͍̥͇͈h̲́e͏͓̼̗̙̼̣͔ ͇̜̱̠͓͍ͅN͕͠e̗̱z̘̝̜̺͙p̤̺̹͍̯͚e̠̻̠͜r̨̤͍̺̖͔̖̖d̠̟̭̬̝͟i̦͖̩͓͔̤a̠̗̬͉̙n͚͜ ̻̞̰͚ͅh̵͉i̳̞v̢͇ḙ͎͟-҉̭̩̼͔m̤̭̫i͕͇̝̦n̗͙ḍ̟ ̯̲͕͞ǫ̟̯̰̲͙̻̝f ̪̰̰̗̖̭̘͘c̦͍̲̞͍̩̙ḥ͚a̮͎̟̙͜ơ̩̹͎s̤.̝̝ ҉Z̡̖̜͖̰̣͉̜a͖̰͙̬͡l̲̫̳͍̩g̡̟̼̱͚̞̬ͅo̗͜.̟
+ ̦H̬̤̗̤͝e͜ ̜̥̝̻͍̟́w̕h̖̯͓o̝͙̖͎̱̮ ҉̺̙̞̟͈W̷̼̭a̺̪͍į͈͕̭͙̯̜t̶̼̮s̘͙͖̕ ̠̫̠B̻͍͙͉̳ͅe̵h̵̬͇̫͙i̹͓̳̳̮͎̫̕n͟d̴̪̜̖ ̰͉̩͇͙̲͞ͅT͖̼͓̪͢h͏͓̮̻e̬̝̟ͅ ̤̹̝W͙̞̝͔͇͝ͅa͏͓͔̹̼̣l̴͔̰̤̟͔ḽ̫.͕
+ Z̮̞̠͙͔ͅḀ̗̞͈̻̗Ḷ͙͎̯̹̞͓G̻O̭̗̮
+ ]],
+ }
+
+ for _, v in ipairs(values) do
+ eq(v, decode(encode(v)))
+ end
+
+ -- Explicitly check encoded output
+ eq('VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZwo=', encode('The quick brown fox jumps over the lazy dog\n'))
+
+ -- Test vectors from rfc4648
+ local rfc4648 = {
+ { '', '' },
+ { 'f', 'Zg==', },
+ { 'fo', 'Zm8=' },
+ { 'foo', 'Zm9v' },
+ { 'foob', 'Zm9vYg==' },
+ { 'fooba', 'Zm9vYmE=' },
+ { 'foobar', 'Zm9vYmFy' },
+ }
+
+ for _, v in ipairs(rfc4648) do
+ local input = v[1]
+ local output = v[2]
+ eq(output, encode(input))
+ eq(input, decode(output))
+ end
+ end)
+
+ it('detects invalid input', function()
+ local invalid = {
+ 'A',
+ 'AA',
+ 'AAA',
+ 'A..A',
+ 'AA=A',
+ 'AA/=',
+ 'A/==',
+ 'A===',
+ '====',
+ 'Zm9vYmFyZm9vYmFyA..A',
+ 'Zm9vYmFyZm9vYmFyAA=A',
+ 'Zm9vYmFyZm9vYmFyAA/=',
+ 'Zm9vYmFyZm9vYmFyA/==',
+ 'Zm9vYmFyZm9vYmFyA===',
+ 'A..AZm9vYmFyZm9vYmFy',
+ 'Zm9vYmFyZm9vAA=A',
+ 'Zm9vYmFyZm9vAA/=',
+ 'Zm9vYmFyZm9vA/==',
+ 'Zm9vYmFyZm9vA===',
+ }
+
+ for _, v in ipairs(invalid) do
+ eq('Invalid input', pcall_err(decode, v))
+ end
+
+ eq('Expected 1 argument', pcall_err(encode))
+ eq('Expected 1 argument', pcall_err(decode))
+ matches('expected string', pcall_err(encode, 42))
+ matches('expected string', pcall_err(decode, 42))
+ end)
+end)