shada_spec.lua 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local eq, nvim_eval, nvim_command, nvim, exc_exec, funcs, nvim_feed, curbuf =
  3. helpers.eq, helpers.eval, helpers.command, helpers.nvim, helpers.exc_exec,
  4. helpers.funcs, helpers.feed, helpers.curbuf
  5. local neq = helpers.neq
  6. local read_file = helpers.read_file
  7. local mpack = require('mpack')
  8. local plugin_helpers = require('test.functional.plugin.helpers')
  9. local reset = plugin_helpers.reset
  10. local shada_helpers = require('test.functional.shada.helpers')
  11. local get_shada_rw = shada_helpers.get_shada_rw
  12. local mpack_eq = function(expected, mpack_result)
  13. local mpack_keys = {'type', 'timestamp', 'length', 'value'}
  14. local unpack = mpack.Unpacker()
  15. local actual = {}
  16. local cur, val
  17. local i = 0
  18. local off = 1
  19. while off <= #mpack_result do
  20. val, off = unpack(mpack_result, off)
  21. if i % 4 == 0 then
  22. cur = {}
  23. actual[#actual + 1] = cur
  24. end
  25. local key = mpack_keys[(i % 4) + 1]
  26. if key ~= 'length' then
  27. if key == 'timestamp' and math.abs(val - os.time()) < 2 then
  28. val = 'current'
  29. end
  30. cur[key] = val
  31. end
  32. i = i + 1
  33. end
  34. eq(expected, actual)
  35. end
  36. local wshada, _, fname = get_shada_rw('Xtest-functional-plugin-shada.shada')
  37. local wshada_tmp, _, fname_tmp =
  38. get_shada_rw('Xtest-functional-plugin-shada.shada.tmp.f')
  39. describe('autoload/shada.vim', function()
  40. local epoch = os.date('%Y-%m-%dT%H:%M:%S', 0)
  41. before_each(function()
  42. reset()
  43. nvim_command([[
  44. function ModifyVal(val)
  45. if type(a:val) == type([])
  46. if len(a:val) == 2 && type(a:val[0]) == type('') && a:val[0][0] is# '!' && has_key(v:msgpack_types, a:val[0][1:])
  47. return {'_TYPE': v:msgpack_types[ a:val[0][1:] ], '_VAL': a:val[1]}
  48. else
  49. return map(copy(a:val), 'ModifyVal(v:val)')
  50. endif
  51. elseif type(a:val) == type({})
  52. let keys = sort(keys(a:val))
  53. let ret = {'_TYPE': v:msgpack_types.map, '_VAL': []}
  54. for key in keys
  55. let k = {'_TYPE': v:msgpack_types.string, '_VAL': split(key, "\n", 1)}
  56. let v = ModifyVal(a:val[key])
  57. call add(ret._VAL, [k, v])
  58. unlet v
  59. endfor
  60. return ret
  61. elseif type(a:val) == type('')
  62. return {'_TYPE': v:msgpack_types.binary, '_VAL': split(a:val, "\n", 1)}
  63. else
  64. return a:val
  65. endif
  66. endfunction
  67. ]])
  68. end)
  69. local sp = function(typ, val)
  70. return ('{"_TYPE": v:msgpack_types.%s, "_VAL": %s}'):format(typ, val)
  71. end
  72. describe('function shada#mpack_to_sd', function()
  73. local mpack2sd = function(arg)
  74. return ('shada#mpack_to_sd(%s)'):format(arg)
  75. end
  76. it('works', function()
  77. eq({}, nvim_eval(mpack2sd('[]')))
  78. eq({{type=1, timestamp=5, length=1, data=7}},
  79. nvim_eval(mpack2sd('[1, 5, 1, 7]')))
  80. eq({{type=1, timestamp=5, length=1, data=7},
  81. {type=1, timestamp=10, length=1, data=5}},
  82. nvim_eval(mpack2sd('[1, 5, 1, 7, 1, 10, 1, 5]')))
  83. eq('zero-uint:Entry 1 has type element which is zero',
  84. exc_exec('call ' .. mpack2sd('[0, 5, 1, 7]')))
  85. eq('zero-uint:Entry 1 has type element which is zero',
  86. exc_exec('call ' .. mpack2sd(('[%s, 5, 1, 7]'):format(
  87. sp('integer', '[1, 0, 0, 0]')))))
  88. eq('not-uint:Entry 1 has timestamp element which is not an unsigned integer',
  89. exc_exec('call ' .. mpack2sd('[1, -1, 1, 7]')))
  90. eq('not-uint:Entry 1 has length element which is not an unsigned integer',
  91. exc_exec('call ' .. mpack2sd('[1, 1, -1, 7]')))
  92. eq('not-uint:Entry 1 has type element which is not an unsigned integer',
  93. exc_exec('call ' .. mpack2sd('["", 1, -1, 7]')))
  94. end)
  95. end)
  96. describe('function shada#sd_to_strings', function()
  97. local sd2strings_eq = function(expected, arg)
  98. if type(arg) == 'table' then
  99. eq(expected, funcs['shada#sd_to_strings'](arg))
  100. else
  101. eq(expected, nvim_eval(('shada#sd_to_strings(%s)'):format(arg)))
  102. end
  103. end
  104. it('works with empty input', function()
  105. sd2strings_eq({}, '[]')
  106. end)
  107. it('works with unknown items', function()
  108. sd2strings_eq({
  109. 'Unknown (0x64) with timestamp ' .. epoch .. ':',
  110. ' = 100'
  111. }, {{type=100, timestamp=0, length=1, data=100}})
  112. sd2strings_eq({
  113. 'Unknown (0x4000001180000006) with timestamp ' .. epoch .. ':',
  114. ' = 100'
  115. }, ('[{"type": %s, "timestamp": 0, "length": 1, "data": 100}]'):format(
  116. sp('integer', '[1, 1, 35, 6]')
  117. ))
  118. end)
  119. it('works with multiple unknown items', function()
  120. sd2strings_eq({
  121. 'Unknown (0x64) with timestamp ' .. epoch .. ':',
  122. ' = 100',
  123. 'Unknown (0x65) with timestamp ' .. epoch .. ':',
  124. ' = 500',
  125. }, {{type=100, timestamp=0, length=1, data=100},
  126. {type=101, timestamp=0, length=1, data=500}})
  127. end)
  128. it('works with header items', function()
  129. sd2strings_eq({
  130. 'Header with timestamp ' .. epoch .. ':',
  131. ' % Key______ Value',
  132. ' + generator "test"',
  133. }, {{type=1, timestamp=0, data={generator='test'}}})
  134. sd2strings_eq({
  135. 'Header with timestamp ' .. epoch .. ':',
  136. ' % Key Description Value',
  137. ' + a 1',
  138. ' + b 2',
  139. ' + c column 3',
  140. ' + d 4',
  141. }, {{type=1, timestamp=0, data={a=1, b=2, c=3, d=4}}})
  142. sd2strings_eq({
  143. 'Header with timestamp ' .. epoch .. ':',
  144. ' % Key Value',
  145. ' + t "test"',
  146. }, {{type=1, timestamp=0, data={t='test'}}})
  147. sd2strings_eq({
  148. 'Header with timestamp ' .. epoch .. ':',
  149. ' # Unexpected type: array instead of map',
  150. ' = [1, 2, 3]',
  151. }, {{type=1, timestamp=0, data={1, 2, 3}}})
  152. end)
  153. it('processes standard keys correctly, even in header', function()
  154. sd2strings_eq({
  155. 'Header with timestamp ' .. epoch .. ':',
  156. ' % Key Description________ Value',
  157. ' + c column 0',
  158. ' + f file name "/tmp/foo"',
  159. ' + l line number 10',
  160. ' + n name \'@\'',
  161. ' + rc contents ["abc", "def"]',
  162. ' + rt type CHARACTERWISE',
  163. ' + ru is_unnamed FALSE',
  164. ' + rw block width 10',
  165. ' + sb search backward TRUE',
  166. ' + sc smartcase value FALSE',
  167. ' + se place cursor at end TRUE',
  168. ' + sh v:hlsearch value TRUE',
  169. ' + sl has line offset FALSE',
  170. ' + sm magic value TRUE',
  171. ' + so offset value 10',
  172. ' + sp pattern "100"',
  173. ' + ss is :s pattern TRUE',
  174. ' + su is last used FALSE',
  175. }, ([[ [{'type': 1, 'timestamp': 0, 'data': {
  176. 'sm': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
  177. 'sc': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
  178. 'sl': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
  179. 'se': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
  180. 'sb': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
  181. 'so': 10,
  182. 'su': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
  183. 'ss': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
  184. 'sh': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
  185. 'sp': '100',
  186. 'rt': 0,
  187. 'rw': 10,
  188. 'rc': ['abc', 'def'],
  189. 'ru': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
  190. 'n': 0x40,
  191. 'l': 10,
  192. 'c': 0,
  193. 'f': '/tmp/foo',
  194. }}] ]]):gsub('\n', ''))
  195. sd2strings_eq({
  196. 'Header with timestamp ' .. epoch .. ':',
  197. ' % Key Description____ Value',
  198. ' # Expected integer',
  199. ' + c column "abc"',
  200. ' # Expected no NUL bytes',
  201. ' + f file name "abc\\0def"',
  202. ' # Value is negative',
  203. ' + l line number -10',
  204. ' # Value is negative',
  205. ' + n name -64',
  206. ' # Expected array value',
  207. ' + rc contents "10"',
  208. ' # Unexpected enum value: expected one of '
  209. .. '0 (CHARACTERWISE), 1 (LINEWISE), 2 (BLOCKWISE)',
  210. ' + rt type 10',
  211. ' # Expected boolean',
  212. ' + ru is_unnamed 10',
  213. ' # Expected boolean',
  214. ' + sc smartcase value NIL',
  215. ' # Expected boolean',
  216. ' + sm magic value "TRUE"',
  217. ' # Expected integer',
  218. ' + so offset value "TRUE"',
  219. ' # Expected binary string',
  220. ' + sp pattern ="abc"',
  221. }, ([[ [{'type': 1, 'timestamp': 0, 'data': {
  222. 'sm': 'TRUE',
  223. 'sc': {'_TYPE': v:msgpack_types.nil, '_VAL': 0},
  224. 'so': 'TRUE',
  225. 'sp': {'_TYPE': v:msgpack_types.string, '_VAL': ["abc"]},
  226. 'rt': 10,
  227. 'rc': '10',
  228. 'ru': 10,
  229. 'n': -0x40,
  230. 'l': -10,
  231. 'c': 'abc',
  232. 'f': {'_TYPE': v:msgpack_types.binary, '_VAL': ["abc\ndef"]},
  233. }}] ]]):gsub('\n', ''))
  234. sd2strings_eq({
  235. 'Header with timestamp ' .. epoch .. ':',
  236. ' % Key Description Value',
  237. ' # Expected no NUL bytes',
  238. ' + f file name "abc\\0def"',
  239. ' # Expected array of binary strings',
  240. ' + rc contents ["abc", ="abc"]',
  241. ' # Expected integer',
  242. ' + rt type "ABC"',
  243. }, ([[ [{'type': 1, 'timestamp': 0, 'data': {
  244. 'rt': 'ABC',
  245. 'rc': ["abc", {'_TYPE': v:msgpack_types.string, '_VAL': ["abc"]}],
  246. 'f': {'_TYPE': v:msgpack_types.binary, '_VAL': ["abc\ndef"]},
  247. }}] ]]):gsub('\n', ''))
  248. sd2strings_eq({
  249. 'Header with timestamp ' .. epoch .. ':',
  250. ' % Key Description Value',
  251. ' # Expected no NUL bytes',
  252. ' + rc contents ["abc", "a\\nd\\0"]',
  253. }, ([[ [{'type': 1, 'timestamp': 0, 'data': {
  254. 'rc': ["abc", {'_TYPE': v:msgpack_types.binary, '_VAL': ["a", "d\n"]}],
  255. }}] ]]):gsub('\n', ''))
  256. end)
  257. it('works with search pattern items', function()
  258. sd2strings_eq({
  259. 'Search pattern with timestamp ' .. epoch .. ':',
  260. ' # Unexpected type: array instead of map',
  261. ' = [1, 2, 3]',
  262. }, {{type=2, timestamp=0, data={1, 2, 3}}})
  263. sd2strings_eq({
  264. 'Search pattern with timestamp ' .. epoch .. ':',
  265. ' % Key Description________ Value',
  266. ' + sp pattern "abc"',
  267. ' + sh v:hlsearch value FALSE',
  268. ' + ss is :s pattern FALSE',
  269. ' + sb search backward FALSE',
  270. ' + sm magic value TRUE',
  271. ' + sc smartcase value FALSE',
  272. ' + sl has line offset FALSE',
  273. ' + se place cursor at end FALSE',
  274. ' + so offset value 0',
  275. ' + su is last used TRUE',
  276. }, ([[ [{'type': 2, 'timestamp': 0, 'data': {
  277. 'sp': 'abc',
  278. }}] ]]):gsub('\n', ''))
  279. sd2strings_eq({
  280. 'Search pattern with timestamp ' .. epoch .. ':',
  281. ' % Key Description________ Value',
  282. ' + sp pattern "abc"',
  283. ' + sh v:hlsearch value FALSE',
  284. ' + ss is :s pattern FALSE',
  285. ' + sb search backward FALSE',
  286. ' + sm magic value TRUE',
  287. ' + sc smartcase value FALSE',
  288. ' + sl has line offset FALSE',
  289. ' + se place cursor at end FALSE',
  290. ' + so offset value 0',
  291. ' + su is last used TRUE',
  292. ' + sX NIL',
  293. ' + sY NIL',
  294. ' + sZ NIL',
  295. }, ([[ [{'type': 2, 'timestamp': 0, 'data': {
  296. 'sp': 'abc',
  297. 'sZ': {'_TYPE': v:msgpack_types.nil, '_VAL': 0},
  298. 'sY': {'_TYPE': v:msgpack_types.nil, '_VAL': 0},
  299. 'sX': {'_TYPE': v:msgpack_types.nil, '_VAL': 0},
  300. }}] ]]):gsub('\n', ''))
  301. sd2strings_eq({
  302. 'Search pattern with timestamp ' .. epoch .. ':',
  303. ' % Key Description________ Value',
  304. ' + sp pattern "abc"',
  305. ' + sh v:hlsearch value FALSE',
  306. ' + ss is :s pattern FALSE',
  307. ' + sb search backward FALSE',
  308. ' + sm magic value TRUE',
  309. ' + sc smartcase value FALSE',
  310. ' + sl has line offset FALSE',
  311. ' + se place cursor at end FALSE',
  312. ' + so offset value 0',
  313. ' + su is last used TRUE',
  314. }, ([[ [{'type': 2, 'timestamp': 0, 'data': {
  315. 'sp': 'abc',
  316. 'sh': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
  317. 'ss': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
  318. 'sb': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
  319. 'sm': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
  320. 'sc': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
  321. 'sl': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
  322. 'se': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
  323. 'so': 0,
  324. 'su': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
  325. }}] ]]):gsub('\n', ''))
  326. sd2strings_eq({
  327. 'Search pattern with timestamp ' .. epoch .. ':',
  328. ' % Key Description________ Value',
  329. ' # Required key missing: sp',
  330. ' + sh v:hlsearch value FALSE',
  331. ' + ss is :s pattern FALSE',
  332. ' + sb search backward FALSE',
  333. ' + sm magic value TRUE',
  334. ' + sc smartcase value FALSE',
  335. ' + sl has line offset FALSE',
  336. ' + se place cursor at end FALSE',
  337. ' + so offset value 0',
  338. ' + su is last used TRUE',
  339. }, ([[ [{'type': 2, 'timestamp': 0, 'data': {
  340. }}] ]]):gsub('\n', ''))
  341. sd2strings_eq({
  342. 'Search pattern with timestamp ' .. epoch .. ':',
  343. ' % Key Description________ Value',
  344. ' + sp pattern ""',
  345. ' + sh v:hlsearch value TRUE',
  346. ' + ss is :s pattern TRUE',
  347. ' + sb search backward TRUE',
  348. ' + sm magic value FALSE',
  349. ' + sc smartcase value TRUE',
  350. ' + sl has line offset TRUE',
  351. ' + se place cursor at end TRUE',
  352. ' + so offset value -10',
  353. ' + su is last used FALSE',
  354. }, ([[ [{'type': 2, 'timestamp': 0, 'data': {
  355. 'sp': '',
  356. 'sh': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
  357. 'ss': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
  358. 'sb': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
  359. 'sm': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
  360. 'sc': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
  361. 'sl': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
  362. 'se': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
  363. 'so': -10,
  364. 'su': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
  365. }}] ]]):gsub('\n', ''))
  366. sd2strings_eq({
  367. 'Search pattern with timestamp ' .. epoch .. ':',
  368. ' % Key Description________ Value',
  369. ' # Expected binary string',
  370. ' + sp pattern 0',
  371. ' # Expected boolean',
  372. ' + sh v:hlsearch value 0',
  373. ' # Expected boolean',
  374. ' + ss is :s pattern 0',
  375. ' # Expected boolean',
  376. ' + sb search backward 0',
  377. ' # Expected boolean',
  378. ' + sm magic value 0',
  379. ' # Expected boolean',
  380. ' + sc smartcase value 0',
  381. ' # Expected boolean',
  382. ' + sl has line offset 0',
  383. ' # Expected boolean',
  384. ' + se place cursor at end 0',
  385. ' # Expected integer',
  386. ' + so offset value ""',
  387. ' # Expected boolean',
  388. ' + su is last used 0',
  389. }, ([[ [{'type': 2, 'timestamp': 0, 'data': {
  390. 'sp': 0,
  391. 'sh': 0,
  392. 'ss': 0,
  393. 'sb': 0,
  394. 'sm': 0,
  395. 'sc': 0,
  396. 'sl': 0,
  397. 'se': 0,
  398. 'so': '',
  399. 'su': 0,
  400. }}] ]]):gsub('\n', ''))
  401. end)
  402. it('works with replacement string items', function()
  403. sd2strings_eq({
  404. 'Replacement string with timestamp ' .. epoch .. ':',
  405. ' # Unexpected type: map instead of array',
  406. ' = {="a": [10]}',
  407. }, {{type=3, timestamp=0, data={a={10}}}})
  408. sd2strings_eq({
  409. 'Replacement string with timestamp ' .. epoch .. ':',
  410. ' @ Description__________ Value',
  411. ' # Expected more elements in list'
  412. }, ([[ [{'type': 3, 'timestamp': 0, 'data': [
  413. ]}] ]]):gsub('\n', ''))
  414. sd2strings_eq({
  415. 'Replacement string with timestamp ' .. epoch .. ':',
  416. ' @ Description__________ Value',
  417. ' # Expected binary string',
  418. ' - :s replacement string 0',
  419. }, ([[ [{'type': 3, 'timestamp': 0, 'data': [
  420. 0,
  421. ]}] ]]):gsub('\n', ''))
  422. sd2strings_eq({
  423. 'Replacement string with timestamp ' .. epoch .. ':',
  424. ' @ Description__________ Value',
  425. ' # Expected no NUL bytes',
  426. ' - :s replacement string "abc\\0def"',
  427. }, ([[ [{'type': 3, 'timestamp': 0, 'data': [
  428. {'_TYPE': v:msgpack_types.binary, '_VAL': ["abc\ndef"]},
  429. ]}] ]]):gsub('\n', ''))
  430. sd2strings_eq({
  431. 'Replacement string with timestamp ' .. epoch .. ':',
  432. ' @ Description__________ Value',
  433. ' - :s replacement string "abc\\ndef"',
  434. }, ([[ [{'type': 3, 'timestamp': 0, 'data': [
  435. {'_TYPE': v:msgpack_types.binary, '_VAL': ["abc", "def"]},
  436. ]}] ]]):gsub('\n', ''))
  437. sd2strings_eq({
  438. 'Replacement string with timestamp ' .. epoch .. ':',
  439. ' @ Description__________ Value',
  440. ' - :s replacement string "abc\\ndef"',
  441. ' - 0',
  442. }, ([[ [{'type': 3, 'timestamp': 0, 'data': [
  443. {'_TYPE': v:msgpack_types.binary, '_VAL': ["abc", "def"]},
  444. 0,
  445. ]}] ]]):gsub('\n', ''))
  446. end)
  447. it('works with history entry items', function()
  448. sd2strings_eq({
  449. 'History entry with timestamp ' .. epoch .. ':',
  450. ' # Unexpected type: map instead of array',
  451. ' = {="a": [10]}',
  452. }, {{type=4, timestamp=0, data={a={10}}}})
  453. sd2strings_eq({
  454. 'History entry with timestamp ' .. epoch .. ':',
  455. ' @ Description_ Value',
  456. ' # Expected more elements in list'
  457. }, ([[ [{'type': 4, 'timestamp': 0, 'data': [
  458. ]}] ]]):gsub('\n', ''))
  459. sd2strings_eq({
  460. 'History entry with timestamp ' .. epoch .. ':',
  461. ' @ Description_ Value',
  462. ' # Expected integer',
  463. ' - history type ""',
  464. ' # Expected more elements in list'
  465. }, ([[ [{'type': 4, 'timestamp': 0, 'data': [
  466. '',
  467. ]}] ]]):gsub('\n', ''))
  468. sd2strings_eq({
  469. 'History entry with timestamp ' .. epoch .. ':',
  470. ' @ Description_ Value',
  471. ' # Unexpected enum value: expected one of 0 (CMD), 1 (SEARCH), '
  472. .. '2 (EXPR), 3 (INPUT), 4 (DEBUG)',
  473. ' - history type 5',
  474. ' - contents ""',
  475. }, ([[ [{'type': 4, 'timestamp': 0, 'data': [
  476. 5,
  477. ''
  478. ]}] ]]):gsub('\n', ''))
  479. sd2strings_eq({
  480. 'History entry with timestamp ' .. epoch .. ':',
  481. ' @ Description_ Value',
  482. ' # Unexpected enum value: expected one of 0 (CMD), 1 (SEARCH), '
  483. .. '2 (EXPR), 3 (INPUT), 4 (DEBUG)',
  484. ' - history type 5',
  485. ' - contents ""',
  486. ' - 32',
  487. }, ([[ [{'type': 4, 'timestamp': 0, 'data': [
  488. 5,
  489. '',
  490. 0x20
  491. ]}] ]]):gsub('\n', ''))
  492. sd2strings_eq({
  493. 'History entry with timestamp ' .. epoch .. ':',
  494. ' @ Description_ Value',
  495. ' - history type CMD',
  496. ' - contents ""',
  497. ' - 32',
  498. }, ([[ [{'type': 4, 'timestamp': 0, 'data': [
  499. 0,
  500. '',
  501. 0x20
  502. ]}] ]]):gsub('\n', ''))
  503. sd2strings_eq({
  504. 'History entry with timestamp ' .. epoch .. ':',
  505. ' @ Description_ Value',
  506. ' - history type SEARCH',
  507. ' - contents ""',
  508. ' - separator \' \'',
  509. }, ([[ [{'type': 4, 'timestamp': 0, 'data': [
  510. 1,
  511. '',
  512. 0x20
  513. ]}] ]]):gsub('\n', ''))
  514. sd2strings_eq({
  515. 'History entry with timestamp ' .. epoch .. ':',
  516. ' @ Description_ Value',
  517. ' - history type SEARCH',
  518. ' - contents ""',
  519. ' # Expected more elements in list',
  520. }, ([[ [{'type': 4, 'timestamp': 0, 'data': [
  521. 1,
  522. '',
  523. ]}] ]]):gsub('\n', ''))
  524. sd2strings_eq({
  525. 'History entry with timestamp ' .. epoch .. ':',
  526. ' @ Description_ Value',
  527. ' - history type EXPR',
  528. ' - contents ""',
  529. }, ([[ [{'type': 4, 'timestamp': 0, 'data': [
  530. 2,
  531. '',
  532. ]}] ]]):gsub('\n', ''))
  533. sd2strings_eq({
  534. 'History entry with timestamp ' .. epoch .. ':',
  535. ' @ Description_ Value',
  536. ' - history type INPUT',
  537. ' - contents ""',
  538. }, ([[ [{'type': 4, 'timestamp': 0, 'data': [
  539. 3,
  540. '',
  541. ]}] ]]):gsub('\n', ''))
  542. sd2strings_eq({
  543. 'History entry with timestamp ' .. epoch .. ':',
  544. ' @ Description_ Value',
  545. ' - history type DEBUG',
  546. ' - contents ""',
  547. }, ([[ [{'type': 4, 'timestamp': 0, 'data': [
  548. 4,
  549. '',
  550. ]}] ]]):gsub('\n', ''))
  551. sd2strings_eq({
  552. 'History entry with timestamp ' .. epoch .. ':',
  553. ' @ Description_ Value',
  554. ' - history type DEBUG',
  555. ' # Expected binary string',
  556. ' - contents 10',
  557. }, ([[ [{'type': 4, 'timestamp': 0, 'data': [
  558. 4,
  559. 10,
  560. ]}] ]]):gsub('\n', ''))
  561. sd2strings_eq({
  562. 'History entry with timestamp ' .. epoch .. ':',
  563. ' @ Description_ Value',
  564. ' - history type DEBUG',
  565. ' # Expected no NUL bytes',
  566. ' - contents "abc\\0def"',
  567. }, ([[ [{'type': 4, 'timestamp': 0, 'data': [
  568. 4,
  569. {'_TYPE': v:msgpack_types.binary, '_VAL': ["abc\ndef"]},
  570. ]}] ]]):gsub('\n', ''))
  571. sd2strings_eq({
  572. 'History entry with timestamp ' .. epoch .. ':',
  573. ' @ Description_ Value',
  574. ' - history type SEARCH',
  575. ' - contents "abc"',
  576. ' # Expected integer',
  577. ' - separator ""',
  578. }, ([[ [{'type': 4, 'timestamp': 0, 'data': [
  579. 1,
  580. 'abc',
  581. '',
  582. ]}] ]]):gsub('\n', ''))
  583. sd2strings_eq({
  584. 'History entry with timestamp ' .. epoch .. ':',
  585. ' @ Description_ Value',
  586. ' - history type SEARCH',
  587. ' - contents "abc"',
  588. ' # Value is negative',
  589. ' - separator -1',
  590. }, ([[ [{'type': 4, 'timestamp': 0, 'data': [
  591. 1,
  592. 'abc',
  593. -1,
  594. ]}] ]]):gsub('\n', ''))
  595. -- Regression: NUL separator must be properly supported
  596. sd2strings_eq({
  597. 'History entry with timestamp ' .. epoch .. ':',
  598. ' @ Description_ Value',
  599. ' - history type SEARCH',
  600. ' - contents ""',
  601. ' - separator \'\\0\'',
  602. }, ([[ [{'type': 4, 'timestamp': 0, 'data': [
  603. 1,
  604. '',
  605. 0x0
  606. ]}] ]]):gsub('\n', ''))
  607. end)
  608. it('works with register items', function()
  609. sd2strings_eq({
  610. 'Register with timestamp ' .. epoch .. ':',
  611. ' # Unexpected type: array instead of map',
  612. ' = [1, 2, 3]',
  613. }, {{type=5, timestamp=0, data={1, 2, 3}}})
  614. sd2strings_eq({
  615. 'Register with timestamp ' .. epoch .. ':',
  616. ' % Key Description Value',
  617. ' # Required key missing: n',
  618. ' # Required key missing: rc',
  619. ' + rw block width 0',
  620. ' + rt type CHARACTERWISE',
  621. ' + ru is_unnamed FALSE',
  622. }, ([[ [{'type': 5, 'timestamp': 0, 'data': {
  623. }}] ]]):gsub('\n', ''))
  624. sd2strings_eq({
  625. 'Register with timestamp ' .. epoch .. ':',
  626. ' % Key Description Value',
  627. ' + n name \' \'',
  628. ' # Required key missing: rc',
  629. ' + rw block width 0',
  630. ' + rt type CHARACTERWISE',
  631. ' + ru is_unnamed FALSE',
  632. }, ([[ [{'type': 5, 'timestamp': 0, 'data': {
  633. 'n': 0x20,
  634. }}] ]]):gsub('\n', ''))
  635. sd2strings_eq({
  636. 'Register with timestamp ' .. epoch .. ':',
  637. ' % Key Description Value',
  638. ' + n name \' \'',
  639. ' + rc contents ["abc", "def"]',
  640. ' + rw block width 0',
  641. ' + rt type CHARACTERWISE',
  642. ' + ru is_unnamed FALSE',
  643. }, ([[ [{'type': 5, 'timestamp': 0, 'data': {
  644. 'n': 0x20,
  645. 'rc': ["abc", "def"],
  646. 'ru': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
  647. }}] ]]):gsub('\n', ''))
  648. sd2strings_eq({
  649. 'Register with timestamp ' .. epoch .. ':',
  650. ' % Key Description Value',
  651. ' + n name \' \'',
  652. ' + rc contents @',
  653. ' | - "abcdefghijklmnopqrstuvwxyz"',
  654. ' | - "abcdefghijklmnopqrstuvwxyz"',
  655. ' + rw block width 0',
  656. ' + rt type CHARACTERWISE',
  657. ' + ru is_unnamed TRUE',
  658. }, ([[ [{'type': 5, 'timestamp': 0, 'data': {
  659. 'n': 0x20,
  660. 'rc': ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'],
  661. 'ru': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
  662. }}] ]]):gsub('\n', ''))
  663. sd2strings_eq({
  664. 'Register with timestamp ' .. epoch .. ':',
  665. ' % Key Description Value',
  666. ' + n name \' \'',
  667. ' + rc contents @',
  668. ' | - "abcdefghijklmnopqrstuvwxyz"',
  669. ' | - "abcdefghijklmnopqrstuvwxyz"',
  670. ' + rw block width 0',
  671. ' + rt type CHARACTERWISE',
  672. ' + ru is_unnamed FALSE',
  673. }, ([[ [{'type': 5, 'timestamp': 0, 'data': {
  674. 'n': 0x20,
  675. 'rc': ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'],
  676. 'rw': 0,
  677. 'rt': 0,
  678. }}] ]]):gsub('\n', ''))
  679. sd2strings_eq({
  680. 'Register with timestamp ' .. epoch .. ':',
  681. ' % Key Description Value',
  682. ' + n name \' \'',
  683. ' + rc contents @',
  684. ' | - "abcdefghijklmnopqrstuvwxyz"',
  685. ' | - "abcdefghijklmnopqrstuvwxyz"',
  686. ' + rw block width 5',
  687. ' + rt type LINEWISE',
  688. ' + ru is_unnamed FALSE',
  689. }, ([[ [{'type': 5, 'timestamp': 0, 'data': {
  690. 'n': 0x20,
  691. 'rc': ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'],
  692. 'rw': 5,
  693. 'rt': 1,
  694. }}] ]]):gsub('\n', ''))
  695. sd2strings_eq({
  696. 'Register with timestamp ' .. epoch .. ':',
  697. ' % Key Description Value',
  698. ' + n name \' \'',
  699. ' + rc contents @',
  700. ' | - "abcdefghijklmnopqrstuvwxyz"',
  701. ' | - "abcdefghijklmnopqrstuvwxyz"',
  702. ' # Expected integer',
  703. ' + rw block width ""',
  704. ' + rt type BLOCKWISE',
  705. ' # Expected boolean',
  706. ' + ru is_unnamed ""',
  707. }, ([[ [{'type': 5, 'timestamp': 0, 'data': {
  708. 'n': 0x20,
  709. 'rc': ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'],
  710. 'rw': "",
  711. 'rt': 2,
  712. 'ru': ""
  713. }}] ]]):gsub('\n', ''))
  714. sd2strings_eq({
  715. 'Register with timestamp ' .. epoch .. ':',
  716. ' % Key Description Value',
  717. ' + n name \' \'',
  718. ' # Expected array value',
  719. ' + rc contents 0',
  720. ' # Value is negative',
  721. ' + rw block width -1',
  722. ' # Unexpected enum value: expected one of 0 (CHARACTERWISE), '
  723. .. '1 (LINEWISE), 2 (BLOCKWISE)',
  724. ' + rt type 10',
  725. ' # Expected boolean',
  726. ' + ru is_unnamed ["abc", "def"]',
  727. }, ([[ [{'type': 5, 'timestamp': 0, 'data': {
  728. 'n': 0x20,
  729. 'rc': 0,
  730. 'rw': -1,
  731. 'rt': 10,
  732. 'ru': ['abc', 'def'],
  733. }}] ]]):gsub('\n', ''))
  734. sd2strings_eq({
  735. 'Register with timestamp ' .. epoch .. ':',
  736. ' % Key Description Value',
  737. ' + n name \' \'',
  738. ' + rc contents @',
  739. ' | - "abcdefghijklmnopqrstuvwxyz"',
  740. ' | - "abcdefghijklmnopqrstuvwxyz"',
  741. ' + rw block width 5',
  742. ' + rt type LINEWISE',
  743. ' # Expected boolean',
  744. ' + ru is_unnamed 0',
  745. }, ([[ [{'type': 5, 'timestamp': 0, 'data': {
  746. 'n': 0x20,
  747. 'rc': ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'],
  748. 'rw': 5,
  749. 'rt': 1,
  750. 'ru': 0,
  751. }}] ]]):gsub('\n', ''))
  752. end)
  753. it('works with variable items', function()
  754. sd2strings_eq({
  755. 'Variable with timestamp ' .. epoch .. ':',
  756. ' # Unexpected type: map instead of array',
  757. ' = {="a": [10]}',
  758. }, {{type=6, timestamp=0, data={a={10}}}})
  759. sd2strings_eq({
  760. 'Variable with timestamp ' .. epoch .. ':',
  761. ' @ Description Value',
  762. ' # Expected more elements in list'
  763. }, ([[ [{'type': 6, 'timestamp': 0, 'data': [
  764. ]}] ]]):gsub('\n', ''))
  765. sd2strings_eq({
  766. 'Variable with timestamp ' .. epoch .. ':',
  767. ' @ Description Value',
  768. ' # Expected binary string',
  769. ' - name 1',
  770. ' # Expected more elements in list',
  771. }, ([[ [{'type': 6, 'timestamp': 0, 'data': [
  772. 1
  773. ]}] ]]):gsub('\n', ''))
  774. sd2strings_eq({
  775. 'Variable with timestamp ' .. epoch .. ':',
  776. ' @ Description Value',
  777. ' # Expected no NUL bytes',
  778. ' - name "\\0"',
  779. ' # Expected more elements in list',
  780. }, ([[ [{'type': 6, 'timestamp': 0, 'data': [
  781. {'_TYPE': v:msgpack_types.binary, '_VAL': ["\n"]},
  782. ]}] ]]):gsub('\n', ''))
  783. sd2strings_eq({
  784. 'Variable with timestamp ' .. epoch .. ':',
  785. ' @ Description Value',
  786. ' - name "foo"',
  787. ' # Expected more elements in list',
  788. }, ([[ [{'type': 6, 'timestamp': 0, 'data': [
  789. {'_TYPE': v:msgpack_types.binary, '_VAL': ["foo"]},
  790. ]}] ]]):gsub('\n', ''))
  791. sd2strings_eq({
  792. 'Variable with timestamp ' .. epoch .. ':',
  793. ' @ Description Value',
  794. ' - name "foo"',
  795. ' - value NIL',
  796. }, ([[ [{'type': 6, 'timestamp': 0, 'data': [
  797. {'_TYPE': v:msgpack_types.binary, '_VAL': ["foo"]},
  798. {'_TYPE': v:msgpack_types.nil, '_VAL': ["foo"]},
  799. ]}] ]]):gsub('\n', ''))
  800. sd2strings_eq({
  801. 'Variable with timestamp ' .. epoch .. ':',
  802. ' @ Description Value',
  803. ' - name "foo"',
  804. ' - value NIL',
  805. ' - NIL',
  806. }, ([[ [{'type': 6, 'timestamp': 0, 'data': [
  807. {'_TYPE': v:msgpack_types.binary, '_VAL': ["foo"]},
  808. {'_TYPE': v:msgpack_types.nil, '_VAL': ["foo"]},
  809. {'_TYPE': v:msgpack_types.nil, '_VAL': ["foo"]},
  810. ]}] ]]):gsub('\n', ''))
  811. end)
  812. it('works with global mark items', function()
  813. sd2strings_eq({
  814. 'Global mark with timestamp ' .. epoch .. ':',
  815. ' # Unexpected type: array instead of map',
  816. ' = [1, 2, 3]',
  817. }, {{type=7, timestamp=0, data={1, 2, 3}}})
  818. sd2strings_eq({
  819. 'Global mark with timestamp ' .. epoch .. ':',
  820. ' % Key Description Value',
  821. ' # Required key missing: n',
  822. ' # Required key missing: f',
  823. ' + l line number 1',
  824. ' + c column 0',
  825. }, ([[ [{'type': 7, 'timestamp': 0, 'data': {
  826. }}] ]]):gsub('\n', ''))
  827. sd2strings_eq({
  828. 'Global mark with timestamp ' .. epoch .. ':',
  829. ' % Key Description Value',
  830. ' # Expected integer',
  831. ' + n name "foo"',
  832. ' # Required key missing: f',
  833. ' + l line number 1',
  834. ' + c column 0',
  835. }, ([[ [{'type': 7, 'timestamp': 0, 'data': {
  836. 'n': 'foo',
  837. }}] ]]):gsub('\n', ''))
  838. sd2strings_eq({
  839. 'Global mark with timestamp ' .. epoch .. ':',
  840. ' % Key Description Value',
  841. ' # Required key missing: n',
  842. ' + f file name "foo"',
  843. ' + l line number 1',
  844. ' + c column 0',
  845. }, ([[ [{'type': 7, 'timestamp': 0, 'data': {
  846. 'f': 'foo',
  847. }}] ]]):gsub('\n', ''))
  848. sd2strings_eq({
  849. 'Global mark with timestamp ' .. epoch .. ':',
  850. ' % Key Description Value',
  851. ' # Value is negative',
  852. ' + n name -10',
  853. ' # Expected no NUL bytes',
  854. ' + f file name "\\0"',
  855. ' + l line number 1',
  856. ' + c column 0',
  857. }, ([[ [{'type': 7, 'timestamp': 0, 'data': {
  858. 'n': -10,
  859. 'f': {'_TYPE': v:msgpack_types.binary, '_VAL': ["\n"]},
  860. }}] ]]):gsub('\n', ''))
  861. sd2strings_eq({
  862. 'Global mark with timestamp ' .. epoch .. ':',
  863. ' % Key Description Value',
  864. ' + n name \'\\20\'',
  865. ' + f file name "foo"',
  866. ' # Value is negative',
  867. ' + l line number -10',
  868. ' # Value is negative',
  869. ' + c column -10',
  870. }, ([[ [{'type': 7, 'timestamp': 0, 'data': {
  871. 'n': 20,
  872. 'f': 'foo',
  873. 'l': -10,
  874. 'c': -10,
  875. }}] ]]):gsub('\n', ''))
  876. sd2strings_eq({
  877. 'Global mark with timestamp ' .. epoch .. ':',
  878. ' % Key Description Value',
  879. ' + n name 128',
  880. ' + f file name "foo"',
  881. ' + l line number 1',
  882. ' + c column 0',
  883. }, ([[ [{'type': 7, 'timestamp': 0, 'data': {
  884. 'n': 128,
  885. 'f': 'foo',
  886. }}] ]]):gsub('\n', ''))
  887. sd2strings_eq({
  888. 'Global mark with timestamp ' .. epoch .. ':',
  889. ' % Key Description Value',
  890. ' + n name \'\\20\'',
  891. ' + f file name "foo"',
  892. ' # Expected integer',
  893. ' + l line number "FOO"',
  894. ' # Expected integer',
  895. ' + c column "foo"',
  896. ' + mX 10',
  897. }, ([[ [{'type': 7, 'timestamp': 0, 'data': {
  898. 'n': 20,
  899. 'f': 'foo',
  900. 'l': 'FOO',
  901. 'c': 'foo',
  902. 'mX': 10,
  903. }}] ]]):gsub('\n', ''))
  904. sd2strings_eq({
  905. 'Global mark with timestamp ' .. epoch .. ':',
  906. ' % Key________ Description Value',
  907. ' + n name \'A\'',
  908. ' + f file name "foo"',
  909. ' + l line number 2',
  910. ' + c column 200',
  911. ' + mX 10',
  912. ' + mYYYYYYYYYY 10',
  913. }, ([[ [{'type': 7, 'timestamp': 0, 'data': {
  914. 'n': char2nr('A'),
  915. 'f': 'foo',
  916. 'l': 2,
  917. 'c': 200,
  918. 'mX': 10,
  919. 'mYYYYYYYYYY': 10,
  920. }}] ]]):gsub('\n', ''))
  921. end)
  922. it('works with jump items', function()
  923. sd2strings_eq({
  924. 'Jump with timestamp ' .. epoch .. ':',
  925. ' # Unexpected type: array instead of map',
  926. ' = [1, 2, 3]',
  927. }, {{type=8, timestamp=0, data={1, 2, 3}}})
  928. sd2strings_eq({
  929. 'Jump with timestamp ' .. epoch .. ':',
  930. ' % Key Description Value',
  931. ' # Required key missing: f',
  932. ' + l line number 1',
  933. ' + c column 0',
  934. }, ([[ [{'type': 8, 'timestamp': 0, 'data': {
  935. }}] ]]):gsub('\n', ''))
  936. sd2strings_eq({
  937. 'Jump with timestamp ' .. epoch .. ':',
  938. ' % Key Description Value',
  939. ' # Required key missing: f',
  940. ' + l line number 1',
  941. ' + c column 0',
  942. ' # Expected integer',
  943. ' + n name "foo"',
  944. }, ([[ [{'type': 8, 'timestamp': 0, 'data': {
  945. 'n': 'foo',
  946. }}] ]]):gsub('\n', ''))
  947. sd2strings_eq({
  948. 'Jump with timestamp ' .. epoch .. ':',
  949. ' % Key Description Value',
  950. ' + f file name "foo"',
  951. ' + l line number 1',
  952. ' + c column 0',
  953. }, ([[ [{'type': 8, 'timestamp': 0, 'data': {
  954. 'f': 'foo',
  955. }}] ]]):gsub('\n', ''))
  956. sd2strings_eq({
  957. 'Jump with timestamp ' .. epoch .. ':',
  958. ' % Key Description Value',
  959. ' # Expected no NUL bytes',
  960. ' + f file name "\\0"',
  961. ' + l line number 1',
  962. ' + c column 0',
  963. ' # Value is negative',
  964. ' + n name -10',
  965. }, ([[ [{'type': 8, 'timestamp': 0, 'data': {
  966. 'n': -10,
  967. 'f': {'_TYPE': v:msgpack_types.binary, '_VAL': ["\n"]},
  968. }}] ]]):gsub('\n', ''))
  969. sd2strings_eq({
  970. 'Jump with timestamp ' .. epoch .. ':',
  971. ' % Key Description Value',
  972. ' + f file name "foo"',
  973. ' # Value is negative',
  974. ' + l line number -10',
  975. ' # Value is negative',
  976. ' + c column -10',
  977. }, ([[ [{'type': 8, 'timestamp': 0, 'data': {
  978. 'f': 'foo',
  979. 'l': -10,
  980. 'c': -10,
  981. }}] ]]):gsub('\n', ''))
  982. sd2strings_eq({
  983. 'Jump with timestamp ' .. epoch .. ':',
  984. ' % Key Description Value',
  985. ' + f file name "foo"',
  986. ' # Expected integer',
  987. ' + l line number "FOO"',
  988. ' # Expected integer',
  989. ' + c column "foo"',
  990. ' + mX 10',
  991. }, ([[ [{'type': 8, 'timestamp': 0, 'data': {
  992. 'f': 'foo',
  993. 'l': 'FOO',
  994. 'c': 'foo',
  995. 'mX': 10,
  996. }}] ]]):gsub('\n', ''))
  997. sd2strings_eq({
  998. 'Jump with timestamp ' .. epoch .. ':',
  999. ' % Key________ Description Value',
  1000. ' + f file name "foo"',
  1001. ' + l line number 2',
  1002. ' + c column 200',
  1003. ' + mX 10',
  1004. ' + mYYYYYYYYYY 10',
  1005. ' + n name \' \'',
  1006. }, ([[ [{'type': 8, 'timestamp': 0, 'data': {
  1007. 'n': 0x20,
  1008. 'f': 'foo',
  1009. 'l': 2,
  1010. 'c': 200,
  1011. 'mX': 10,
  1012. 'mYYYYYYYYYY': 10,
  1013. }}] ]]):gsub('\n', ''))
  1014. end)
  1015. it('works with buffer list items', function()
  1016. sd2strings_eq({
  1017. 'Buffer list with timestamp ' .. epoch .. ':',
  1018. ' # Unexpected type: map instead of array',
  1019. ' = {="a": [10]}',
  1020. }, {{type=9, timestamp=0, data={a={10}}}})
  1021. sd2strings_eq({
  1022. 'Buffer list with timestamp ' .. epoch .. ':',
  1023. ' # Expected array of maps',
  1024. ' = [[], []]',
  1025. }, {{type=9, timestamp=0, data={{}, {}}}})
  1026. sd2strings_eq({
  1027. 'Buffer list with timestamp ' .. epoch .. ':',
  1028. ' # Expected array of maps',
  1029. ' = [{="a": 10}, []]',
  1030. }, {{type=9, timestamp=0, data={{a=10}, {}}}})
  1031. sd2strings_eq({
  1032. 'Buffer list with timestamp ' .. epoch .. ':',
  1033. ' % Key Description Value',
  1034. ' # Required key missing: f',
  1035. ' + l line number 1',
  1036. ' + c column 0',
  1037. ' + a 10',
  1038. }, {{type=9, timestamp=0, data={{a=10}}}})
  1039. sd2strings_eq({
  1040. 'Buffer list with timestamp ' .. epoch .. ':',
  1041. ' % Key Description Value',
  1042. ' # Required key missing: f',
  1043. ' # Expected integer',
  1044. ' + l line number "10"',
  1045. ' # Expected integer',
  1046. ' + c column "10"',
  1047. ' + a 10',
  1048. }, {{type=9, timestamp=0, data={{l='10', c='10', a=10}}}})
  1049. sd2strings_eq({
  1050. 'Buffer list with timestamp ' .. epoch .. ':',
  1051. ' % Key Description Value',
  1052. ' # Required key missing: f',
  1053. ' + l line number 10',
  1054. ' + c column 10',
  1055. ' + a 10',
  1056. }, {{type=9, timestamp=0, data={{l=10, c=10, a=10}}}})
  1057. sd2strings_eq({
  1058. 'Buffer list with timestamp ' .. epoch .. ':',
  1059. ' % Key Description Value',
  1060. ' # Required key missing: f',
  1061. ' # Value is negative',
  1062. ' + l line number -10',
  1063. ' # Value is negative',
  1064. ' + c column -10',
  1065. }, {{type=9, timestamp=0, data={{l=-10, c=-10}}}})
  1066. sd2strings_eq({
  1067. 'Buffer list with timestamp ' .. epoch .. ':',
  1068. ' % Key Description Value',
  1069. ' + f file name "abc"',
  1070. ' + l line number 1',
  1071. ' + c column 0',
  1072. }, {{type=9, timestamp=0, data={{f='abc'}}}})
  1073. sd2strings_eq({
  1074. 'Buffer list with timestamp ' .. epoch .. ':',
  1075. ' % Key Description Value',
  1076. ' # Expected binary string',
  1077. ' + f file name 10',
  1078. ' + l line number 1',
  1079. ' + c column 0',
  1080. '',
  1081. ' % Key Description Value',
  1082. ' # Expected binary string',
  1083. ' + f file name 20',
  1084. ' + l line number 1',
  1085. ' + c column 0',
  1086. }, {{type=9, timestamp=0, data={{f=10}, {f=20}}}})
  1087. sd2strings_eq({
  1088. 'Buffer list with timestamp ' .. epoch .. ':',
  1089. ' % Key Description Value',
  1090. ' # Expected binary string',
  1091. ' + f file name 10',
  1092. ' + l line number 1',
  1093. ' + c column 0',
  1094. '',
  1095. ' % Key Description Value',
  1096. ' # Expected no NUL bytes',
  1097. ' + f file name "\\0"',
  1098. ' + l line number 1',
  1099. ' + c column 0',
  1100. }, ([[ [{'type': 9, 'timestamp': 0, 'data': [
  1101. {'f': 10},
  1102. {'f': {'_TYPE': v:msgpack_types.binary, '_VAL': ["\n"]}},
  1103. ]}] ]]):gsub('\n', ''))
  1104. end)
  1105. it('works with local mark items', function()
  1106. sd2strings_eq({
  1107. 'Local mark with timestamp ' .. epoch .. ':',
  1108. ' # Unexpected type: array instead of map',
  1109. ' = [1, 2, 3]',
  1110. }, {{type=10, timestamp=0, data={1, 2, 3}}})
  1111. sd2strings_eq({
  1112. 'Local mark with timestamp ' .. epoch .. ':',
  1113. ' % Key Description Value',
  1114. ' # Required key missing: f',
  1115. ' + n name \'"\'',
  1116. ' + l line number 1',
  1117. ' + c column 0',
  1118. }, ([[ [{'type': 10, 'timestamp': 0, 'data': {
  1119. }}] ]]):gsub('\n', ''))
  1120. sd2strings_eq({
  1121. 'Local mark with timestamp ' .. epoch .. ':',
  1122. ' % Key Description Value',
  1123. ' # Required key missing: f',
  1124. ' # Expected integer',
  1125. ' + n name "foo"',
  1126. ' + l line number 1',
  1127. ' + c column 0',
  1128. }, ([[ [{'type': 10, 'timestamp': 0, 'data': {
  1129. 'n': 'foo',
  1130. }}] ]]):gsub('\n', ''))
  1131. sd2strings_eq({
  1132. 'Local mark with timestamp ' .. epoch .. ':',
  1133. ' % Key Description Value',
  1134. ' + f file name "foo"',
  1135. ' + n name \'"\'',
  1136. ' + l line number 1',
  1137. ' + c column 0',
  1138. }, ([[ [{'type': 10, 'timestamp': 0, 'data': {
  1139. 'f': 'foo',
  1140. }}] ]]):gsub('\n', ''))
  1141. sd2strings_eq({
  1142. 'Local mark with timestamp ' .. epoch .. ':',
  1143. ' % Key Description Value',
  1144. ' # Expected no NUL bytes',
  1145. ' + f file name "\\0"',
  1146. ' # Value is negative',
  1147. ' + n name -10',
  1148. ' + l line number 1',
  1149. ' + c column 0',
  1150. }, ([[ [{'type': 10, 'timestamp': 0, 'data': {
  1151. 'n': -10,
  1152. 'f': {'_TYPE': v:msgpack_types.binary, '_VAL': ["\n"]},
  1153. }}] ]]):gsub('\n', ''))
  1154. sd2strings_eq({
  1155. 'Local mark with timestamp ' .. epoch .. ':',
  1156. ' % Key Description Value',
  1157. ' + f file name "foo"',
  1158. ' + n name \'\\20\'',
  1159. ' # Value is negative',
  1160. ' + l line number -10',
  1161. ' # Value is negative',
  1162. ' + c column -10',
  1163. }, ([[ [{'type': 10, 'timestamp': 0, 'data': {
  1164. 'n': 20,
  1165. 'f': 'foo',
  1166. 'l': -10,
  1167. 'c': -10,
  1168. }}] ]]):gsub('\n', ''))
  1169. sd2strings_eq({
  1170. 'Local mark with timestamp ' .. epoch .. ':',
  1171. ' % Key Description Value',
  1172. ' + f file name "foo"',
  1173. ' + n name \'\\20\'',
  1174. ' # Expected integer',
  1175. ' + l line number "FOO"',
  1176. ' # Expected integer',
  1177. ' + c column "foo"',
  1178. ' + mX 10',
  1179. }, ([[ [{'type': 10, 'timestamp': 0, 'data': {
  1180. 'n': 20,
  1181. 'f': 'foo',
  1182. 'l': 'FOO',
  1183. 'c': 'foo',
  1184. 'mX': 10,
  1185. }}] ]]):gsub('\n', ''))
  1186. sd2strings_eq({
  1187. 'Local mark with timestamp ' .. epoch .. ':',
  1188. ' % Key________ Description Value',
  1189. ' + f file name "foo"',
  1190. ' + n name \'a\'',
  1191. ' + l line number 2',
  1192. ' + c column 200',
  1193. ' + mX 10',
  1194. ' + mYYYYYYYYYY 10',
  1195. }, ([[ [{'type': 10, 'timestamp': 0, 'data': {
  1196. 'n': char2nr('a'),
  1197. 'f': 'foo',
  1198. 'l': 2,
  1199. 'c': 200,
  1200. 'mX': 10,
  1201. 'mYYYYYYYYYY': 10,
  1202. }}] ]]):gsub('\n', ''))
  1203. end)
  1204. it('works with change items', function()
  1205. sd2strings_eq({
  1206. 'Change with timestamp ' .. epoch .. ':',
  1207. ' # Unexpected type: array instead of map',
  1208. ' = [1, 2, 3]',
  1209. }, {{type=11, timestamp=0, data={1, 2, 3}}})
  1210. sd2strings_eq({
  1211. 'Change with timestamp ' .. epoch .. ':',
  1212. ' % Key Description Value',
  1213. ' # Required key missing: f',
  1214. ' + l line number 1',
  1215. ' + c column 0',
  1216. }, ([[ [{'type': 11, 'timestamp': 0, 'data': {
  1217. }}] ]]):gsub('\n', ''))
  1218. sd2strings_eq({
  1219. 'Change with timestamp ' .. epoch .. ':',
  1220. ' % Key Description Value',
  1221. ' # Required key missing: f',
  1222. ' + l line number 1',
  1223. ' + c column 0',
  1224. ' # Expected integer',
  1225. ' + n name "foo"',
  1226. }, ([[ [{'type': 11, 'timestamp': 0, 'data': {
  1227. 'n': 'foo',
  1228. }}] ]]):gsub('\n', ''))
  1229. sd2strings_eq({
  1230. 'Change with timestamp ' .. epoch .. ':',
  1231. ' % Key Description Value',
  1232. ' + f file name "foo"',
  1233. ' + l line number 1',
  1234. ' + c column 0',
  1235. }, ([[ [{'type': 11, 'timestamp': 0, 'data': {
  1236. 'f': 'foo',
  1237. }}] ]]):gsub('\n', ''))
  1238. sd2strings_eq({
  1239. 'Change with timestamp ' .. epoch .. ':',
  1240. ' % Key Description Value',
  1241. ' # Expected no NUL bytes',
  1242. ' + f file name "\\0"',
  1243. ' + l line number 1',
  1244. ' + c column 0',
  1245. ' # Value is negative',
  1246. ' + n name -10',
  1247. }, ([[ [{'type': 11, 'timestamp': 0, 'data': {
  1248. 'n': -10,
  1249. 'f': {'_TYPE': v:msgpack_types.binary, '_VAL': ["\n"]},
  1250. }}] ]]):gsub('\n', ''))
  1251. sd2strings_eq({
  1252. 'Change with timestamp ' .. epoch .. ':',
  1253. ' % Key Description Value',
  1254. ' + f file name "foo"',
  1255. ' # Value is negative',
  1256. ' + l line number -10',
  1257. ' # Value is negative',
  1258. ' + c column -10',
  1259. }, ([[ [{'type': 11, 'timestamp': 0, 'data': {
  1260. 'f': 'foo',
  1261. 'l': -10,
  1262. 'c': -10,
  1263. }}] ]]):gsub('\n', ''))
  1264. sd2strings_eq({
  1265. 'Change with timestamp ' .. epoch .. ':',
  1266. ' % Key Description Value',
  1267. ' + f file name "foo"',
  1268. ' # Expected integer',
  1269. ' + l line number "FOO"',
  1270. ' # Expected integer',
  1271. ' + c column "foo"',
  1272. ' + mX 10',
  1273. }, ([[ [{'type': 11, 'timestamp': 0, 'data': {
  1274. 'f': 'foo',
  1275. 'l': 'FOO',
  1276. 'c': 'foo',
  1277. 'mX': 10,
  1278. }}] ]]):gsub('\n', ''))
  1279. sd2strings_eq({
  1280. 'Change with timestamp ' .. epoch .. ':',
  1281. ' % Key________ Description Value',
  1282. ' + f file name "foo"',
  1283. ' + l line number 2',
  1284. ' + c column 200',
  1285. ' + mX 10',
  1286. ' + mYYYYYYYYYY 10',
  1287. ' + n name \' \'',
  1288. }, ([[ [{'type': 11, 'timestamp': 0, 'data': {
  1289. 'n': 0x20,
  1290. 'f': 'foo',
  1291. 'l': 2,
  1292. 'c': 200,
  1293. 'mX': 10,
  1294. 'mYYYYYYYYYY': 10,
  1295. }}] ]]):gsub('\n', ''))
  1296. end)
  1297. end)
  1298. describe('function shada#get_strings', function()
  1299. it('works', function()
  1300. eq({
  1301. 'Header with timestamp ' .. epoch .. ':',
  1302. ' % Key Value',
  1303. }, nvim_eval('shada#get_strings(msgpackdump([1, 0, 0, {}]))'))
  1304. end)
  1305. end)
  1306. describe('function shada#strings_to_sd', function()
  1307. local strings2sd_eq = function(expected, input)
  1308. nvim('set_var', '__input', input)
  1309. nvim_command('let g:__actual = map(shada#strings_to_sd(g:__input), '
  1310. .. '"filter(v:val, \\"v:key[0] isnot# \'_\' '
  1311. .. '&& v:key isnot# \'length\'\\")")')
  1312. -- print()
  1313. if type(expected) == 'table' then
  1314. nvim('set_var', '__expected', expected)
  1315. nvim_command('let g:__expected = ModifyVal(g:__expected)')
  1316. expected = 'g:__expected'
  1317. -- print(nvim_eval('msgpack#string(g:__expected)'))
  1318. end
  1319. -- print(nvim_eval('msgpack#string(g:__actual)'))
  1320. eq(1, nvim_eval(('msgpack#equal(%s, g:__actual)'):format(expected)))
  1321. if type(expected) == 'table' then
  1322. nvim_command('unlet g:__expected')
  1323. end
  1324. nvim_command('unlet g:__input')
  1325. nvim_command('unlet g:__actual')
  1326. end
  1327. assert:set_parameter('TableFormatLevel', 100)
  1328. it('works with multiple items', function()
  1329. strings2sd_eq({{
  1330. type=11, timestamp=0, data={
  1331. f='foo',
  1332. l=2,
  1333. c=200,
  1334. mX=10,
  1335. mYYYYYYYYYY=10,
  1336. n=(' '):byte(),
  1337. }
  1338. }, {
  1339. type=1, timestamp=0, data={
  1340. c='abc',
  1341. f={'!binary', {'abc\ndef'}},
  1342. l=-10,
  1343. n=-64,
  1344. rc='10',
  1345. rt=10,
  1346. sc={'!nil', 0},
  1347. sm='TRUE',
  1348. so='TRUE',
  1349. sp={'!string', {'abc'}},
  1350. }
  1351. }}, {
  1352. 'Change with timestamp ' .. epoch .. ':',
  1353. ' % Key________ Description Value',
  1354. ' + f file name "foo"',
  1355. ' + l line number 2',
  1356. ' + c column 200',
  1357. ' + mX 10',
  1358. ' + mYYYYYYYYYY 10',
  1359. ' + n name \' \'',
  1360. 'Header with timestamp ' .. epoch .. ':',
  1361. ' % Key Description____ Value',
  1362. ' # Expected integer',
  1363. ' + c column "abc"',
  1364. ' # Expected no NUL bytes',
  1365. ' + f file name "abc\\0def"',
  1366. ' # Value is negative',
  1367. ' + l line number -10',
  1368. ' # Value is negative',
  1369. ' + n name -64',
  1370. ' # Expected array value',
  1371. ' + rc contents "10"',
  1372. ' # Unexpected enum value: expected one of '
  1373. .. '0 (CHARACTERWISE), 1 (LINEWISE), 2 (BLOCKWISE)',
  1374. ' + rt type 10',
  1375. ' # Expected boolean',
  1376. ' + sc smartcase value NIL',
  1377. ' # Expected boolean',
  1378. ' + sm magic value "TRUE"',
  1379. ' # Expected integer',
  1380. ' + so offset value "TRUE"',
  1381. ' # Expected binary string',
  1382. ' + sp pattern ="abc"',
  1383. })
  1384. end)
  1385. it('works with empty list', function()
  1386. strings2sd_eq({}, {})
  1387. end)
  1388. it('works with header items', function()
  1389. strings2sd_eq({{type=1, timestamp=0, data={
  1390. generator='test',
  1391. }}}, {
  1392. 'Header with timestamp ' .. epoch .. ':',
  1393. ' % Key______ Value',
  1394. ' + generator "test"',
  1395. })
  1396. strings2sd_eq({{type=1, timestamp=0, data={
  1397. 1, 2, 3,
  1398. }}}, {
  1399. 'Header with timestamp ' .. epoch .. ':',
  1400. ' # Unexpected type: array instead of map',
  1401. ' = [1, 2, 3]',
  1402. })
  1403. strings2sd_eq({{type=1, timestamp=0, data={
  1404. a=1, b=2, c=3, d=4,
  1405. }}}, {
  1406. 'Header with timestamp ' .. epoch .. ':',
  1407. ' % Key Description Value',
  1408. ' + a 1',
  1409. ' + b 2',
  1410. ' + c column 3',
  1411. ' + d 4',
  1412. })
  1413. strings2sd_eq({{type=1, timestamp=0, data={
  1414. c='abc',
  1415. f={'!binary', {'abc\ndef'}},
  1416. l=-10,
  1417. n=-64,
  1418. rc='10',
  1419. rt=10,
  1420. sc={'!nil', 0},
  1421. sm='TRUE',
  1422. so='TRUE',
  1423. sp={'!string', {'abc'}},
  1424. }}}, {
  1425. 'Header with timestamp ' .. epoch .. ':',
  1426. ' % Key Description____ Value',
  1427. ' # Expected integer',
  1428. ' + c column "abc"',
  1429. ' # Expected no NUL bytes',
  1430. ' + f file name "abc\\0def"',
  1431. ' # Value is negative',
  1432. ' + l line number -10',
  1433. ' # Value is negative',
  1434. ' + n name -64',
  1435. ' # Expected array value',
  1436. ' + rc contents "10"',
  1437. ' # Unexpected enum value: expected one of '
  1438. .. '0 (CHARACTERWISE), 1 (LINEWISE), 2 (BLOCKWISE)',
  1439. ' + rt type 10',
  1440. ' # Expected boolean',
  1441. ' + sc smartcase value NIL',
  1442. ' # Expected boolean',
  1443. ' + sm magic value "TRUE"',
  1444. ' # Expected integer',
  1445. ' + so offset value "TRUE"',
  1446. ' # Expected binary string',
  1447. ' + sp pattern ="abc"',
  1448. })
  1449. end)
  1450. it('works with search pattern items', function()
  1451. strings2sd_eq({{type=2, timestamp=0, data={
  1452. 1, 2, 3
  1453. }}}, {
  1454. 'Search pattern with timestamp ' .. epoch .. ':',
  1455. ' # Unexpected type: array instead of map',
  1456. ' = [1, 2, 3]',
  1457. })
  1458. strings2sd_eq({{type=2, timestamp=0, data={
  1459. sp='abc',
  1460. }}}, {
  1461. 'Search pattern with timestamp ' .. epoch .. ':',
  1462. ' % Key Description________ Value',
  1463. ' + sp pattern "abc"',
  1464. ' + sh v:hlsearch value FALSE',
  1465. ' + ss is :s pattern FALSE',
  1466. ' + sm magic value TRUE',
  1467. ' + sc smartcase value FALSE',
  1468. ' + sl has line offset FALSE',
  1469. ' + se place cursor at end FALSE',
  1470. ' + so offset value 0',
  1471. ' + su is last used TRUE',
  1472. })
  1473. strings2sd_eq({{type=2, timestamp=0, data={
  1474. sp='abc',
  1475. sX={'!nil', 0},
  1476. sY={'!nil', 0},
  1477. sZ={'!nil', 0},
  1478. }}}, {
  1479. 'Search pattern with timestamp ' .. epoch .. ':',
  1480. ' % Key Description________ Value',
  1481. ' + sp pattern "abc"',
  1482. ' + sh v:hlsearch value FALSE',
  1483. ' + ss is :s pattern FALSE',
  1484. ' + sm magic value TRUE',
  1485. ' + sc smartcase value FALSE',
  1486. ' + sl has line offset FALSE',
  1487. ' + se place cursor at end FALSE',
  1488. ' + so offset value 0',
  1489. ' + su is last used TRUE',
  1490. ' + sX NIL',
  1491. ' + sY NIL',
  1492. ' + sZ NIL',
  1493. })
  1494. strings2sd_eq({{type=2, timestamp=0, data={'!map', {
  1495. }}}}, {
  1496. 'Search pattern with timestamp ' .. epoch .. ':',
  1497. ' % Key Description________ Value',
  1498. ' # Required key missing: sp',
  1499. ' + sh v:hlsearch value FALSE',
  1500. ' + ss is :s pattern FALSE',
  1501. ' + sm magic value TRUE',
  1502. ' + sc smartcase value FALSE',
  1503. ' + sl has line offset FALSE',
  1504. ' + se place cursor at end FALSE',
  1505. ' + so offset value 0',
  1506. ' + su is last used TRUE',
  1507. })
  1508. strings2sd_eq({{type=2, timestamp=0, data={
  1509. sp='',
  1510. sh={'!boolean', 1},
  1511. ss={'!boolean', 1},
  1512. sc={'!boolean', 1},
  1513. sl={'!boolean', 1},
  1514. se={'!boolean', 1},
  1515. sm={'!boolean', 0},
  1516. su={'!boolean', 0},
  1517. so=-10,
  1518. }}}, {
  1519. 'Search pattern with timestamp ' .. epoch .. ':',
  1520. ' % Key Description________ Value',
  1521. ' + sp pattern ""',
  1522. ' + sh v:hlsearch value TRUE',
  1523. ' + ss is :s pattern TRUE',
  1524. ' + sm magic value FALSE',
  1525. ' + sc smartcase value TRUE',
  1526. ' + sl has line offset TRUE',
  1527. ' + se place cursor at end TRUE',
  1528. ' + so offset value -10',
  1529. ' + su is last used FALSE',
  1530. })
  1531. strings2sd_eq({{type=2, timestamp=0, data={
  1532. sp=0,
  1533. sh=0,
  1534. ss=0,
  1535. sc=0,
  1536. sl=0,
  1537. se=0,
  1538. sm=0,
  1539. su=0,
  1540. so='',
  1541. }}}, {
  1542. 'Search pattern with timestamp ' .. epoch .. ':',
  1543. ' % Key Description________ Value',
  1544. ' # Expected binary string',
  1545. ' + sp pattern 0',
  1546. ' # Expected boolean',
  1547. ' + sh v:hlsearch value 0',
  1548. ' # Expected boolean',
  1549. ' + ss is :s pattern 0',
  1550. ' # Expected boolean',
  1551. ' + sm magic value 0',
  1552. ' # Expected boolean',
  1553. ' + sc smartcase value 0',
  1554. ' # Expected boolean',
  1555. ' + sl has line offset 0',
  1556. ' # Expected boolean',
  1557. ' + se place cursor at end 0',
  1558. ' # Expected integer',
  1559. ' + so offset value ""',
  1560. ' # Expected boolean',
  1561. ' + su is last used 0',
  1562. })
  1563. end)
  1564. it('works with replacement string items', function()
  1565. strings2sd_eq({{type=3, timestamp=0, data={
  1566. a={10}
  1567. }}}, {
  1568. 'Replacement string with timestamp ' .. epoch .. ':',
  1569. ' # Unexpected type: map instead of array',
  1570. ' = {="a": [10]}',
  1571. })
  1572. strings2sd_eq({{type=3, timestamp=0, data={
  1573. }}}, {
  1574. 'Replacement string with timestamp ' .. epoch .. ':',
  1575. ' @ Description__________ Value',
  1576. ' # Expected more elements in list'
  1577. })
  1578. strings2sd_eq({{type=3, timestamp=0, data={
  1579. 0
  1580. }}}, {
  1581. 'Replacement string with timestamp ' .. epoch .. ':',
  1582. ' @ Description__________ Value',
  1583. ' # Expected binary string',
  1584. ' - :s replacement string 0',
  1585. })
  1586. strings2sd_eq({{type=3, timestamp=0, data={
  1587. 'abc\ndef', 0,
  1588. }}}, {
  1589. 'Replacement string with timestamp ' .. epoch .. ':',
  1590. ' @ Description__________ Value',
  1591. ' - :s replacement string "abc\\ndef"',
  1592. ' - 0',
  1593. })
  1594. strings2sd_eq({{type=3, timestamp=0, data={
  1595. 'abc\ndef',
  1596. }}}, {
  1597. 'Replacement string with timestamp ' .. epoch .. ':',
  1598. ' @ Description__________ Value',
  1599. ' - :s replacement string "abc\\ndef"',
  1600. })
  1601. end)
  1602. it('works with history entry items', function()
  1603. strings2sd_eq({{type=4, timestamp=0, data={
  1604. a={10},
  1605. }}}, {
  1606. 'History entry with timestamp ' .. epoch .. ':',
  1607. ' # Unexpected type: map instead of array',
  1608. ' = {="a": [10]}',
  1609. })
  1610. strings2sd_eq({{type=4, timestamp=0, data={
  1611. }}}, {
  1612. 'History entry with timestamp ' .. epoch .. ':',
  1613. ' @ Description_ Value',
  1614. ' # Expected more elements in list'
  1615. })
  1616. strings2sd_eq({{type=4, timestamp=0, data={
  1617. '',
  1618. }}}, {
  1619. 'History entry with timestamp ' .. epoch .. ':',
  1620. ' @ Description_ Value',
  1621. ' # Expected integer',
  1622. ' - history type ""',
  1623. ' # Expected more elements in list'
  1624. })
  1625. strings2sd_eq({{type=4, timestamp=0, data={
  1626. 5, '',
  1627. }}}, {
  1628. 'History entry with timestamp ' .. epoch .. ':',
  1629. ' @ Description_ Value',
  1630. ' # Unexpected enum value: expected one of 0 (CMD), 1 (SEARCH), '
  1631. .. '2 (EXPR), 3 (INPUT), 4 (DEBUG)',
  1632. ' - history type 5',
  1633. ' - contents ""',
  1634. })
  1635. strings2sd_eq({{type=4, timestamp=0, data={
  1636. 5, '', 32,
  1637. }}}, {
  1638. 'History entry with timestamp ' .. epoch .. ':',
  1639. ' @ Description_ Value',
  1640. ' # Unexpected enum value: expected one of 0 (CMD), 1 (SEARCH), '
  1641. .. '2 (EXPR), 3 (INPUT), 4 (DEBUG)',
  1642. ' - history type 5',
  1643. ' - contents ""',
  1644. ' - 32',
  1645. })
  1646. strings2sd_eq({{type=4, timestamp=0, data={
  1647. 0, '', 32,
  1648. }}}, {
  1649. 'History entry with timestamp ' .. epoch .. ':',
  1650. ' @ Description_ Value',
  1651. ' - history type CMD',
  1652. ' - contents ""',
  1653. ' - 32',
  1654. })
  1655. strings2sd_eq({{type=4, timestamp=0, data={
  1656. 1, '', 32,
  1657. }}}, {
  1658. 'History entry with timestamp ' .. epoch .. ':',
  1659. ' @ Description_ Value',
  1660. ' - history type SEARCH',
  1661. ' - contents ""',
  1662. ' - separator \' \'',
  1663. })
  1664. strings2sd_eq({{type=4, timestamp=0, data={
  1665. 1, '',
  1666. }}}, {
  1667. 'History entry with timestamp ' .. epoch .. ':',
  1668. ' @ Description_ Value',
  1669. ' - history type SEARCH',
  1670. ' - contents ""',
  1671. ' # Expected more elements in list',
  1672. })
  1673. strings2sd_eq({{type=4, timestamp=0, data={
  1674. 2, '',
  1675. }}}, {
  1676. 'History entry with timestamp ' .. epoch .. ':',
  1677. ' @ Description_ Value',
  1678. ' - history type EXPR',
  1679. ' - contents ""',
  1680. })
  1681. strings2sd_eq({{type=4, timestamp=0, data={
  1682. 3, ''
  1683. }}}, {
  1684. 'History entry with timestamp ' .. epoch .. ':',
  1685. ' @ Description_ Value',
  1686. ' - history type INPUT',
  1687. ' - contents ""',
  1688. })
  1689. strings2sd_eq({{type=4, timestamp=0, data={
  1690. 4, ''
  1691. }}}, {
  1692. 'History entry with timestamp ' .. epoch .. ':',
  1693. ' @ Description_ Value',
  1694. ' - history type DEBUG',
  1695. ' - contents ""',
  1696. })
  1697. end)
  1698. it('works with register items', function()
  1699. strings2sd_eq({{type=5, timestamp=0, data={
  1700. 1, 2, 3
  1701. }}}, {
  1702. 'Register with timestamp ' .. epoch .. ':',
  1703. ' # Unexpected type: array instead of map',
  1704. ' = [1, 2, 3]',
  1705. })
  1706. strings2sd_eq({{type=5, timestamp=0, data={'!map', {
  1707. }}}}, {
  1708. 'Register with timestamp ' .. epoch .. ':',
  1709. ' % Key Description Value',
  1710. ' # Required key missing: n',
  1711. ' # Required key missing: rc',
  1712. ' + rw block width 0',
  1713. ' + rt type CHARACTERWISE',
  1714. })
  1715. strings2sd_eq({{type=5, timestamp=0, data={
  1716. n=(' '):byte()
  1717. }}}, {
  1718. 'Register with timestamp ' .. epoch .. ':',
  1719. ' % Key Description Value',
  1720. ' + n name \' \'',
  1721. ' # Required key missing: rc',
  1722. ' + rw block width 0',
  1723. ' + rt type CHARACTERWISE',
  1724. })
  1725. strings2sd_eq({{type=5, timestamp=0, data={
  1726. n=(' '):byte(), rc={'abc', 'def'}
  1727. }}}, {
  1728. 'Register with timestamp ' .. epoch .. ':',
  1729. ' % Key Description Value',
  1730. ' + n name \' \'',
  1731. ' + rc contents ["abc", "def"]',
  1732. ' + rw block width 0',
  1733. ' + rt type CHARACTERWISE',
  1734. })
  1735. strings2sd_eq({{type=5, timestamp=0, data={
  1736. n=(' '):byte(),
  1737. rc={'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'},
  1738. }}}, {
  1739. 'Register with timestamp ' .. epoch .. ':',
  1740. ' % Key Description Value',
  1741. ' + n name \' \'',
  1742. ' + rc contents @',
  1743. ' | - "abcdefghijklmnopqrstuvwxyz"',
  1744. ' | - "abcdefghijklmnopqrstuvwxyz"',
  1745. ' + rw block width 0',
  1746. ' + rt type CHARACTERWISE',
  1747. })
  1748. strings2sd_eq({{type=5, timestamp=0, data={
  1749. n=(' '):byte(),
  1750. rc={'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'},
  1751. rw=5,
  1752. rt=1,
  1753. }}}, {
  1754. 'Register with timestamp ' .. epoch .. ':',
  1755. ' % Key Description Value',
  1756. ' + n name \' \'',
  1757. ' + rc contents @',
  1758. ' | - "abcdefghijklmnopqrstuvwxyz"',
  1759. ' | - "abcdefghijklmnopqrstuvwxyz"',
  1760. ' + rw block width 5',
  1761. ' + rt type LINEWISE',
  1762. })
  1763. strings2sd_eq({{type=5, timestamp=0, data={
  1764. n=(' '):byte(),
  1765. rc={'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'},
  1766. rw=5,
  1767. rt=2,
  1768. }}}, {
  1769. 'Register with timestamp ' .. epoch .. ':',
  1770. ' % Key Description Value',
  1771. ' + n name \' \'',
  1772. ' + rc contents @',
  1773. ' | - "abcdefghijklmnopqrstuvwxyz"',
  1774. ' | - "abcdefghijklmnopqrstuvwxyz"',
  1775. ' + rw block width 5',
  1776. ' + rt type BLOCKWISE',
  1777. })
  1778. strings2sd_eq({{type=5, timestamp=0, data={
  1779. n=(' '):byte(),
  1780. rc=0,
  1781. rw=-1,
  1782. rt=10,
  1783. }}}, {
  1784. 'Register with timestamp ' .. epoch .. ':',
  1785. ' % Key Description Value',
  1786. ' + n name \' \'',
  1787. ' # Expected array value',
  1788. ' + rc contents 0',
  1789. ' # Value is negative',
  1790. ' + rw block width -1',
  1791. ' # Unexpected enum value: expected one of 0 (CHARACTERWISE), '
  1792. .. '1 (LINEWISE), 2 (BLOCKWISE)',
  1793. ' + rt type 10',
  1794. })
  1795. end)
  1796. it('works with variable items', function()
  1797. strings2sd_eq({{type=6, timestamp=0, data={
  1798. a={10}
  1799. }}}, {
  1800. 'Variable with timestamp ' .. epoch .. ':',
  1801. ' # Unexpected type: map instead of array',
  1802. ' = {="a": [10]}',
  1803. })
  1804. strings2sd_eq({{type=6, timestamp=0, data={
  1805. }}}, {
  1806. 'Variable with timestamp ' .. epoch .. ':',
  1807. ' @ Description Value',
  1808. ' # Expected more elements in list'
  1809. })
  1810. strings2sd_eq({{type=6, timestamp=0, data={
  1811. 'foo',
  1812. }}}, {
  1813. 'Variable with timestamp ' .. epoch .. ':',
  1814. ' @ Description Value',
  1815. ' - name "foo"',
  1816. ' # Expected more elements in list',
  1817. })
  1818. strings2sd_eq({{type=6, timestamp=0, data={
  1819. 'foo', {'!nil', 0},
  1820. }}}, {
  1821. 'Variable with timestamp ' .. epoch .. ':',
  1822. ' @ Description Value',
  1823. ' - name "foo"',
  1824. ' - value NIL',
  1825. })
  1826. strings2sd_eq({{type=6, timestamp=0, data={
  1827. 'foo', {'!nil', 0}, {'!nil', 0}
  1828. }}}, {
  1829. 'Variable with timestamp ' .. epoch .. ':',
  1830. ' @ Description Value',
  1831. ' - name "foo"',
  1832. ' - value NIL',
  1833. ' - NIL',
  1834. })
  1835. end)
  1836. it('works with global mark items', function()
  1837. strings2sd_eq({{type=7, timestamp=0, data={
  1838. 1, 2, 3
  1839. }}}, {
  1840. 'Global mark with timestamp ' .. epoch .. ':',
  1841. ' # Unexpected type: array instead of map',
  1842. ' = [1, 2, 3]',
  1843. })
  1844. strings2sd_eq({{type=7, timestamp=0, data={
  1845. n=('A'):byte(), f='foo', l=2, c=200, mX=10, mYYYYYYYYYY=10,
  1846. }}}, {
  1847. 'Global mark with timestamp ' .. epoch .. ':',
  1848. ' % Key________ Description Value',
  1849. ' + n name \'A\'',
  1850. ' + f file name "foo"',
  1851. ' + l line number 2',
  1852. ' + c column 200',
  1853. ' + mX 10',
  1854. ' + mYYYYYYYYYY 10',
  1855. })
  1856. end)
  1857. it('works with jump items', function()
  1858. strings2sd_eq({{type=8, timestamp=0, data={
  1859. 1, 2, 3
  1860. }}}, {
  1861. 'Jump with timestamp ' .. epoch .. ':',
  1862. ' # Unexpected type: array instead of map',
  1863. ' = [1, 2, 3]',
  1864. })
  1865. strings2sd_eq({{type=8, timestamp=0, data={
  1866. n=('A'):byte(), f='foo', l=2, c=200, mX=10, mYYYYYYYYYY=10,
  1867. }}}, {
  1868. 'Jump with timestamp ' .. epoch .. ':',
  1869. ' % Key________ Description Value',
  1870. ' + n name \'A\'',
  1871. ' + f file name "foo"',
  1872. ' + l line number 2',
  1873. ' + c column 200',
  1874. ' + mX 10',
  1875. ' + mYYYYYYYYYY 10',
  1876. })
  1877. end)
  1878. it('works with buffer list items', function()
  1879. strings2sd_eq({{type=9, timestamp=0, data={
  1880. a={10}
  1881. }}}, {
  1882. 'Buffer list with timestamp ' .. epoch .. ':',
  1883. ' # Unexpected type: map instead of array',
  1884. ' = {="a": [10]}',
  1885. })
  1886. strings2sd_eq({{type=9, timestamp=0, data={
  1887. {a=10}, {}
  1888. }}}, {
  1889. 'Buffer list with timestamp ' .. epoch .. ':',
  1890. ' # Expected array of maps',
  1891. ' = [{="a": 10}, []]',
  1892. })
  1893. strings2sd_eq({{type=9, timestamp=0, data={
  1894. {a=10},
  1895. }}}, {
  1896. 'Buffer list with timestamp ' .. epoch .. ':',
  1897. ' % Key Description Value',
  1898. ' # Required key missing: f',
  1899. ' + l line number 1',
  1900. ' + c column 0',
  1901. ' + a 10',
  1902. })
  1903. strings2sd_eq({{type=9, timestamp=0, data={
  1904. {l='10', c='10', a=10},
  1905. }}}, {
  1906. 'Buffer list with timestamp ' .. epoch .. ':',
  1907. ' % Key Description Value',
  1908. ' # Required key missing: f',
  1909. ' # Expected integer',
  1910. ' + l line number "10"',
  1911. ' # Expected integer',
  1912. ' + c column "10"',
  1913. ' + a 10',
  1914. })
  1915. strings2sd_eq({{type=9, timestamp=0, data={
  1916. {l=10, c=10, a=10},
  1917. }}}, {
  1918. 'Buffer list with timestamp ' .. epoch .. ':',
  1919. ' % Key Description Value',
  1920. ' # Required key missing: f',
  1921. ' + l line number 10',
  1922. ' + c column 10',
  1923. ' + a 10',
  1924. })
  1925. strings2sd_eq({{type=9, timestamp=0, data={
  1926. {l=-10, c=-10},
  1927. }}}, {
  1928. 'Buffer list with timestamp ' .. epoch .. ':',
  1929. ' % Key Description Value',
  1930. ' # Required key missing: f',
  1931. ' # Value is negative',
  1932. ' + l line number -10',
  1933. ' # Value is negative',
  1934. ' + c column -10',
  1935. })
  1936. strings2sd_eq({{type=9, timestamp=0, data={
  1937. {f='abc'},
  1938. }}}, {
  1939. 'Buffer list with timestamp ' .. epoch .. ':',
  1940. ' % Key Description Value',
  1941. ' + f file name "abc"',
  1942. ' + l line number 1',
  1943. ' + c column 0',
  1944. })
  1945. strings2sd_eq({{type=9, timestamp=0, data={
  1946. {f=10}, {f=20},
  1947. }}}, {
  1948. 'Buffer list with timestamp ' .. epoch .. ':',
  1949. ' % Key Description Value',
  1950. ' # Expected binary string',
  1951. ' + f file name \'\\10\'',
  1952. ' + l line number 1',
  1953. ' + c column 0',
  1954. '',
  1955. ' % Key Description Value',
  1956. ' # Expected binary string',
  1957. ' + f file name \'\\20\'',
  1958. ' + l line number 1',
  1959. ' + c column 0',
  1960. })
  1961. strings2sd_eq({{type=9, timestamp=0, data={
  1962. {f=10}, {f={'!binary', {'\n'}}},
  1963. }}}, {
  1964. 'Buffer list with timestamp ' .. epoch .. ':',
  1965. ' % Key Description Value',
  1966. ' # Expected binary string',
  1967. ' + f file name \'\\10\'',
  1968. ' + l line number 1',
  1969. ' + c column 0',
  1970. '',
  1971. ' % Key Description Value',
  1972. ' # Expected no NUL bytes',
  1973. ' + f file name "\\0"',
  1974. ' + l line number 1',
  1975. ' + c column 0',
  1976. })
  1977. end)
  1978. it('works with local mark items', function()
  1979. strings2sd_eq({{type=10, timestamp=0, data={
  1980. 1, 2, 3
  1981. }}}, {
  1982. 'Local mark with timestamp ' .. epoch .. ':',
  1983. ' # Unexpected type: array instead of map',
  1984. ' = [1, 2, 3]',
  1985. })
  1986. strings2sd_eq({{type=10, timestamp=0, data={
  1987. n=('A'):byte(), f='foo', l=2, c=200, mX=10, mYYYYYYYYYY=10,
  1988. }}}, {
  1989. 'Local mark with timestamp ' .. epoch .. ':',
  1990. ' % Key________ Description Value',
  1991. ' + n name \'A\'',
  1992. ' + f file name "foo"',
  1993. ' + l line number 2',
  1994. ' + c column 200',
  1995. ' + mX 10',
  1996. ' + mYYYYYYYYYY 10',
  1997. })
  1998. end)
  1999. it('works with change items', function()
  2000. strings2sd_eq({{type=11, timestamp=0, data={
  2001. 1, 2, 3
  2002. }}}, {
  2003. 'Change with timestamp ' .. epoch .. ':',
  2004. ' # Unexpected type: array instead of map',
  2005. ' = [1, 2, 3]',
  2006. })
  2007. strings2sd_eq({{type=11, timestamp=0, data={
  2008. n=('A'):byte(), f='foo', l=2, c=200, mX=10, mYYYYYYYYYY=10,
  2009. }}}, {
  2010. 'Change with timestamp ' .. epoch .. ':',
  2011. ' % Key________ Description Value',
  2012. ' + n name \'A\'',
  2013. ' + f file name "foo"',
  2014. ' + l line number 2',
  2015. ' + c column 200',
  2016. ' + mX 10',
  2017. ' + mYYYYYYYYYY 10',
  2018. })
  2019. end)
  2020. end)
  2021. describe('function shada#get_binstrings', function()
  2022. local getbstrings_eq = function(expected, input)
  2023. local result = funcs['shada#get_binstrings'](input)
  2024. for i, s in ipairs(result) do
  2025. result[i] = s:gsub('\n', '\0')
  2026. end
  2027. local mpack_result = table.concat(result, '\n')
  2028. return mpack_eq(expected, mpack_result)
  2029. end
  2030. it('works', function()
  2031. local version = nvim('get_vvar', 'version')
  2032. getbstrings_eq({{timestamp='current', type=1, value={
  2033. generator='shada.vim',
  2034. version=version,
  2035. }}}, {})
  2036. getbstrings_eq({
  2037. {timestamp='current', type=1, value={
  2038. generator='shada.vim', version=version
  2039. }},
  2040. {timestamp=0, type=1, value={generator='test'}}
  2041. }, {
  2042. 'Header with timestamp ' .. epoch .. ':',
  2043. ' % Key______ Value',
  2044. ' + generator "test"',
  2045. })
  2046. nvim('set_var', 'shada#add_own_header', 1)
  2047. getbstrings_eq({{timestamp='current', type=1, value={
  2048. generator='shada.vim',
  2049. version=version,
  2050. }}}, {})
  2051. getbstrings_eq({
  2052. {timestamp='current', type=1, value={
  2053. generator='shada.vim', version=version
  2054. }},
  2055. {timestamp=0, type=1, value={generator='test'}}
  2056. }, {
  2057. 'Header with timestamp ' .. epoch .. ':',
  2058. ' % Key______ Value',
  2059. ' + generator "test"',
  2060. })
  2061. nvim('set_var', 'shada#add_own_header', 0)
  2062. getbstrings_eq({}, {})
  2063. getbstrings_eq({{timestamp=0, type=1, value={generator='test'}}}, {
  2064. 'Header with timestamp ' .. epoch .. ':',
  2065. ' % Key______ Value',
  2066. ' + generator "test"',
  2067. })
  2068. nvim('set_var', 'shada#keep_old_header', 0)
  2069. getbstrings_eq({}, {
  2070. 'Header with timestamp ' .. epoch .. ':',
  2071. ' % Key______ Value',
  2072. ' + generator "test"',
  2073. })
  2074. getbstrings_eq({
  2075. {type=3, timestamp=0, value={'abc\ndef'}},
  2076. {type=3, timestamp=0, value={'abc\ndef'}},
  2077. {type=3, timestamp=0, value={'abc\ndef'}},
  2078. }, {
  2079. 'Replacement string with timestamp ' .. epoch .. ':',
  2080. ' @ Description__________ Value',
  2081. ' - :s replacement string "abc\\ndef"',
  2082. 'Replacement string with timestamp ' .. epoch .. ':',
  2083. ' @ Description__________ Value',
  2084. ' - :s replacement string "abc\\ndef"',
  2085. 'Replacement string with timestamp ' .. epoch .. ':',
  2086. ' @ Description__________ Value',
  2087. ' - :s replacement string "abc\\ndef"',
  2088. })
  2089. end)
  2090. end)
  2091. end)
  2092. describe('plugin/shada.vim', function()
  2093. local epoch = os.date('%Y-%m-%dT%H:%M:%S', 0)
  2094. local eol = helpers.iswin() and '\r\n' or '\n'
  2095. before_each(function()
  2096. reset()
  2097. os.remove(fname)
  2098. os.remove(fname .. '.tst')
  2099. os.remove(fname_tmp)
  2100. end)
  2101. teardown(function()
  2102. os.remove(fname)
  2103. os.remove(fname_tmp)
  2104. end)
  2105. local shada_eq = function(expected, fname_)
  2106. local mpack_result = read_file(fname_)
  2107. mpack_eq(expected, mpack_result)
  2108. end
  2109. describe('event BufReadCmd', function()
  2110. it('works', function()
  2111. wshada('\004\000\009\147\000\196\002ab\196\001a')
  2112. wshada_tmp('\004\000\009\147\000\196\002ab\196\001b')
  2113. nvim_command('edit ' .. fname)
  2114. eq({
  2115. 'History entry with timestamp ' .. epoch .. ':',
  2116. ' @ Description_ Value',
  2117. ' - history type CMD',
  2118. ' - contents "ab"',
  2119. ' - "a"',
  2120. }, nvim_eval('getline(1, "$")'))
  2121. eq(false, curbuf('get_option', 'modified'))
  2122. eq('shada', curbuf('get_option', 'filetype'))
  2123. nvim_command('edit ' .. fname_tmp)
  2124. eq({
  2125. 'History entry with timestamp ' .. epoch .. ':',
  2126. ' @ Description_ Value',
  2127. ' - history type CMD',
  2128. ' - contents "ab"',
  2129. ' - "b"',
  2130. }, nvim_eval('getline(1, "$")'))
  2131. eq(false, curbuf('get_option', 'modified'))
  2132. eq('shada', curbuf('get_option', 'filetype'))
  2133. eq('++opt not supported', exc_exec('edit ++enc=latin1 ' .. fname))
  2134. neq({
  2135. 'History entry with timestamp ' .. epoch .. ':',
  2136. ' @ Description_ Value',
  2137. ' - history type CMD',
  2138. ' - contents "ab"',
  2139. ' - "a"',
  2140. }, nvim_eval('getline(1, "$")'))
  2141. neq(true, curbuf('get_option', 'modified'))
  2142. end)
  2143. end)
  2144. describe('event FileReadCmd', function()
  2145. it('works', function()
  2146. wshada('\004\000\009\147\000\196\002ab\196\001a')
  2147. wshada_tmp('\004\000\009\147\000\196\002ab\196\001b')
  2148. nvim_command('$read ' .. fname)
  2149. eq({
  2150. '',
  2151. 'History entry with timestamp ' .. epoch .. ':',
  2152. ' @ Description_ Value',
  2153. ' - history type CMD',
  2154. ' - contents "ab"',
  2155. ' - "a"',
  2156. }, nvim_eval('getline(1, "$")'))
  2157. eq(true, curbuf('get_option', 'modified'))
  2158. neq('shada', curbuf('get_option', 'filetype'))
  2159. nvim_command('1,$read ' .. fname_tmp)
  2160. eq({
  2161. '',
  2162. 'History entry with timestamp ' .. epoch .. ':',
  2163. ' @ Description_ Value',
  2164. ' - history type CMD',
  2165. ' - contents "ab"',
  2166. ' - "a"',
  2167. 'History entry with timestamp ' .. epoch .. ':',
  2168. ' @ Description_ Value',
  2169. ' - history type CMD',
  2170. ' - contents "ab"',
  2171. ' - "b"',
  2172. }, nvim_eval('getline(1, "$")'))
  2173. eq(true, curbuf('get_option', 'modified'))
  2174. neq('shada', curbuf('get_option', 'filetype'))
  2175. curbuf('set_option', 'modified', false)
  2176. eq('++opt not supported', exc_exec('$read ++enc=latin1 ' .. fname))
  2177. eq({
  2178. '',
  2179. 'History entry with timestamp ' .. epoch .. ':',
  2180. ' @ Description_ Value',
  2181. ' - history type CMD',
  2182. ' - contents "ab"',
  2183. ' - "a"',
  2184. 'History entry with timestamp ' .. epoch .. ':',
  2185. ' @ Description_ Value',
  2186. ' - history type CMD',
  2187. ' - contents "ab"',
  2188. ' - "b"',
  2189. }, nvim_eval('getline(1, "$")'))
  2190. neq(true, curbuf('get_option', 'modified'))
  2191. end)
  2192. end)
  2193. describe('event BufWriteCmd', function()
  2194. it('works', function()
  2195. nvim('set_var', 'shada#add_own_header', 0)
  2196. curbuf('set_lines', 0, 1, true, {
  2197. 'Jump with timestamp ' .. epoch .. ':',
  2198. ' % Key________ Description Value',
  2199. ' + n name \'A\'',
  2200. ' + f file name ["foo"]',
  2201. ' + l line number 2',
  2202. ' + c column -200',
  2203. 'Jump with timestamp ' .. epoch .. ':',
  2204. ' % Key________ Description Value',
  2205. ' + n name \'A\'',
  2206. ' + f file name ["foo"]',
  2207. ' + l line number 2',
  2208. ' + c column -200',
  2209. })
  2210. nvim_command('w ' .. fname .. '.tst')
  2211. nvim_command('w ' .. fname)
  2212. nvim_command('w ' .. fname_tmp)
  2213. eq('++opt not supported', exc_exec('w! ++enc=latin1 ' .. fname))
  2214. eq(table.concat({
  2215. 'Jump with timestamp ' .. epoch .. ':',
  2216. ' % Key________ Description Value',
  2217. ' + n name \'A\'',
  2218. ' + f file name ["foo"]',
  2219. ' + l line number 2',
  2220. ' + c column -200',
  2221. 'Jump with timestamp ' .. epoch .. ':',
  2222. ' % Key________ Description Value',
  2223. ' + n name \'A\'',
  2224. ' + f file name ["foo"]',
  2225. ' + l line number 2',
  2226. ' + c column -200',
  2227. }, eol) .. eol, read_file(fname .. '.tst'))
  2228. shada_eq({{
  2229. timestamp=0,
  2230. type=8,
  2231. value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
  2232. }, {
  2233. timestamp=0,
  2234. type=8,
  2235. value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
  2236. }}, fname)
  2237. shada_eq({{
  2238. timestamp=0,
  2239. type=8,
  2240. value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
  2241. }, {
  2242. timestamp=0,
  2243. type=8,
  2244. value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
  2245. }}, fname_tmp)
  2246. end)
  2247. end)
  2248. describe('event FileWriteCmd', function()
  2249. it('works', function()
  2250. nvim('set_var', 'shada#add_own_header', 0)
  2251. curbuf('set_lines', 0, 1, true, {
  2252. 'Jump with timestamp ' .. epoch .. ':',
  2253. ' % Key________ Description Value',
  2254. ' + n name \'A\'',
  2255. ' + f file name ["foo"]',
  2256. ' + l line number 2',
  2257. ' + c column -200',
  2258. 'Jump with timestamp ' .. epoch .. ':',
  2259. ' % Key________ Description Value',
  2260. ' + n name \'A\'',
  2261. ' + f file name ["foo"]',
  2262. ' + l line number 2',
  2263. ' + c column -200',
  2264. })
  2265. nvim_command('1,3w ' .. fname .. '.tst')
  2266. nvim_command('1,3w ' .. fname)
  2267. nvim_command('1,3w ' .. fname_tmp)
  2268. eq('++opt not supported', exc_exec('1,3w! ++enc=latin1 ' .. fname))
  2269. eq(table.concat({
  2270. 'Jump with timestamp ' .. epoch .. ':',
  2271. ' % Key________ Description Value',
  2272. ' + n name \'A\'',
  2273. }, eol) .. eol, read_file(fname .. '.tst'))
  2274. shada_eq({{
  2275. timestamp=0,
  2276. type=8,
  2277. value={n=('A'):byte()},
  2278. }}, fname)
  2279. shada_eq({{
  2280. timestamp=0,
  2281. type=8,
  2282. value={n=('A'):byte()},
  2283. }}, fname_tmp)
  2284. end)
  2285. end)
  2286. describe('event FileAppendCmd', function()
  2287. it('works', function()
  2288. nvim('set_var', 'shada#add_own_header', 0)
  2289. curbuf('set_lines', 0, 1, true, {
  2290. 'Jump with timestamp ' .. epoch .. ':',
  2291. ' % Key________ Description Value',
  2292. ' + n name \'A\'',
  2293. ' + f file name ["foo"]',
  2294. ' + l line number 2',
  2295. ' + c column -200',
  2296. 'Jump with timestamp ' .. epoch .. ':',
  2297. ' % Key________ Description Value',
  2298. ' + n name \'A\'',
  2299. ' + f file name ["foo"]',
  2300. ' + l line number 2',
  2301. ' + c column -200',
  2302. })
  2303. funcs.writefile({''}, fname .. '.tst', 'b')
  2304. funcs.writefile({''}, fname, 'b')
  2305. funcs.writefile({''}, fname_tmp, 'b')
  2306. nvim_command('1,3w >> ' .. fname .. '.tst')
  2307. nvim_command('1,3w >> ' .. fname)
  2308. nvim_command('1,3w >> ' .. fname_tmp)
  2309. nvim_command('w >> ' .. fname .. '.tst')
  2310. nvim_command('w >> ' .. fname)
  2311. nvim_command('w >> ' .. fname_tmp)
  2312. eq('++opt not supported', exc_exec('1,3w! ++enc=latin1 >> ' .. fname))
  2313. eq(table.concat({
  2314. 'Jump with timestamp ' .. epoch .. ':',
  2315. ' % Key________ Description Value',
  2316. ' + n name \'A\'',
  2317. 'Jump with timestamp ' .. epoch .. ':',
  2318. ' % Key________ Description Value',
  2319. ' + n name \'A\'',
  2320. ' + f file name ["foo"]',
  2321. ' + l line number 2',
  2322. ' + c column -200',
  2323. 'Jump with timestamp ' .. epoch .. ':',
  2324. ' % Key________ Description Value',
  2325. ' + n name \'A\'',
  2326. ' + f file name ["foo"]',
  2327. ' + l line number 2',
  2328. ' + c column -200',
  2329. }, eol) .. eol, read_file(fname .. '.tst'))
  2330. shada_eq({{
  2331. timestamp=0,
  2332. type=8,
  2333. value={n=('A'):byte()},
  2334. }, {
  2335. timestamp=0,
  2336. type=8,
  2337. value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
  2338. }, {
  2339. timestamp=0,
  2340. type=8,
  2341. value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
  2342. }}, fname)
  2343. shada_eq({{
  2344. timestamp=0,
  2345. type=8,
  2346. value={n=('A'):byte()},
  2347. }, {
  2348. timestamp=0,
  2349. type=8,
  2350. value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
  2351. }, {
  2352. timestamp=0,
  2353. type=8,
  2354. value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
  2355. }}, fname_tmp)
  2356. end)
  2357. end)
  2358. describe('event SourceCmd', function()
  2359. before_each(function()
  2360. reset(fname)
  2361. end)
  2362. it('works', function()
  2363. wshada('\004\000\006\146\000\196\002ab')
  2364. wshada_tmp('\004\001\006\146\000\196\002bc')
  2365. eq(0, exc_exec('source ' .. fname))
  2366. eq(0, exc_exec('source ' .. fname_tmp))
  2367. eq('bc', funcs.histget(':', -1))
  2368. eq('ab', funcs.histget(':', -2))
  2369. end)
  2370. end)
  2371. end)
  2372. describe('ftplugin/shada.vim', function()
  2373. local epoch = os.date('%Y-%m-%dT%H:%M:%S', 0)
  2374. before_each(reset)
  2375. it('sets indentexpr correctly', function()
  2376. nvim_command('filetype plugin indent on')
  2377. nvim_command('setlocal filetype=shada')
  2378. funcs.setline(1, {
  2379. 'Jump with timestamp ' .. epoch .. ':',
  2380. '% Key________ Description Value',
  2381. '+ n name \'A\'',
  2382. '+ f file name "foo"',
  2383. '+ l line number 2',
  2384. '+ c column 200',
  2385. '+ mX 10',
  2386. '+ mYYYYYYYYYY 10',
  2387. 'Register with timestamp ' .. epoch .. ':',
  2388. '% Key Description Value',
  2389. '+ n name \' \'',
  2390. '+ rc contents @',
  2391. '| - "abcdefghijklmnopqrstuvwxyz"',
  2392. '| - "abcdefghijklmnopqrstuvwxyz"',
  2393. '+ rw block width 0',
  2394. '+ rt type CHARACTERWISE',
  2395. 'Replacement string with timestamp ' .. epoch .. ':',
  2396. ' @ Description__________ Value',
  2397. ' - :s replacement string "abc\\ndef"',
  2398. ' Buffer list with timestamp ' .. epoch .. ':',
  2399. ' # Expected array of maps',
  2400. '= [{="a": 10}, []]',
  2401. ' Buffer list with timestamp ' .. epoch .. ':',
  2402. ' % Key Description Value',
  2403. ' # Expected binary string',
  2404. '+ f file name 10',
  2405. ' + l line number 1',
  2406. ' + c column 0',
  2407. '',
  2408. ' % Key Description Value',
  2409. ' # Expected binary string',
  2410. ' + f file name 20',
  2411. '+ l line number 1',
  2412. ' + c column 0',
  2413. })
  2414. nvim_command('normal! gg=G')
  2415. eq({
  2416. 'Jump with timestamp ' .. epoch .. ':',
  2417. ' % Key________ Description Value',
  2418. ' + n name \'A\'',
  2419. ' + f file name "foo"',
  2420. ' + l line number 2',
  2421. ' + c column 200',
  2422. ' + mX 10',
  2423. ' + mYYYYYYYYYY 10',
  2424. 'Register with timestamp ' .. epoch .. ':',
  2425. ' % Key Description Value',
  2426. ' + n name \' \'',
  2427. ' + rc contents @',
  2428. ' | - "abcdefghijklmnopqrstuvwxyz"',
  2429. ' | - "abcdefghijklmnopqrstuvwxyz"',
  2430. ' + rw block width 0',
  2431. ' + rt type CHARACTERWISE',
  2432. 'Replacement string with timestamp ' .. epoch .. ':',
  2433. ' @ Description__________ Value',
  2434. ' - :s replacement string "abc\\ndef"',
  2435. 'Buffer list with timestamp ' .. epoch .. ':',
  2436. ' # Expected array of maps',
  2437. ' = [{="a": 10}, []]',
  2438. 'Buffer list with timestamp ' .. epoch .. ':',
  2439. ' % Key Description Value',
  2440. ' # Expected binary string',
  2441. ' + f file name 10',
  2442. ' + l line number 1',
  2443. ' + c column 0',
  2444. '',
  2445. ' % Key Description Value',
  2446. ' # Expected binary string',
  2447. ' + f file name 20',
  2448. ' + l line number 1',
  2449. ' + c column 0',
  2450. }, funcs.getline(1, funcs.line('$')))
  2451. end)
  2452. it('sets options correctly', function()
  2453. nvim_command('filetype plugin indent on')
  2454. nvim_command('setlocal filetype=shada')
  2455. eq(true, curbuf('get_option', 'expandtab'))
  2456. eq(2, curbuf('get_option', 'tabstop'))
  2457. eq(2, curbuf('get_option', 'softtabstop'))
  2458. eq(2, curbuf('get_option', 'shiftwidth'))
  2459. end)
  2460. it('sets indentkeys correctly', function()
  2461. nvim_command('filetype plugin indent on')
  2462. nvim_command('setlocal filetype=shada')
  2463. funcs.setline(1, ' Replacement with timestamp ' .. epoch)
  2464. nvim_feed('ggA:\027')
  2465. eq('Replacement with timestamp ' .. epoch .. ':', curbuf('get_lines', 0, 1, true)[1])
  2466. nvim_feed('o-\027')
  2467. eq({' -'}, curbuf('get_lines', 1, 2, true))
  2468. nvim_feed('ggO+\027')
  2469. eq({'+'}, curbuf('get_lines', 0, 1, true))
  2470. nvim_feed('GO*\027')
  2471. eq({' *'}, curbuf('get_lines', 2, 3, true))
  2472. nvim_feed('ggO /\027')
  2473. eq({' /'}, curbuf('get_lines', 0, 1, true))
  2474. nvim_feed('ggOx\027')
  2475. eq({'x'}, curbuf('get_lines', 0, 1, true))
  2476. end)
  2477. end)
  2478. describe('syntax/shada.vim', function()
  2479. local epoch = os.date('%Y-%m-%dT%H:%M:%S', 0)
  2480. before_each(reset)
  2481. it('works', function()
  2482. nvim_command('syntax on')
  2483. nvim_command('setlocal syntax=shada')
  2484. curbuf('set_lines', 0, 1, true, {
  2485. 'Header with timestamp ' .. epoch .. ':',
  2486. ' % Key Value',
  2487. ' + t "test"',
  2488. 'Jump with timestamp ' .. epoch .. ':',
  2489. ' % Key________ Description Value',
  2490. ' + n name \'A\'',
  2491. ' + f file name ["foo"]',
  2492. ' + l line number 2',
  2493. ' + c column -200',
  2494. 'Register with timestamp ' .. epoch .. ':',
  2495. ' % Key Description Value',
  2496. ' + rc contents @',
  2497. ' | - {"abcdefghijklmnopqrstuvwxyz": 1.0}',
  2498. ' + rt type CHARACTERWISE',
  2499. ' + rt type LINEWISE',
  2500. ' + rt type BLOCKWISE',
  2501. 'Replacement string with timestamp ' .. epoch .. ':',
  2502. ' @ Description__________ Value',
  2503. ' - :s replacement string CMD',
  2504. ' - :s replacement string SEARCH',
  2505. ' - :s replacement string EXPR',
  2506. ' - :s replacement string INPUT',
  2507. ' - :s replacement string DEBUG',
  2508. 'Buffer list with timestamp ' .. epoch .. ':',
  2509. ' # Expected array of maps',
  2510. ' = [{="a": +(10)"ac\\0df\\ngi\\"tt\\.", TRUE: FALSE}, [NIL, +(-10)""]]',
  2511. 'Buffer list with timestamp ' .. epoch .. ':',
  2512. ' % Key Description Value',
  2513. '',
  2514. ' % Key Description Value',
  2515. 'Header with timestamp ' .. epoch .. ':',
  2516. ' % Key Description________ Value',
  2517. ' + se place cursor at end TRUE',
  2518. })
  2519. nvim_command([[
  2520. function GetSyntax()
  2521. let lines = []
  2522. for l in range(1, line('$'))
  2523. let columns = []
  2524. let line = getline(l)
  2525. for c in range(1, col([l, '$']) - 1)
  2526. let synstack = map(synstack(l, c), 'synIDattr(v:val, "name")')
  2527. if !empty(columns) && columns[-1][0] ==# synstack
  2528. let columns[-1][1] .= line[c - 1]
  2529. else
  2530. call add(columns, [ synstack, line[c - 1] ])
  2531. endif
  2532. endfor
  2533. call add(lines, columns)
  2534. endfor
  2535. return lines
  2536. endfunction
  2537. ]])
  2538. local hname = function(s) return {{'ShaDaEntryHeader', 'ShaDaEntryName'},
  2539. s} end
  2540. local h = function(s) return {{'ShaDaEntryHeader'}, s} end
  2541. local htsnum = function(s) return {
  2542. {'ShaDaEntryHeader', 'ShaDaEntryTimestamp', 'ShaDaEntryTimestampNumber'},
  2543. s
  2544. } end
  2545. local synhtssep = function(s)
  2546. return {{'ShaDaEntryHeader', 'ShaDaEntryTimestamp'}, s}
  2547. end
  2548. local synepoch = {
  2549. year = htsnum(os.date('%Y', 0)),
  2550. month = htsnum(os.date('%m', 0)),
  2551. day = htsnum(os.date('%d', 0)),
  2552. hour = htsnum(os.date('%H', 0)),
  2553. minute = htsnum(os.date('%M', 0)),
  2554. second = htsnum(os.date('%S', 0)),
  2555. }
  2556. local msh = function(s) return {{'ShaDaEntryMapShort',
  2557. 'ShaDaEntryMapHeader'}, s} end
  2558. local mlh = function(s) return {{'ShaDaEntryMapLong',
  2559. 'ShaDaEntryMapHeader'}, s} end
  2560. local ah = function(s) return {{'ShaDaEntryArray',
  2561. 'ShaDaEntryArrayHeader'}, s} end
  2562. -- luacheck: ignore
  2563. local mses = function(s) return {{'ShaDaEntryMapShort',
  2564. 'ShaDaEntryMapShortEntryStart'}, s} end
  2565. local mles = function(s) return {{'ShaDaEntryMapLong',
  2566. 'ShaDaEntryMapLongEntryStart'}, s} end
  2567. local act = funcs.GetSyntax()
  2568. local ms = function(syn)
  2569. return {
  2570. {'ShaDaEntryMap' .. syn, 'ShaDaEntryMap' .. syn .. 'EntryStart'}, ' + '
  2571. }
  2572. end
  2573. local as = function()
  2574. return {{'ShaDaEntryArray', 'ShaDaEntryArrayEntryStart'}, ' - '}
  2575. end
  2576. local ad = function(s) return {{'ShaDaEntryArray',
  2577. 'ShaDaEntryArrayDescription'}, s} end
  2578. local mbas = function(syn)
  2579. return {
  2580. {'ShaDaEntryMap' .. syn, 'ShaDaEntryMapBinArrayStart'},
  2581. ' | - '
  2582. }
  2583. end
  2584. local msk = function(s) return {{'ShaDaEntryMapShort',
  2585. 'ShaDaEntryMapShortKey'}, s} end
  2586. local mlk = function(s) return {{'ShaDaEntryMapLong',
  2587. 'ShaDaEntryMapLongKey'}, s} end
  2588. local mld = function(s) return {{'ShaDaEntryMapLong',
  2589. 'ShaDaEntryMapLongDescription'}, s} end
  2590. local c = function(s) return {{'ShaDaComment'}, s} end
  2591. local exp = {
  2592. {
  2593. hname('Header'), h(' with timestamp '),
  2594. synepoch.year, synhtssep('-'), synepoch.month, synhtssep('-'),
  2595. synepoch.day, synhtssep('T'), synepoch.hour, synhtssep(':'),
  2596. synepoch.minute, synhtssep(':'), synepoch.second, h(':'),
  2597. },
  2598. {
  2599. msh(' % Key Value'),
  2600. },
  2601. {
  2602. ms('Short'), msk('t '),
  2603. {{'ShaDaEntryMapShort', 'ShaDaMsgpackBinaryString',
  2604. 'ShaDaMsgpackStringQuotes'}, '"'},
  2605. {{'ShaDaEntryMapShort', 'ShaDaMsgpackBinaryString'}, 'test'},
  2606. {{'ShaDaEntryMapShort', 'ShaDaMsgpackStringQuotes'}, '"'},
  2607. },
  2608. {
  2609. hname('Jump'), h(' with timestamp '),
  2610. synepoch.year, synhtssep('-'), synepoch.month, synhtssep('-'),
  2611. synepoch.day, synhtssep('T'), synepoch.hour, synhtssep(':'),
  2612. synepoch.minute, synhtssep(':'), synepoch.second, h(':'),
  2613. },
  2614. {
  2615. mlh(' % Key________ Description Value'),
  2616. },
  2617. {
  2618. ms('Long'), mlk('n '), mld('name '),
  2619. {{'ShaDaEntryMapLong', 'ShaDaMsgpackCharacter'}, '\'A\''},
  2620. },
  2621. {
  2622. ms('Long'), mlk('f '), mld('file name '),
  2623. {{'ShaDaEntryMapLong', 'ShaDaMsgpackArray',
  2624. 'ShaDaMsgpackArrayBraces'}, '['},
  2625. {{'ShaDaEntryMapLong', 'ShaDaMsgpackArray', 'ShaDaMsgpackBinaryString',
  2626. 'ShaDaMsgpackStringQuotes'}, '"'},
  2627. {{'ShaDaEntryMapLong', 'ShaDaMsgpackArray', 'ShaDaMsgpackBinaryString'},
  2628. 'foo'},
  2629. {{'ShaDaEntryMapLong', 'ShaDaMsgpackArray', 'ShaDaMsgpackStringQuotes'},
  2630. '"'},
  2631. {{'ShaDaEntryMapLong', 'ShaDaMsgpackArrayBraces'}, ']'},
  2632. },
  2633. {
  2634. ms('Long'), mlk('l '), mld('line number '),
  2635. {{'ShaDaEntryMapLong', 'ShaDaMsgpackInteger'}, '2'},
  2636. },
  2637. {
  2638. ms('Long'), mlk('c '), mld('column '),
  2639. {{'ShaDaEntryMapLong', 'ShaDaMsgpackInteger'}, '-200'},
  2640. },
  2641. {
  2642. hname('Register'), h(' with timestamp '),
  2643. synepoch.year, synhtssep('-'), synepoch.month, synhtssep('-'),
  2644. synepoch.day, synhtssep('T'), synepoch.hour, synhtssep(':'),
  2645. synepoch.minute, synhtssep(':'), synepoch.second, h(':'),
  2646. },
  2647. {
  2648. mlh(' % Key Description Value'),
  2649. },
  2650. {
  2651. ms('Long'), mlk('rc '), mld('contents '),
  2652. {{'ShaDaEntryMapLong', 'ShaDaMsgpackMultilineArray'}, '@'},
  2653. },
  2654. {
  2655. mbas('Long'),
  2656. {{'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackMapBraces'},
  2657. '{'},
  2658. {{'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString',
  2659. 'ShaDaMsgpackStringQuotes'}, '"'},
  2660. {{'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString'},
  2661. 'abcdefghijklmnopqrstuvwxyz'},
  2662. {{'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackStringQuotes'},
  2663. '"'},
  2664. {{'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackColon'}, ':'},
  2665. {{'ShaDaEntryMapLong', 'ShaDaMsgpackMap'}, ' '},
  2666. {{'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackFloat'}, '1.0'},
  2667. {{'ShaDaEntryMapLong', 'ShaDaMsgpackMapBraces'}, '}'},
  2668. },
  2669. {
  2670. ms('Long'), mlk('rt '), mld('type '),
  2671. {{'ShaDaEntryMapLong', 'ShaDaMsgpackShaDaKeyword'}, 'CHARACTERWISE'},
  2672. },
  2673. {
  2674. ms('Long'), mlk('rt '), mld('type '),
  2675. {{'ShaDaEntryMapLong', 'ShaDaMsgpackShaDaKeyword'}, 'LINEWISE'},
  2676. },
  2677. {
  2678. ms('Long'), mlk('rt '), mld('type '),
  2679. {{'ShaDaEntryMapLong', 'ShaDaMsgpackShaDaKeyword'}, 'BLOCKWISE'},
  2680. },
  2681. {
  2682. hname('Replacement string'), h(' with timestamp '),
  2683. synepoch.year, synhtssep('-'), synepoch.month, synhtssep('-'),
  2684. synepoch.day, synhtssep('T'), synepoch.hour, synhtssep(':'),
  2685. synepoch.minute, synhtssep(':'), synepoch.second, h(':'),
  2686. },
  2687. {
  2688. ah(' @ Description__________ Value'),
  2689. },
  2690. {
  2691. as(), ad(':s replacement string '),
  2692. {{'ShaDaEntryArray', 'ShaDaMsgpackShaDaKeyword'}, 'CMD'},
  2693. },
  2694. {
  2695. as(), ad(':s replacement string '),
  2696. {{'ShaDaEntryArray', 'ShaDaMsgpackShaDaKeyword'}, 'SEARCH'},
  2697. },
  2698. {
  2699. as(), ad(':s replacement string '),
  2700. {{'ShaDaEntryArray', 'ShaDaMsgpackShaDaKeyword'}, 'EXPR'},
  2701. },
  2702. {
  2703. as(), ad(':s replacement string '),
  2704. {{'ShaDaEntryArray', 'ShaDaMsgpackShaDaKeyword'}, 'INPUT'},
  2705. },
  2706. {
  2707. {{'ShaDaEntryArrayEntryStart'}, ' - '},
  2708. {{'ShaDaEntryArrayDescription'}, ':s replacement string '},
  2709. {{'ShaDaMsgpackShaDaKeyword'}, 'DEBUG'},
  2710. },
  2711. {
  2712. hname('Buffer list'), h(' with timestamp '),
  2713. synepoch.year, synhtssep('-'), synepoch.month, synhtssep('-'),
  2714. synepoch.day, synhtssep('T'), synepoch.hour, synhtssep(':'),
  2715. synepoch.minute, synhtssep(':'), synepoch.second, h(':'),
  2716. },
  2717. {
  2718. c(' # Expected array of maps'),
  2719. },
  2720. {
  2721. {{'ShaDaEntryRawMsgpack'}, ' = '},
  2722. {{'ShaDaMsgpackArray', 'ShaDaMsgpackArrayBraces'}, '['},
  2723. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackMapBraces'},
  2724. '{'},
  2725. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackString'}, '='},
  2726. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString',
  2727. 'ShaDaMsgpackStringQuotes'}, '"'},
  2728. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString'},
  2729. 'a'},
  2730. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackStringQuotes'},
  2731. '"'},
  2732. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackColon'}, ':'},
  2733. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap'}, ' '},
  2734. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackExt'}, '+('},
  2735. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackExt',
  2736. 'ShaDaMsgpackExtType'}, '10'},
  2737. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackExt'}, ')'},
  2738. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString',
  2739. 'ShaDaMsgpackStringQuotes'}, '"'},
  2740. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString'},
  2741. 'ac'},
  2742. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString',
  2743. 'ShaDaMsgpackBinaryStringEscape'},
  2744. '\\0'},
  2745. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString'},
  2746. 'df'},
  2747. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString',
  2748. 'ShaDaMsgpackBinaryStringEscape'},
  2749. '\\n'},
  2750. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString'},
  2751. 'gi'},
  2752. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString',
  2753. 'ShaDaMsgpackBinaryStringEscape'},
  2754. '\\"'},
  2755. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString'},
  2756. 'tt\\.'},
  2757. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackStringQuotes'},
  2758. '"'},
  2759. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackComma'}, ','},
  2760. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap'}, ' '},
  2761. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackKeyword'},
  2762. 'TRUE'},
  2763. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackColon'}, ':'},
  2764. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap'}, ' '},
  2765. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackKeyword'},
  2766. 'FALSE'},
  2767. {{'ShaDaMsgpackArray', 'ShaDaMsgpackMapBraces'}, '}'},
  2768. {{'ShaDaMsgpackArray', 'ShaDaMsgpackComma'}, ','},
  2769. {{'ShaDaMsgpackArray'}, ' '},
  2770. {{'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackArrayBraces'},
  2771. '['},
  2772. {{'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackKeyword'},
  2773. 'NIL'},
  2774. {{'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackComma'}, ','},
  2775. {{'ShaDaMsgpackArray', 'ShaDaMsgpackArray'}, ' '},
  2776. {{'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackExt'}, '+('},
  2777. {{'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackExt',
  2778. 'ShaDaMsgpackExtType'}, '-10'},
  2779. {{'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackExt'}, ')'},
  2780. {{'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackBinaryString',
  2781. 'ShaDaMsgpackStringQuotes'}, '"'},
  2782. {{'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackStringQuotes'},
  2783. '"'},
  2784. {{'ShaDaMsgpackArray', 'ShaDaMsgpackArrayBraces'}, ']'},
  2785. {{'ShaDaMsgpackArrayBraces'}, ']'},
  2786. },
  2787. {
  2788. hname('Buffer list'), h(' with timestamp '),
  2789. synepoch.year, synhtssep('-'), synepoch.month, synhtssep('-'),
  2790. synepoch.day, synhtssep('T'), synepoch.hour, synhtssep(':'),
  2791. synepoch.minute, synhtssep(':'), synepoch.second, h(':'),
  2792. },
  2793. {
  2794. mlh(' % Key Description Value'),
  2795. },
  2796. {
  2797. },
  2798. {
  2799. mlh(' % Key Description Value'),
  2800. },
  2801. {
  2802. hname('Header'), h(' with timestamp '),
  2803. synepoch.year, synhtssep('-'), synepoch.month, synhtssep('-'),
  2804. synepoch.day, synhtssep('T'), synepoch.hour, synhtssep(':'),
  2805. synepoch.minute, synhtssep(':'), synepoch.second, h(':'),
  2806. },
  2807. {
  2808. mlh(' % Key Description________ Value'),
  2809. },
  2810. {
  2811. {{'ShaDaEntryMapLongEntryStart'}, ' + '},
  2812. {{'ShaDaEntryMapLongKey'}, 'se '},
  2813. {{'ShaDaEntryMapLongDescription'}, 'place cursor at end '},
  2814. {{'ShaDaMsgpackKeyword'}, 'TRUE'},
  2815. },
  2816. }
  2817. eq(exp, act)
  2818. end)
  2819. end)