@@ -15,19 +15,19 @@ fn reply_keyboard_markup() {
15
15
16
16
// Test encoding
17
17
let x = RKM :: default ( ) ;
18
- assert_eq ! ( json:: encode( & x) . unwrap( ) , "{ \ " keyboard\ " :[]}". to_string( ) ) ;
18
+ assert_eq ! ( json:: encode( & x) . unwrap( ) , r#"{ "keyboard":[]}"# . to_string( ) ) ;
19
19
20
20
let x = RKM { resize_keyboard : Some ( true ) , ..Default :: default ( ) } ;
21
21
assert_eq ! ( json:: encode( & x) . unwrap( ) ,
22
- "{ \ " keyboard\ " :[],\ " resize_keyboard\ " :true}". to_string( ) ) ;
22
+ r#"{ "keyboard":[],"resize_keyboard":true}"# . to_string( ) ) ;
23
23
24
24
let x = RKM {
25
25
keyboard : vec ! [ vec![ "ABC" . into( ) ] , vec![ "X" . into( ) , "Y" . into( ) ] ] ,
26
26
resize_keyboard : Some ( false ) ,
27
27
..Default :: default ( )
28
28
} ;
29
29
assert_eq ! ( json:: encode( & x) . unwrap( ) ,
30
- "{ \ " keyboard\ " :[[\ " ABC\ " ],[\" X \" , \" Y \ " ]],\ " resize_keyboard\ " :false}". to_string( ) ) ;
30
+ r#"{ "keyboard":[["ABC"],["X","Y "]],"resize_keyboard":false}"# . to_string( ) ) ;
31
31
}
32
32
33
33
#[ test]
@@ -37,15 +37,15 @@ fn keyboard_markup() {
37
37
38
38
// Test encoding
39
39
let x = RM :: Keyboard ( RKM :: default ( ) ) ;
40
- assert_eq ! ( json:: encode( & x) . unwrap( ) , "{ \ " keyboard\ " :[]}". to_string( ) ) ;
40
+ assert_eq ! ( json:: encode( & x) . unwrap( ) , r#"{ "keyboard":[]}"# . to_string( ) ) ;
41
41
42
42
let x = RM :: KeyboardHide ( false ) ;
43
43
assert_eq ! ( json:: encode( & x) . unwrap( ) ,
44
- "{ \ " hide_keyboard\ " :true,\ " selective\ " :false}". to_string( ) ) ;
44
+ r#"{ "hide_keyboard":true,"selective":false}"# . to_string( ) ) ;
45
45
46
46
let x = RM :: ForceReply ( true ) ;
47
47
assert_eq ! ( json:: encode( & x) . unwrap( ) ,
48
- "{ \ " force_reply\ " :true,\ " selective\ " :true}". to_string( ) ) ;
48
+ r#"{ "force_reply":true,"selective":true}"# . to_string( ) ) ;
49
49
}
50
50
51
51
#[ test]
@@ -73,3 +73,76 @@ fn decode_user_chat() {
73
73
assert ! ( chat. is_user( ) ) ;
74
74
assert_eq ! ( Chat :: User ( user) , chat) ;
75
75
}
76
+
77
+ #[ test]
78
+ fn decode_update ( ) {
79
+ use Update ;
80
+ let blob = r#"{
81
+ "message" : {
82
+ "text" : "The quick brown fox jumps over the lazy dog",
83
+ "from" : {
84
+ "first_name" : "test",
85
+ "id" : 123456789,
86
+ "username" : "test"
87
+ },
88
+ "date" : 1437821492,
89
+ "message_id" : 74,
90
+ "chat" : {
91
+ "title" : "This is a group chat",
92
+ "id" : -12345678
93
+ }
94
+ },
95
+ "update_id" : 123456789
96
+ }"# ;
97
+ let _: Update = json:: decode ( & blob) . unwrap ( ) ;
98
+ }
99
+
100
+ #[ test]
101
+ fn decode_get_updates_response ( ) {
102
+ use Response ;
103
+ use Update ;
104
+
105
+ let blob = r#"{
106
+ "result" : [
107
+ {
108
+ "message" : {
109
+ "text" : "This is the first message",
110
+ "from" : {
111
+ "username" : "test",
112
+ "id" : 123456789,
113
+ "first_name" : "Test"
114
+ },
115
+ "date" : 1437821579,
116
+ "message_id" : 78,
117
+ "chat" : {
118
+ "username" : "test",
119
+ "id" : 123456789,
120
+ "first_name" : "Test"
121
+ }
122
+ },
123
+ "update_id" : 123456789
124
+ },
125
+ {
126
+ "message" : {
127
+ "text" : "This is the second message",
128
+ "from" : {
129
+ "username" : "test",
130
+ "id" : 123456789,
131
+ "first_name" : "Test"
132
+ },
133
+ "date" : 1437821579,
134
+ "message_id" : 79,
135
+ "chat" : {
136
+ "username" : "test",
137
+ "id" : 123456789,
138
+ "first_name" : "Test"
139
+ }
140
+ },
141
+ "update_id" : 123456790
142
+ }
143
+ ],
144
+ "ok" : true
145
+ }"# ;
146
+
147
+ let _: Response < Vec < Update > > = json:: decode ( & blob) . unwrap ( ) ;
148
+ }
0 commit comments