@@ -20,3 +20,86 @@ fn test_is_single_arg() {
20
20
assert_eq ! ( twobytesslice. is_single_arg( ) , false ) ;
21
21
assert_eq ! ( twobytesvec. is_single_arg( ) , false ) ;
22
22
}
23
+
24
+ #[ test]
25
+ fn test_info_dict ( ) {
26
+ use redis:: { InfoDict , FromRedisValue , Value } ;
27
+
28
+ let d : InfoDict = FromRedisValue :: from_redis_value ( & Value :: Status (
29
+ "# this is a comment\n key1:foo\n key2:42\n " . into ( )
30
+ ) ) . unwrap ( ) ;
31
+
32
+ assert_eq ! ( d. get( "key1" ) , Some ( "foo" . to_string( ) ) ) ;
33
+ assert_eq ! ( d. get( "key2" ) , Some ( 42i64 ) ) ;
34
+ assert_eq ! ( d. get:: <String >( "key3" ) , None ) ;
35
+ }
36
+
37
+ #[ test]
38
+ fn test_i32 ( ) {
39
+ use redis:: { FromRedisValue , Value , ErrorKind } ;
40
+
41
+ let i = FromRedisValue :: from_redis_value ( & Value :: Status ( "42" . into ( ) ) ) ;
42
+ assert_eq ! ( i, Ok ( 42i32 ) ) ;
43
+
44
+ let i = FromRedisValue :: from_redis_value ( & Value :: Int ( 42 ) ) ;
45
+ assert_eq ! ( i, Ok ( 42i32 ) ) ;
46
+
47
+ let i = FromRedisValue :: from_redis_value ( & Value :: Data ( "42" . into ( ) ) ) ;
48
+ assert_eq ! ( i, Ok ( 42i32 ) ) ;
49
+
50
+ let bad_i : Result < i32 , _ > = FromRedisValue :: from_redis_value (
51
+ & Value :: Status ( "42x" . into ( ) ) ) ;
52
+ assert_eq ! ( bad_i. unwrap_err( ) . kind( ) , ErrorKind :: TypeError ) ;
53
+ }
54
+
55
+ #[ test]
56
+ fn test_u32 ( ) {
57
+ use redis:: { FromRedisValue , Value , ErrorKind } ;
58
+
59
+ let i = FromRedisValue :: from_redis_value ( & Value :: Status ( "42" . into ( ) ) ) ;
60
+ assert_eq ! ( i, Ok ( 42u32 ) ) ;
61
+
62
+ let bad_i : Result < i32 , _ > = FromRedisValue :: from_redis_value (
63
+ & Value :: Status ( "-1" . into ( ) ) ) ;
64
+ assert_eq ! ( bad_i. unwrap_err( ) . kind( ) , ErrorKind :: TypeError ) ;
65
+ }
66
+
67
+ #[ test]
68
+ fn test_vec ( ) {
69
+ use redis:: { FromRedisValue , Value } ;
70
+
71
+ let v = FromRedisValue :: from_redis_value ( & Value :: Bulk ( vec ! [
72
+ Value :: Data ( "1" . into( ) ) ,
73
+ Value :: Data ( "2" . into( ) ) ,
74
+ Value :: Data ( "3" . into( ) ) ,
75
+ ] ) ) ;
76
+
77
+ assert_eq ! ( v, Ok ( vec![ 1i32 , 2 , 3 ] ) ) ;
78
+ }
79
+
80
+ #[ test]
81
+ fn test_bool ( ) {
82
+ use redis:: { FromRedisValue , Value , ErrorKind } ;
83
+
84
+ let v = FromRedisValue :: from_redis_value ( & Value :: Status ( "1" . into ( ) ) ) ;
85
+ assert_eq ! ( v, Ok ( true ) ) ;
86
+
87
+ let v = FromRedisValue :: from_redis_value ( & Value :: Status ( "0" . into ( ) ) ) ;
88
+ assert_eq ! ( v, Ok ( false ) ) ;
89
+
90
+ let v : Result < bool , _ > = FromRedisValue :: from_redis_value (
91
+ & Value :: Status ( "garbage" . into ( ) ) ) ;
92
+ assert_eq ! ( v. unwrap_err( ) . kind( ) , ErrorKind :: TypeError ) ;
93
+
94
+ let v = FromRedisValue :: from_redis_value ( & Value :: Okay ) ;
95
+ assert_eq ! ( v, Ok ( true ) ) ;
96
+
97
+ let v = FromRedisValue :: from_redis_value ( & Value :: Nil ) ;
98
+ assert_eq ! ( v, Ok ( false ) ) ;
99
+
100
+ let v = FromRedisValue :: from_redis_value ( & Value :: Int ( 0 ) ) ;
101
+ assert_eq ! ( v, Ok ( false ) ) ;
102
+
103
+ let v = FromRedisValue :: from_redis_value ( & Value :: Int ( 42 ) ) ;
104
+ assert_eq ! ( v, Ok ( true ) ) ;
105
+ }
0 commit comments