@@ -20,4 +20,58 @@ def test_calculate_width_with_escape_sequence
20
20
width = @line_editor . send ( :calculate_width , "\1 \e [31m\2 RubyColor\1 \e [34m\2 default string \1 \e [m\2 >" , true )
21
21
assert_equal ( 'RubyColor default string >' . size , width )
22
22
end
23
+
24
+ def test_completion_proc_with_preposing_and_postposing
25
+ buf = [ 'def hoge' , ' puts :aaa' , 'end' ]
26
+
27
+ @line_editor . instance_variable_set ( :@is_multiline , true )
28
+ @line_editor . instance_variable_set ( :@buffer_of_lines , buf )
29
+ @line_editor . instance_variable_set ( :@line , buf [ 1 ] )
30
+ @line_editor . instance_variable_set ( :@byte_pointer , 3 )
31
+ @line_editor . instance_variable_set ( :@cursor , 3 )
32
+ @line_editor . instance_variable_set ( :@cursor_max , 11 )
33
+ @line_editor . instance_variable_set ( :@line_index , 1 )
34
+ @line_editor . instance_variable_set ( :@completion_proc , proc { |target |
35
+ assert_equal ( 'p' , target )
36
+ } )
37
+ @line_editor . __send__ ( :call_completion_proc )
38
+
39
+ @line_editor . instance_variable_set ( :@is_multiline , true )
40
+ @line_editor . instance_variable_set ( :@buffer_of_lines , buf )
41
+ @line_editor . instance_variable_set ( :@line , buf [ 1 ] )
42
+ @line_editor . instance_variable_set ( :@byte_pointer , 6 )
43
+ @line_editor . instance_variable_set ( :@cursor , 6 )
44
+ @line_editor . instance_variable_set ( :@cursor_max , 11 )
45
+ @line_editor . instance_variable_set ( :@line_index , 1 )
46
+ @line_editor . instance_variable_set ( :@completion_proc , proc { |target , pre , post |
47
+ assert_equal ( 'puts' , target )
48
+ assert_equal ( "def hoge\n " , pre )
49
+ assert_equal ( " :aaa\n end" , post )
50
+ } )
51
+ @line_editor . __send__ ( :call_completion_proc )
52
+
53
+ @line_editor . instance_variable_set ( :@line , buf [ 0 ] )
54
+ @line_editor . instance_variable_set ( :@byte_pointer , 6 )
55
+ @line_editor . instance_variable_set ( :@cursor , 6 )
56
+ @line_editor . instance_variable_set ( :@cursor_max , 8 )
57
+ @line_editor . instance_variable_set ( :@line_index , 0 )
58
+ @line_editor . instance_variable_set ( :@completion_proc , proc { |target , pre , post |
59
+ assert_equal ( 'ho' , target )
60
+ assert_equal ( 'def ' , pre )
61
+ assert_equal ( "ge\n puts :aaa\n end" , post )
62
+ } )
63
+ @line_editor . __send__ ( :call_completion_proc )
64
+
65
+ @line_editor . instance_variable_set ( :@line , buf [ 2 ] )
66
+ @line_editor . instance_variable_set ( :@byte_pointer , 1 )
67
+ @line_editor . instance_variable_set ( :@cursor , 1 )
68
+ @line_editor . instance_variable_set ( :@cursor_max , 3 )
69
+ @line_editor . instance_variable_set ( :@line_index , 2 )
70
+ @line_editor . instance_variable_set ( :@completion_proc , proc { |target , pre , post |
71
+ assert_equal ( 'e' , target )
72
+ assert_equal ( "def hoge\n puts :aaa\n " , pre )
73
+ assert_equal ( 'nd' , post )
74
+ } )
75
+ @line_editor . __send__ ( :call_completion_proc )
76
+ end
23
77
end
0 commit comments