@@ -88,6 +88,9 @@ local ALWAYS_PROMPT_KEYMAP = {
88
88
local teardown = function (opts )
89
89
opts = vim .tbl_extend (" keep" , opts or {}, { reset_counter = true })
90
90
91
+ -- Reset filetypes
92
+ debugprint .setup ({ filetypes = require (" debugprint.filetypes" ) })
93
+
91
94
notify_message = nil
92
95
pcall (vim .keymap .del , " n" , " g?p" )
93
96
pcall (vim .keymap .del , " n" , " g?P" )
@@ -3161,3 +3164,198 @@ describe("dynamic filetype configuration", function()
3161
3164
})
3162
3165
end )
3163
3166
end )
3167
+
3168
+ describe (" double statement insertion" , function ()
3169
+ after_each (teardown )
3170
+
3171
+ it (" plain" , function ()
3172
+ assert .equals (notify_message , nil )
3173
+
3174
+ local filename = init_file ({
3175
+ " foo" ,
3176
+ " bar" ,
3177
+ }, " lua" , 1 , 0 )
3178
+
3179
+ feedkeys (" g?sp" )
3180
+
3181
+ check_lines ({
3182
+ " print('DEBUGPRINT[1]: " .. filename .. " :1 (before foo)')" ,
3183
+ " foo" ,
3184
+ " print('DEBUGPRINT[2]: " .. filename .. " :2 (after foo)')" ,
3185
+ " bar" ,
3186
+ })
3187
+
3188
+ assert .equals (notify_message , nil )
3189
+ end )
3190
+
3191
+ it (" plain - undo is atomic" , function ()
3192
+ assert .equals (notify_message , nil )
3193
+
3194
+ local filename = init_file ({
3195
+ " foo" ,
3196
+ " bar" ,
3197
+ }, " lua" , 1 , 0 )
3198
+
3199
+ feedkeys (" g?sp" )
3200
+
3201
+ check_lines ({
3202
+ " print('DEBUGPRINT[1]: " .. filename .. " :1 (before foo)')" ,
3203
+ " foo" ,
3204
+ " print('DEBUGPRINT[2]: " .. filename .. " :2 (after foo)')" ,
3205
+ " bar" ,
3206
+ })
3207
+
3208
+ feedkeys (" u" )
3209
+
3210
+ check_lines ({
3211
+ " foo" ,
3212
+ " bar" ,
3213
+ })
3214
+
3215
+ assert .equals (notify_message , nil )
3216
+ end )
3217
+
3218
+ it (" plain - repeat" , function ()
3219
+ assert .equals (notify_message , nil )
3220
+
3221
+ local filename = init_file ({
3222
+ " foo" ,
3223
+ " bar" ,
3224
+ }, " lua" , 1 , 0 )
3225
+
3226
+ feedkeys (" g?sp" )
3227
+ feedkeys (" jj" )
3228
+ feedkeys (" g?sp" )
3229
+
3230
+ check_lines ({
3231
+ " print('DEBUGPRINT[1]: " .. filename .. " :1 (before foo)')" ,
3232
+ " foo" ,
3233
+ " print('DEBUGPRINT[2]: " .. filename .. " :2 (after foo)')" ,
3234
+ " print('DEBUGPRINT[3]: " .. filename .. " :4 (before bar)')" ,
3235
+ " bar" ,
3236
+ " print('DEBUGPRINT[4]: " .. filename .. " :5 (after bar)')" ,
3237
+ })
3238
+
3239
+ assert .equals (notify_message , nil )
3240
+ end )
3241
+
3242
+ it (" plain - complex indentation" , function ()
3243
+ assert .equals (notify_message , nil )
3244
+
3245
+ local filename = init_file ({
3246
+ " function()" ,
3247
+ " foo = 1" ,
3248
+ " end" ,
3249
+ }, " lua" , 1 , 0 )
3250
+
3251
+ feedkeys (" g?sp" )
3252
+
3253
+ check_lines ({
3254
+ " print('DEBUGPRINT[1]: " .. filename .. " :1 (before function())')" ,
3255
+ " function()" ,
3256
+ " print('DEBUGPRINT[2]: "
3257
+ .. filename
3258
+ .. " :2 (after function())')" ,
3259
+ " foo = 1" ,
3260
+ " end" ,
3261
+ })
3262
+
3263
+ assert .equals (notify_message , nil )
3264
+ end )
3265
+
3266
+ it (" variable" , function ()
3267
+ local filename = init_file ({
3268
+ " local foo = 1" ,
3269
+ " local bar = 2" ,
3270
+ }, " lua" , 1 , 7 )
3271
+
3272
+ feedkeys (" g?sv" )
3273
+
3274
+ check_lines ({
3275
+ " print('DEBUGPRINT[1]: "
3276
+ .. filename
3277
+ .. " :1: foo=' .. vim.inspect(foo))" ,
3278
+ " local foo = 1" ,
3279
+ " print('DEBUGPRINT[2]: "
3280
+ .. filename
3281
+ .. " :2: foo=' .. vim.inspect(foo))" ,
3282
+ " local bar = 2" ,
3283
+ })
3284
+
3285
+ assert .equals (notify_message , nil )
3286
+ end )
3287
+
3288
+ it (" variable (prompt)" , function ()
3289
+ local filename = init_file ({
3290
+ " -- local foo = 1" ,
3291
+ " local bar = 2" ,
3292
+ }, " lua" , 1 , 10 )
3293
+
3294
+ feedkeys (" g?sv<CR>" )
3295
+
3296
+ check_lines ({
3297
+ " print('DEBUGPRINT[1]: "
3298
+ .. filename
3299
+ .. " :1: foo=' .. vim.inspect(foo))" ,
3300
+ " -- local foo = 1" ,
3301
+ " print('DEBUGPRINT[2]: "
3302
+ .. filename
3303
+ .. " :2: foo=' .. vim.inspect(foo))" ,
3304
+ " local bar = 2" ,
3305
+ })
3306
+
3307
+ assert .equals (notify_message , nil )
3308
+ end )
3309
+
3310
+ it (" variable (always prompt)" , function ()
3311
+ debugprint .setup ({
3312
+ keymaps = {
3313
+ normal = {
3314
+ surround_variable_alwaysprompt = " g?sz" ,
3315
+ },
3316
+ },
3317
+ })
3318
+
3319
+ local filename = init_file ({
3320
+ " local foo = 1" ,
3321
+ " local bar = 2" ,
3322
+ }, " lua" , 1 , 7 )
3323
+
3324
+ feedkeys (" g?sz<CR>" )
3325
+
3326
+ check_lines ({
3327
+ " print('DEBUGPRINT[1]: "
3328
+ .. filename
3329
+ .. " :1: foo=' .. vim.inspect(foo))" ,
3330
+ " local foo = 1" ,
3331
+ " print('DEBUGPRINT[2]: "
3332
+ .. filename
3333
+ .. " :2: foo=' .. vim.inspect(foo))" ,
3334
+ " local bar = 2" ,
3335
+ })
3336
+
3337
+ assert .equals (notify_message , nil )
3338
+ end )
3339
+
3340
+ it (" variable (textobj)" , function ()
3341
+ local filename = init_file ({
3342
+ " local foo = 1" ,
3343
+ " local bar = 2" ,
3344
+ }, " lua" , 1 , 7 )
3345
+
3346
+ feedkeys (" g?soiw" )
3347
+
3348
+ check_lines ({
3349
+ " print('DEBUGPRINT[1]: "
3350
+ .. filename
3351
+ .. " :1: foo=' .. vim.inspect(foo))" ,
3352
+ " local foo = 1" ,
3353
+ " print('DEBUGPRINT[2]: "
3354
+ .. filename
3355
+ .. " :2: foo=' .. vim.inspect(foo))" ,
3356
+ " local bar = 2" ,
3357
+ })
3358
+
3359
+ assert .equals (notify_message , nil )
3360
+ end )
3361
+ end )
0 commit comments