@@ -13,6 +13,10 @@ def to_keys
13
13
end
14
14
}
15
15
16
+ def encoding
17
+ Reline . core . encoding
18
+ end
19
+
16
20
def test_match_status
17
21
config = Reline ::Config . new
18
22
{
@@ -23,7 +27,7 @@ def test_match_status
23
27
} . each_pair do |key , func |
24
28
config . add_default_key_binding ( key . bytes , func . bytes )
25
29
end
26
- stroke = Reline ::KeyStroke . new ( config )
30
+ stroke = Reline ::KeyStroke . new ( config , encoding )
27
31
assert_equal ( :matching_matched , stroke . match_status ( "a" . bytes ) )
28
32
assert_equal ( :matching_matched , stroke . match_status ( "ab" . bytes ) )
29
33
assert_equal ( :matched , stroke . match_status ( "abc" . bytes ) )
@@ -37,7 +41,7 @@ def test_match_status
37
41
def test_match_unknown
38
42
config = Reline ::Config . new
39
43
config . add_default_key_binding ( "\e [9abc" . bytes , 'x' )
40
- stroke = Reline ::KeyStroke . new ( config )
44
+ stroke = Reline ::KeyStroke . new ( config , encoding )
41
45
sequences = [
42
46
"\e [9abc" ,
43
47
"\e [9d" ,
@@ -66,7 +70,7 @@ def test_expand
66
70
} . each_pair do |key , func |
67
71
config . add_default_key_binding ( key . bytes , func . bytes )
68
72
end
69
- stroke = Reline ::KeyStroke . new ( config )
73
+ stroke = Reline ::KeyStroke . new ( config , encoding )
70
74
assert_equal ( [ '123' . bytes . map { |c | Reline ::Key . new ( c , c , false ) } , 'de' . bytes ] , stroke . expand ( 'abcde' . bytes ) )
71
75
assert_equal ( [ '456' . bytes . map { |c | Reline ::Key . new ( c , c , false ) } , 'de' . bytes ] , stroke . expand ( 'abde' . bytes ) )
72
76
# CSI sequence
@@ -83,7 +87,7 @@ def test_oneshot_key_bindings
83
87
} . each_pair do |key , func |
84
88
config . add_default_key_binding ( key . bytes , func . bytes )
85
89
end
86
- stroke = Reline ::KeyStroke . new ( config )
90
+ stroke = Reline ::KeyStroke . new ( config , encoding )
87
91
assert_equal ( :unmatched , stroke . match_status ( 'zzz' . bytes ) )
88
92
assert_equal ( :matched , stroke . match_status ( 'abc' . bytes ) )
89
93
end
@@ -96,10 +100,27 @@ def test_with_reline_key
96
100
} . each_pair do |key , func |
97
101
config . add_oneshot_key_binding ( key , func . bytes )
98
102
end
99
- stroke = Reline ::KeyStroke . new ( config )
103
+ stroke = Reline ::KeyStroke . new ( config , encoding )
100
104
assert_equal ( :unmatched , stroke . match_status ( 'da' . bytes ) )
101
105
assert_equal ( :matched , stroke . match_status ( "\e da" . bytes ) )
102
106
assert_equal ( :unmatched , stroke . match_status ( [ 32 , 195 , 164 ] ) )
103
107
assert_equal ( :matched , stroke . match_status ( [ 195 , 164 ] ) )
104
108
end
109
+
110
+ def test_multibyte_matching
111
+ config = Reline ::Config . new
112
+ stroke = Reline ::KeyStroke . new ( config , encoding )
113
+ char = 'あ' . encode ( encoding )
114
+ key = Reline ::Key . new ( char . ord , char . ord , false )
115
+ bytes = char . bytes
116
+ assert_equal ( :matched , stroke . match_status ( bytes ) )
117
+ assert_equal ( [ [ key ] , [ ] ] , stroke . expand ( bytes ) )
118
+ assert_equal ( :unmatched , stroke . match_status ( bytes * 2 ) )
119
+ assert_equal ( [ [ key ] , bytes ] , stroke . expand ( bytes * 2 ) )
120
+ ( 1 ...bytes . size ) . each do |i |
121
+ partial_bytes = bytes . take ( i )
122
+ assert_equal ( :matching_matched , stroke . match_status ( partial_bytes ) )
123
+ assert_equal ( [ [ ] , [ ] ] , stroke . expand ( partial_bytes ) )
124
+ end
125
+ end
105
126
end
0 commit comments