File tree 2 files changed +17
-5
lines changed
2 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -145,19 +145,32 @@ mod tests {
145
145
146
146
#[ test]
147
147
fn respv2_map_length_should_work ( ) {
148
- let buf = b"%2 \r \n +OK\r \n -ERR\r \n " ;
148
+ let buf = b"%1 \r \n +OK\r \n -ERR\r \n " ;
149
149
let len = RespFrame :: expect_length ( buf) . unwrap ( ) ;
150
150
assert_eq ! ( len, buf. len( ) ) ;
151
151
}
152
152
153
153
#[ test]
154
154
fn respv2_map_should_work ( ) {
155
- let mut buf = BytesMut :: from ( "%2 \r \n +OK\r \n -ERR\r \n " ) ;
155
+ let mut buf = BytesMut :: from ( "%1 \r \n +OK\r \n -ERR\r \n " ) ;
156
156
let frame = RespFrame :: decode ( & mut buf) . unwrap ( ) ;
157
157
let items: BTreeMap < String , RespFrame > =
158
158
[ ( "OK" . to_string ( ) , RespFrame :: Error ( "ERR" . into ( ) ) ) ]
159
159
. into_iter ( )
160
160
. collect ( ) ;
161
161
assert_eq ! ( frame, RespFrame :: Map ( items. into( ) ) ) ;
162
162
}
163
+
164
+ #[ test]
165
+ fn respv2_map_with_real_data_should_work ( ) {
166
+ let mut buf = BytesMut :: from ( "%2\r \n +hello\r \n $5\r \n world\r \n +foo\r \n $3\r \n bar\r \n " ) ;
167
+ let frame = RespFrame :: decode ( & mut buf) . unwrap ( ) ;
168
+ let items: BTreeMap < String , RespFrame > = [
169
+ ( "hello" . to_string ( ) , RespFrame :: BulkString ( "world" . into ( ) ) ) ,
170
+ ( "foo" . to_string ( ) , RespFrame :: BulkString ( "bar" . into ( ) ) ) ,
171
+ ]
172
+ . into_iter ( )
173
+ . collect ( ) ;
174
+ assert_eq ! ( frame, RespFrame :: Map ( items. into( ) ) ) ;
175
+ }
163
176
}
Original file line number Diff line number Diff line change @@ -167,13 +167,13 @@ fn double(input: &mut &[u8]) -> PResult<f64> {
167
167
terminated ( float, CRLF ) . parse_next ( input)
168
168
}
169
169
170
- // - map: "%2\r\n+foo\r\n-bar\r\n"
170
+ // my understanding of map len is incorrect: https://redis.io/docs/latest/develop/reference/protocol-spec/#maps
171
+ // - map: "%1\r\n+foo\r\n-bar\r\n"
171
172
fn map ( input : & mut & [ u8 ] ) -> PResult < RespMap > {
172
173
let len: i64 = integer. parse_next ( input) ?;
173
174
if len <= 0 {
174
175
return Err ( err_cut ( "map length must be non-negative" ) ) ;
175
176
}
176
- let len = len as usize / 2 ;
177
177
let mut map = BTreeMap :: new ( ) ;
178
178
for _ in 0 ..len {
179
179
let key = preceded ( '+' , parse_string) . parse_next ( input) ?;
@@ -188,7 +188,6 @@ fn map_len(input: &mut &[u8]) -> PResult<()> {
188
188
if len <= 0 {
189
189
return Err ( err_cut ( "map length must be non-negative" ) ) ;
190
190
}
191
- let len = len as usize / 2 ;
192
191
for _ in 0 ..len {
193
192
terminated ( take_until ( 0 .., CRLF ) , CRLF )
194
193
. value ( ( ) )
You can’t perform that action at this time.
0 commit comments