030_fileformats_spec.lua 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. -- Test for a lot of variations of the 'fileformats' option
  2. local t = require('test.testutil')
  3. local n = require('test.functional.testnvim')()
  4. local feed, clear, command = n.feed, n.clear, n.command
  5. local eq, write_file = t.eq, t.write_file
  6. local poke_eventloop = n.poke_eventloop
  7. describe('fileformats option', function()
  8. setup(function()
  9. clear()
  10. local dos = 'dos\r\ndos\r\n'
  11. local mac = 'mac\rmac\r'
  12. local unix = 'unix\nunix\n'
  13. local eol = 'noeol'
  14. write_file('XXDos', dos)
  15. write_file('XXMac', mac)
  16. write_file('XXUnix', unix)
  17. write_file('XXEol', eol)
  18. write_file('XXDosMac', dos..mac)
  19. write_file('XXMacEol', mac..eol)
  20. write_file('XXUxDs', unix..dos)
  21. write_file('XXUxDsMc', unix..dos..mac)
  22. write_file('XXUxMac', unix..mac)
  23. end)
  24. teardown(function()
  25. os.remove('test.out')
  26. os.remove('XXDos')
  27. os.remove('XXMac')
  28. os.remove('XXUnix')
  29. os.remove('XXEol')
  30. os.remove('XXDosMac')
  31. os.remove('XXMacEol')
  32. os.remove('XXUxDs')
  33. os.remove('XXUxDsMc')
  34. os.remove('XXUxMac')
  35. for i = 0, 9 do
  36. for j = 1, 4 do
  37. os.remove('XXtt'..i..j)
  38. end
  39. end
  40. end)
  41. it('is working', function()
  42. -- Try reading and writing with 'fileformats' empty.
  43. command('set fileformats=')
  44. command('set fileformat=unix')
  45. command('e! XXUnix')
  46. command('w! test.out')
  47. command('e! XXDos')
  48. command('w! XXtt01')
  49. command('e! XXMac')
  50. command('w! XXtt02')
  51. command('bwipe XXUnix XXDos XXMac')
  52. command('set fileformat=dos')
  53. command('e! XXUnix')
  54. command('w! XXtt11')
  55. command('e! XXDos')
  56. command('w! XXtt12')
  57. command('e! XXMac')
  58. command('w! XXtt13')
  59. command('bwipe XXUnix XXDos XXMac')
  60. command('set fileformat=mac')
  61. command('e! XXUnix')
  62. command('w! XXtt21')
  63. command('e! XXDos')
  64. command('w! XXtt22')
  65. command('e! XXMac')
  66. command('w! XXtt23')
  67. command('bwipe XXUnix XXDos XXMac')
  68. -- Try reading and writing with 'fileformats' set to one format.
  69. command('set fileformats=unix')
  70. command('e! XXUxDsMc')
  71. command('w! XXtt31')
  72. command('bwipe XXUxDsMc')
  73. command('set fileformats=dos')
  74. command('e! XXUxDsMc')
  75. command('w! XXtt32')
  76. command('bwipe XXUxDsMc')
  77. command('set fileformats=mac')
  78. command('e! XXUxDsMc')
  79. command('w! XXtt33')
  80. command('bwipe XXUxDsMc')
  81. -- Try reading and writing with 'fileformats' set to two formats.
  82. command('set fileformats=unix,dos')
  83. command('e! XXUxDsMc')
  84. command('w! XXtt41')
  85. command('bwipe XXUxDsMc')
  86. command('e! XXUxMac')
  87. command('w! XXtt42')
  88. command('bwipe XXUxMac')
  89. command('e! XXDosMac')
  90. command('w! XXtt43')
  91. command('bwipe XXDosMac')
  92. command('set fileformats=unix,mac')
  93. command('e! XXUxDs')
  94. command('w! XXtt51')
  95. command('bwipe XXUxDs')
  96. command('e! XXUxDsMc')
  97. command('w! XXtt52')
  98. command('bwipe XXUxDsMc')
  99. command('e! XXDosMac')
  100. command('w! XXtt53')
  101. command('bwipe XXDosMac')
  102. command('e! XXEol')
  103. feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>')
  104. poke_eventloop()
  105. command('w! XXtt54')
  106. command('bwipeout! XXEol')
  107. command('set fileformats=dos,mac')
  108. command('e! XXUxDs')
  109. command('w! XXtt61')
  110. command('bwipe XXUxDs')
  111. command('e! XXUxMac')
  112. feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>')
  113. poke_eventloop()
  114. command('w! XXtt62')
  115. command('bwipeout! XXUxMac')
  116. command('e! XXUxDsMc')
  117. command('w! XXtt63')
  118. command('bwipe XXUxDsMc')
  119. command('e! XXMacEol')
  120. feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>')
  121. poke_eventloop()
  122. command('w! XXtt64')
  123. command('bwipeout! XXMacEol')
  124. -- Try reading and writing with 'fileformats' set to three formats.
  125. command('set fileformats=unix,dos,mac')
  126. command('e! XXUxDsMc')
  127. command('w! XXtt71')
  128. command('bwipe XXUxDsMc')
  129. command('e! XXEol')
  130. feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>')
  131. poke_eventloop()
  132. command('w! XXtt72')
  133. command('bwipeout! XXEol')
  134. command('set fileformats=mac,dos,unix')
  135. command('e! XXUxDsMc')
  136. command('w! XXtt81')
  137. command('bwipe XXUxDsMc')
  138. command('e! XXEol')
  139. feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>')
  140. poke_eventloop()
  141. command('w! XXtt82')
  142. command('bwipeout! XXEol')
  143. -- Try with 'binary' set.
  144. command('set fileformats=mac,unix,dos')
  145. command('set binary')
  146. command('e! XXUxDsMc')
  147. command('w! XXtt91')
  148. command('bwipe XXUxDsMc')
  149. command('set fileformats=mac')
  150. command('e! XXUxDsMc')
  151. command('w! XXtt92')
  152. command('bwipe XXUxDsMc')
  153. command('set fileformats=dos')
  154. command('e! XXUxDsMc')
  155. command('w! XXtt93')
  156. -- Append "END" to each file so that we can see what the last written
  157. -- char was.
  158. command('set fileformat=unix nobin')
  159. feed('ggdGaEND<esc>')
  160. poke_eventloop()
  161. command('w >>XXtt01')
  162. command('w >>XXtt02')
  163. command('w >>XXtt11')
  164. command('w >>XXtt12')
  165. command('w >>XXtt13')
  166. command('w >>XXtt21')
  167. command('w >>XXtt22')
  168. command('w >>XXtt23')
  169. command('w >>XXtt31')
  170. command('w >>XXtt32')
  171. command('w >>XXtt33')
  172. command('w >>XXtt41')
  173. command('w >>XXtt42')
  174. command('w >>XXtt43')
  175. command('w >>XXtt51')
  176. command('w >>XXtt52')
  177. command('w >>XXtt53')
  178. command('w >>XXtt54')
  179. command('w >>XXtt61')
  180. command('w >>XXtt62')
  181. command('w >>XXtt63')
  182. command('w >>XXtt64')
  183. command('w >>XXtt71')
  184. command('w >>XXtt72')
  185. command('w >>XXtt81')
  186. command('w >>XXtt82')
  187. command('w >>XXtt91')
  188. command('w >>XXtt92')
  189. command('w >>XXtt93')
  190. -- Concatenate the results.
  191. -- Make fileformat of test.out the native fileformat.
  192. -- Add a newline at the end.
  193. command('set binary')
  194. command('e! test.out')
  195. command('$r XXtt01')
  196. command('$r XXtt02')
  197. feed('Go1<esc>')
  198. poke_eventloop()
  199. command('$r XXtt11')
  200. command('$r XXtt12')
  201. command('$r XXtt13')
  202. feed('Go2<esc>')
  203. poke_eventloop()
  204. command('$r XXtt21')
  205. command('$r XXtt22')
  206. command('$r XXtt23')
  207. feed('Go3<esc>')
  208. poke_eventloop()
  209. command('$r XXtt31')
  210. command('$r XXtt32')
  211. command('$r XXtt33')
  212. feed('Go4<esc>')
  213. poke_eventloop()
  214. command('$r XXtt41')
  215. command('$r XXtt42')
  216. command('$r XXtt43')
  217. feed('Go5<esc>')
  218. poke_eventloop()
  219. command('$r XXtt51')
  220. command('$r XXtt52')
  221. command('$r XXtt53')
  222. command('$r XXtt54')
  223. feed('Go6<esc>')
  224. poke_eventloop()
  225. command('$r XXtt61')
  226. command('$r XXtt62')
  227. command('$r XXtt63')
  228. command('$r XXtt64')
  229. feed('Go7<esc>')
  230. poke_eventloop()
  231. command('$r XXtt71')
  232. command('$r XXtt72')
  233. feed('Go8<esc>')
  234. poke_eventloop()
  235. command('$r XXtt81')
  236. command('$r XXtt82')
  237. feed('Go9<esc>')
  238. poke_eventloop()
  239. command('$r XXtt91')
  240. command('$r XXtt92')
  241. command('$r XXtt93')
  242. feed('Go10<esc>')
  243. poke_eventloop()
  244. command('$r XXUnix')
  245. command('set nobinary ff&')
  246. -- Assert buffer contents. This has to be done manually as
  247. -- n.expect() calls t.dedent() which messes up the white space
  248. -- and carriage returns.
  249. eq(
  250. 'unix\n'..
  251. 'unix\n'..
  252. 'dos\r\n'..
  253. 'dos\r\n'..
  254. 'END\n'..
  255. 'mac\rmac\r\n'..
  256. 'END\n'..
  257. '1\n'..
  258. 'unix\r\n'..
  259. 'unix\r\n'..
  260. 'END\n'..
  261. 'dos\r\n'..
  262. 'dos\r\n'..
  263. 'END\n'..
  264. 'mac\rmac\r\r\n'..
  265. 'END\n'..
  266. '2\n'..
  267. 'unix\n'..
  268. 'unix\n'..
  269. '\rEND\n'..
  270. 'dos\r\n'..
  271. 'dos\r\n'..
  272. '\rEND\n'..
  273. 'mac\rmac\rEND\n'..
  274. '3\n'..
  275. 'unix\n'..
  276. 'unix\n'..
  277. 'dos\r\n'..
  278. 'dos\r\n'..
  279. 'mac\rmac\r\n'..
  280. 'END\n'..
  281. 'unix\r\n'..
  282. 'unix\r\n'..
  283. 'dos\r\n'..
  284. 'dos\r\n'..
  285. 'mac\rmac\r\r\n'..
  286. 'END\n'..
  287. 'unix\n'..
  288. 'unix\n'..
  289. 'dos\r\n'..
  290. 'dos\r\n'..
  291. 'mac\rmac\rEND\n'..
  292. '4\n'..
  293. 'unix\n'..
  294. 'unix\n'..
  295. 'dos\r\n'..
  296. 'dos\r\n'..
  297. 'mac\rmac\r\n'..
  298. 'END\n'..
  299. 'unix\n'..
  300. 'unix\n'..
  301. 'mac\rmac\r\n'..
  302. 'END\n'..
  303. 'dos\r\n'..
  304. 'dos\r\n'..
  305. 'mac\rmac\r\r\n'..
  306. 'END\n'..
  307. '5\n'..
  308. 'unix\n'..
  309. 'unix\n'..
  310. 'dos\r\n'..
  311. 'dos\r\n'..
  312. 'END\n'..
  313. 'unix\n'..
  314. 'unix\n'..
  315. 'dos\r\n'..
  316. 'dos\r\n'..
  317. 'mac\rmac\r\n'..
  318. 'END\n'..
  319. 'dos\r\n'..
  320. 'dos\r\n'..
  321. 'mac\rmac\rEND\n'..
  322. 'unix,mac:unix\n'..
  323. 'noeol\n'..
  324. 'END\n'..
  325. '6\n'..
  326. 'unix\r\n'..
  327. 'unix\r\n'..
  328. 'dos\r\n'..
  329. 'dos\r\n'..
  330. 'END\n'..
  331. 'dos,mac:dos\r\n'..
  332. 'unix\r\n'..
  333. 'unix\r\n'..
  334. 'mac\rmac\r\r\n'..
  335. 'END\n'..
  336. 'unix\r\n'..
  337. 'unix\r\n'..
  338. 'dos\r\n'..
  339. 'dos\r\n'..
  340. 'mac\rmac\r\r\n'..
  341. 'END\n'..
  342. 'dos,mac:mac\rmac\rmac\rnoeol\rEND\n'..
  343. '7\n'..
  344. 'unix\n'..
  345. 'unix\n'..
  346. 'dos\r\n'..
  347. 'dos\r\n'..
  348. 'mac\rmac\r\n'..
  349. 'END\n'..
  350. 'unix,dos,mac:unix\n'..
  351. 'noeol\n'..
  352. 'END\n'..
  353. '8\n'..
  354. 'unix\n'..
  355. 'unix\n'..
  356. 'dos\r\n'..
  357. 'dos\r\n'..
  358. 'mac\rmac\r\n'..
  359. 'END\n'..
  360. 'mac,dos,unix:mac\rnoeol\rEND\n'..
  361. '9\n'..
  362. 'unix\n'..
  363. 'unix\n'..
  364. 'dos\r\n'..
  365. 'dos\r\n'..
  366. 'mac\rmac\rEND\n'..
  367. 'unix\n'..
  368. 'unix\n'..
  369. 'dos\r\n'..
  370. 'dos\r\n'..
  371. 'mac\rmac\rEND\n'..
  372. 'unix\n'..
  373. 'unix\n'..
  374. 'dos\r\n'..
  375. 'dos\r\n'..
  376. 'mac\rmac\rEND\n'..
  377. '10\n'..
  378. 'unix\n'..
  379. 'unix',
  380. n.curbuf_contents())
  381. end)
  382. end)