@@ -275,6 +275,78 @@ def test_unmatched_endif
275
275
assert_equal "INPUTRC:1: unmatched endif" , e . message
276
276
end
277
277
278
+ def test_if_with_mode
279
+ @config . read_lines ( <<~LINES . lines )
280
+ $if mode=emacs
281
+ "\C -e": history-search-backward # comment
282
+ $else
283
+ "\C -f": history-search-forward
284
+ $endif
285
+ LINES
286
+
287
+ assert_equal ( { [ 5 ] => :history_search_backward } , @config . instance_variable_get ( :@additional_key_bindings ) [ :emacs ] )
288
+ assert_equal ( { } , @config . instance_variable_get ( :@additional_key_bindings ) [ :vi_insert ] )
289
+ assert_equal ( { } , @config . instance_variable_get ( :@additional_key_bindings ) [ :vi_command ] )
290
+ end
291
+
292
+ def test_else
293
+ @config . read_lines ( <<~LINES . lines )
294
+ $if mode=vi
295
+ "\C -e": history-search-backward # comment
296
+ $else
297
+ "\C -f": history-search-forward
298
+ $endif
299
+ LINES
300
+
301
+ assert_equal ( { [ 6 ] => :history_search_forward } , @config . instance_variable_get ( :@additional_key_bindings ) [ :emacs ] )
302
+ assert_equal ( { } , @config . instance_variable_get ( :@additional_key_bindings ) [ :vi_insert ] )
303
+ assert_equal ( { } , @config . instance_variable_get ( :@additional_key_bindings ) [ :vi_command ] )
304
+ end
305
+
306
+ def test_if_with_invalid_mode
307
+ @config . read_lines ( <<~LINES . lines )
308
+ $if mode=vim
309
+ "\C -e": history-search-backward
310
+ $else
311
+ "\C -f": history-search-forward # comment
312
+ $endif
313
+ LINES
314
+
315
+ assert_equal ( { [ 6 ] => :history_search_forward } , @config . instance_variable_get ( :@additional_key_bindings ) [ :emacs ] )
316
+ assert_equal ( { } , @config . instance_variable_get ( :@additional_key_bindings ) [ :vi_insert ] )
317
+ assert_equal ( { } , @config . instance_variable_get ( :@additional_key_bindings ) [ :vi_command ] )
318
+ end
319
+
320
+ def test_mode_label_differs_from_keymap_label
321
+ @config . read_lines ( <<~LINES . lines )
322
+ # Sets mode_label and keymap_label to vi
323
+ set editing-mode vi
324
+ # Change keymap_label to emacs. mode_label is still vi.
325
+ set keymap emacs
326
+ # condition=true because current mode_label is vi
327
+ $if mode=vi
328
+ # sets keybinding to current keymap_label=emacs
329
+ "\C -e": history-search-backward
330
+ $endif
331
+ LINES
332
+ assert_equal ( { [ 5 ] => :history_search_backward } , @config . instance_variable_get ( :@additional_key_bindings ) [ :emacs ] )
333
+ assert_equal ( { } , @config . instance_variable_get ( :@additional_key_bindings ) [ :vi_insert ] )
334
+ assert_equal ( { } , @config . instance_variable_get ( :@additional_key_bindings ) [ :vi_command ] )
335
+ end
336
+
337
+ def test_if_without_else_condition
338
+ @config . read_lines ( <<~LINES . lines )
339
+ set editing-mode vi
340
+ $if mode=vi
341
+ "\C -e": history-search-backward
342
+ $endif
343
+ LINES
344
+
345
+ assert_equal ( { } , @config . instance_variable_get ( :@additional_key_bindings ) [ :emacs ] )
346
+ assert_equal ( { [ 5 ] => :history_search_backward } , @config . instance_variable_get ( :@additional_key_bindings ) [ :vi_insert ] )
347
+ assert_equal ( { } , @config . instance_variable_get ( :@additional_key_bindings ) [ :vi_command ] )
348
+ end
349
+
278
350
def test_default_key_bindings
279
351
@config . add_default_key_binding ( 'abcd' . bytes , 'EFGH' . bytes )
280
352
@config . read_lines ( <<~'LINES' . lines )
0 commit comments