@@ -1260,4 +1260,79 @@ func Test_insert_small_delete_linewise()
12601260 bwipe!
12611261endfunc
12621262
1263+ func PutList ()
1264+ return [" c" , [" list" ]]
1265+ endfunc
1266+
1267+ func PutTuple ()
1268+ return (" b40" , [" tuple" , " of" , " strings" ])
1269+ endfunc
1270+
1271+ func YankReg (type , lines )
1272+ let g: vim_test_stuff = {
1273+ \ " type" : a: type ,
1274+ \ " lines" : a: lines
1275+ \ }
1276+ endfunc
1277+
1278+ func Test_custom_register_put ()
1279+ CheckFeature eval
1280+
1281+ set regreqfunc= PutList
1282+ new
1283+ normal ! " &p
1284+ call assert_equal ([' list' ], getline (1 , ' $' ))
1285+ call assert_equal (" list" , getreg (' &' ))
1286+ call assert_equal (' v' , getregtype (' &' ))
1287+ bw !
1288+
1289+ set regreqfunc= PutTuple
1290+ new
1291+ normal ! " &p
1292+ call assert_equal ([' tuple' , ' of' , ' strings' ], getline (1 , 4 ))
1293+ call assert_equal (" tuple\n of\n strings" , getreg (' &' ))
1294+ call assert_equal (' 40' , getregtype (' &' ))
1295+ bw !
1296+
1297+ set regreqfunc&
1298+ endfunc
1299+
1300+ func Test_custom_register_yank ()
1301+ CheckFeature eval
1302+
1303+ set regsetfunc= YankReg
1304+ new
1305+ call append (0 , [" hello" , " world!" ])
1306+ call execute (" 1,2yank &" )
1307+ call assert_equal (" hello\n world!\n " , getreg (' &' ))
1308+ call assert_equal (" V" , g: vim_test_stuff .type )
1309+ call assert_equal ([" hello" , " world!" ], g: vim_test_stuff .lines )
1310+ bw !
1311+
1312+ set regsetfunc&
1313+ endfunc
1314+
1315+ func Test_custom_register_combined ()
1316+ CheckFeature eval
1317+
1318+ " Test if it acts like a normal register without the callbacks
1319+ set regreqfunc= regsetfunc=
1320+ new
1321+ call append (0 , [" hello" , " world!" ])
1322+ call execute (" 1,2yank &" )
1323+ call assert_equal (" hello\n world!\n " , getreg (' &' ))
1324+
1325+ set regreqfunc= PutTuple
1326+ call assert_equal (" tuple\n of\n strings" , getreg (' &' ))
1327+ call execute (" 1,2yank &" )
1328+ call assert_equal (" tuple\n of\n strings" , getreg (' &' ))
1329+
1330+ set regreqfunc= regsetfunc= YankReg
1331+ call execute (" 1yank &" )
1332+ call assert_equal (" hello\n " , getreg (' &' ))
1333+ bw !
1334+
1335+ set regreqfunc& regsetfunc&
1336+ endfunc
1337+
12631338" vim: shiftwidth = 2 sts = 2 expandtab
0 commit comments