11use bytes:: { Bytes , BytesMut } ;
2- use matches:: { assert_matches, matches} ;
32
43use crate :: error:: Error ;
54use crate :: packet:: { self , Mode , Opts , Packet , RwReq } ;
@@ -15,13 +14,13 @@ fn packet_to_bytes(packet: &Packet) -> Bytes {
1514fn check_rrq ( ) {
1615 let packet = Packet :: decode ( b"\x00 \x01 abc\0 netascii\0 " ) ;
1716
18- assert_matches ! ( packet, Ok ( Packet :: Rrq ( ref req) )
17+ assert ! ( matches !( packet, Ok ( Packet :: Rrq ( ref req) )
1918 if req == & RwReq {
2019 filename: "abc" . to_string( ) ,
2120 mode: Mode :: Netascii ,
2221 opts: Opts :: default ( )
2322 }
24- ) ;
23+ ) ) ;
2524
2625 assert_eq ! (
2726 packet_to_bytes( & packet. unwrap( ) ) ,
@@ -30,33 +29,33 @@ fn check_rrq() {
3029
3130 let packet = Packet :: decode ( b"\x00 \x01 abc\0 netascII\0 " ) ;
3231
33- assert_matches ! ( packet, Ok ( Packet :: Rrq ( ref req) )
32+ assert ! ( matches !( packet, Ok ( Packet :: Rrq ( ref req) )
3433 if req == & RwReq {
3534 filename: "abc" . to_string( ) ,
3635 mode: Mode :: Netascii ,
3736 opts: Opts :: default ( )
3837 }
39- ) ;
38+ ) ) ;
4039
4140 assert_eq ! (
4241 packet_to_bytes( & packet. unwrap( ) ) ,
4342 b"\x00 \x01 abc\0 netascii\0 " [ ..]
4443 ) ;
4544
4645 let packet = Packet :: decode ( b"\x00 \x01 abc\0 netascii\0 more" ) ;
47- assert_matches ! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ;
46+ assert ! ( matches! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ) ;
4847
4948 let packet = Packet :: decode ( b"\x00 \x01 abc\0 netascii" ) ;
50- assert_matches ! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ;
49+ assert ! ( matches! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ) ;
5150
5251 let packet = Packet :: decode ( b"\x00 \x01 abc\0 netascXX\0 " ) ;
53- assert_matches ! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ;
52+ assert ! ( matches! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ) ;
5453
5554 let packet = Packet :: decode (
5655 b"\x00 \x01 abc\0 netascii\0 blksize\0 123\0 timeout\0 3\0 tsize\0 5556\0 " ,
5756 ) ;
5857
59- assert_matches ! ( packet, Ok ( Packet :: Rrq ( ref req) )
58+ assert ! ( matches !( packet, Ok ( Packet :: Rrq ( ref req) )
6059 if req == & RwReq {
6160 filename: "abc" . to_string( ) ,
6261 mode: Mode :: Netascii ,
@@ -66,7 +65,7 @@ fn check_rrq() {
6665 transfer_size: Some ( 5556 )
6766 }
6867 }
69- ) ;
68+ ) ) ;
7069
7170 assert_eq ! (
7271 packet_to_bytes( & packet. unwrap( ) ) ,
@@ -76,58 +75,58 @@ fn check_rrq() {
7675 let packet = Packet :: decode (
7776 b"\x00 \x01 abc\0 netascii\0 blksize\0 123\0 timeout\0 3\0 tsize\0 " ,
7877 ) ;
79- assert_matches ! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ;
78+ assert ! ( matches! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ) ;
8079
8180 let packet = Packet :: decode ( b"\x00 \x01 abc\0 netascii\0 blksizeX\0 123\0 " ) ;
82- assert_matches ! ( packet, Ok ( Packet :: Rrq ( ref req) )
81+ assert ! ( matches !( packet, Ok ( Packet :: Rrq ( ref req) )
8382 if req == & RwReq {
8483 filename: "abc" . to_string( ) ,
8584 mode: Mode :: Netascii ,
8685 opts: Opts :: default ( )
8786 }
88- ) ;
87+ ) ) ;
8988}
9089
9190#[ test]
9291fn check_wrq ( ) {
9392 let packet = Packet :: decode ( b"\x00 \x02 abc\0 octet\0 " ) ;
9493
95- assert_matches ! ( packet, Ok ( Packet :: Wrq ( ref req) )
94+ assert ! ( matches !( packet, Ok ( Packet :: Wrq ( ref req) )
9695 if req == & RwReq {
9796 filename: "abc" . to_string( ) ,
9897 mode: Mode :: Octet ,
9998 opts: Opts :: default ( )
10099 }
101- ) ;
100+ ) ) ;
102101
103102 assert_eq ! ( packet_to_bytes( & packet. unwrap( ) ) , b"\x00 \x02 abc\0 octet\0 " [ ..] ) ;
104103
105104 let packet = Packet :: decode ( b"\x00 \x02 abc\0 OCTet\0 " ) ;
106105
107- assert_matches ! ( packet, Ok ( Packet :: Wrq ( ref req) )
106+ assert ! ( matches !( packet, Ok ( Packet :: Wrq ( ref req) )
108107 if req == & RwReq {
109108 filename: "abc" . to_string( ) ,
110109 mode: Mode :: Octet ,
111110 opts: Opts :: default ( )
112111 }
113- ) ;
112+ ) ) ;
114113
115114 assert_eq ! ( packet_to_bytes( & packet. unwrap( ) ) , b"\x00 \x02 abc\0 octet\0 " [ ..] ) ;
116115
117116 let packet = Packet :: decode ( b"\x00 \x02 abc\0 octet\0 more" ) ;
118- assert_matches ! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ;
117+ assert ! ( matches! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ) ;
119118
120119 let packet = Packet :: decode ( b"\x00 \x02 abc\0 octet" ) ;
121- assert_matches ! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ;
120+ assert ! ( matches! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ) ;
122121
123122 let packet = Packet :: decode ( b"\x00 \x02 abc\0 octex\0 " ) ;
124- assert_matches ! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ;
123+ assert ! ( matches! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ) ;
125124
126125 let packet = Packet :: decode (
127126 b"\x00 \x02 abc\0 octet\0 blksize\0 123\0 timeout\0 3\0 tsize\0 5556\0 " ,
128127 ) ;
129128
130- assert_matches ! ( packet, Ok ( Packet :: Wrq ( ref req) )
129+ assert ! ( matches !( packet, Ok ( Packet :: Wrq ( ref req) )
131130 if req == & RwReq {
132131 filename: "abc" . to_string( ) ,
133132 mode: Mode :: Octet ,
@@ -137,128 +136,132 @@ fn check_wrq() {
137136 transfer_size: Some ( 5556 )
138137 }
139138 }
140- ) ;
139+ ) ) ;
141140
142141 assert_eq ! (
143142 packet_to_bytes( & packet. unwrap( ) ) ,
144143 b"\x00 \x02 abc\0 octet\0 blksize\0 123\0 timeout\0 3\0 tsize\0 5556\0 " [ ..]
145144 ) ;
146145
147146 let packet = Packet :: decode ( b"\x00 \x02 abc\0 octet\0 blksizeX\0 123\0 " ) ;
148- assert_matches ! ( packet, Ok ( Packet :: Wrq ( ref req) )
147+ assert ! ( matches !( packet, Ok ( Packet :: Wrq ( ref req) )
149148 if req == & RwReq {
150149 filename: "abc" . to_string( ) ,
151150 mode: Mode :: Octet ,
152151 opts: Opts :: default ( )
153152 }
154- ) ;
153+ ) ) ;
155154}
156155
157156#[ test]
158157fn check_data ( ) {
159158 let packet = Packet :: decode ( b"\x00 \x03 \x00 \x09 abcde" ) ;
160- assert_matches ! ( packet, Ok ( Packet :: Data ( 9 , ref data) ) if & data[ ..] == b"abcde" ) ;
159+ assert ! (
160+ matches!( packet, Ok ( Packet :: Data ( 9 , ref data) ) if & data[ ..] == b"abcde" )
161+ ) ;
161162
162163 assert_eq ! ( packet_to_bytes( & packet. unwrap( ) ) , b"\x00 \x03 \x00 \x09 abcde" [ ..] ) ;
163164
164165 let packet = Packet :: decode ( b"\x00 \x03 \x00 \x09 " ) ;
165- assert_matches ! ( packet, Ok ( Packet :: Data ( 9 , ref data) ) if data. is_empty( ) ) ;
166+ assert ! ( matches! ( packet, Ok ( Packet :: Data ( 9 , ref data) ) if data. is_empty( ) ) ) ;
166167 assert_eq ! ( packet_to_bytes( & packet. unwrap( ) ) , b"\x00 \x03 \x00 \x09 " [ ..] ) ;
167168}
168169
169170#[ test]
170171fn check_ack ( ) {
171172 let packet = Packet :: decode ( b"\x00 \x04 \x00 \x09 " ) ;
172- assert_matches ! ( packet, Ok ( Packet :: Ack ( 9 ) ) ) ;
173+ assert ! ( matches! ( packet, Ok ( Packet :: Ack ( 9 ) ) ) ) ;
173174 assert_eq ! ( packet_to_bytes( & packet. unwrap( ) ) , b"\x00 \x04 \x00 \x09 " [ ..] ) ;
174175
175176 let packet = Packet :: decode ( b"\x00 \x04 \x00 " ) ;
176- assert_matches ! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ;
177+ assert ! ( matches! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ) ;
177178
178179 let packet = Packet :: decode ( b"\x00 \x04 \x00 \x09 a" ) ;
179- assert_matches ! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ;
180+ assert ! ( matches! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ) ;
180181}
181182
182183#[ test]
183184fn check_error ( ) {
184185 let packet = Packet :: decode ( b"\x00 \x05 \x00 \x01 msg\0 " ) ;
185- assert_matches ! ( packet, Ok ( Packet :: Error ( packet:: Error :: FileNotFound ) ) ) ;
186+ assert ! ( matches! ( packet, Ok ( Packet :: Error ( packet:: Error :: FileNotFound ) ) ) ) ;
186187 assert_eq ! (
187188 packet_to_bytes( & packet. unwrap( ) ) ,
188189 b"\x00 \x05 \x00 \x01 File not found\0 " [ ..]
189190 ) ;
190191
191192 // 0x10 is unknown error code an will be treated as 0
192193 let packet = Packet :: decode ( b"\x00 \x05 \x00 \x10 msg\0 " ) ;
193- assert_matches ! ( packet, Ok ( Packet :: Error ( packet:: Error :: Msg ( ref errmsg) ) )
194- if errmsg == "msg" ) ;
194+ assert ! ( matches !( packet, Ok ( Packet :: Error ( packet:: Error :: Msg ( ref errmsg) ) )
195+ if errmsg == "msg" ) ) ;
195196 assert_eq ! ( packet_to_bytes( & packet. unwrap( ) ) , b"\x00 \x05 \x00 \x00 msg\0 " [ ..] ) ;
196197
197198 let packet = Packet :: decode ( b"\x00 \x05 \x00 \x00 msg\0 " ) ;
198- assert_matches ! ( packet, Ok ( Packet :: Error ( packet:: Error :: Msg ( ref errmsg) ) )
199- if errmsg == "msg" ) ;
199+ assert ! ( matches !( packet, Ok ( Packet :: Error ( packet:: Error :: Msg ( ref errmsg) ) )
200+ if errmsg == "msg" ) ) ;
200201 assert_eq ! ( packet_to_bytes( & packet. unwrap( ) ) , b"\x00 \x05 \x00 \x00 msg\0 " [ ..] ) ;
201202
202203 let packet = Packet :: decode ( b"\x00 \x05 \x00 \x00 msg\0 more" ) ;
203- assert_matches ! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ;
204+ assert ! ( matches! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ) ;
204205
205206 let packet = Packet :: decode ( b"\x00 \x05 \x00 \x00 msg" ) ;
206- assert_matches ! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ;
207+ assert ! ( matches! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ) ;
207208
208209 let packet = Packet :: decode ( b"\x00 \x05 \x00 \x00 " ) ;
209- assert_matches ! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ;
210+ assert ! ( matches! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ) ;
210211}
211212
212213#[ test]
213214fn check_oack ( ) {
214215 let packet = Packet :: decode ( b"\x00 \x06 " ) ;
215- assert_matches ! ( packet, Ok ( Packet :: OAck ( ref opts) ) if opts == & Opts :: default ( ) ) ;
216+ assert ! (
217+ matches!( packet, Ok ( Packet :: OAck ( ref opts) ) if opts == & Opts :: default ( ) )
218+ ) ;
216219
217220 let packet = Packet :: decode ( b"\x00 \x06 blksize\0 123\0 " ) ;
218- assert_matches ! ( packet, Ok ( Packet :: OAck ( ref opts) )
221+ assert ! ( matches !( packet, Ok ( Packet :: OAck ( ref opts) )
219222 if opts == & Opts {
220223 block_size: Some ( 123 ) ,
221224 timeout: None ,
222225 transfer_size: None
223226 }
224- ) ;
227+ ) ) ;
225228
226229 let packet = Packet :: decode ( b"\x00 \x06 timeout\0 3\0 " ) ;
227- assert_matches ! ( packet, Ok ( Packet :: OAck ( ref opts) )
230+ assert ! ( matches !( packet, Ok ( Packet :: OAck ( ref opts) )
228231 if opts == & Opts {
229232 block_size: None ,
230233 timeout: Some ( 3 ) ,
231234 transfer_size: None
232235 }
233- ) ;
236+ ) ) ;
234237
235238 let packet = Packet :: decode ( b"\x00 \x06 tsize\0 5556\0 " ) ;
236- assert_matches ! ( packet, Ok ( Packet :: OAck ( ref opts) )
239+ assert ! ( matches !( packet, Ok ( Packet :: OAck ( ref opts) )
237240 if opts == & Opts {
238241 block_size: None ,
239242 timeout: None ,
240243 transfer_size: Some ( 5556 ) ,
241244 }
242- ) ;
245+ ) ) ;
243246
244247 let packet =
245248 Packet :: decode ( b"\x00 \x06 tsize\0 5556\0 blksize\0 123\0 timeout\0 3\0 " ) ;
246- assert_matches ! ( packet, Ok ( Packet :: OAck ( ref opts) )
249+ assert ! ( matches !( packet, Ok ( Packet :: OAck ( ref opts) )
247250 if opts == & Opts {
248251 block_size: Some ( 123 ) ,
249252 timeout: Some ( 3 ) ,
250253 transfer_size: Some ( 5556 ) ,
251254 }
252- ) ;
255+ ) ) ;
253256}
254257
255258#[ test]
256259fn check_packet ( ) {
257260 let packet = Packet :: decode ( b"\x00 \x07 " ) ;
258- assert_matches ! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ;
261+ assert ! ( matches! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ) ;
259262
260263 let packet = Packet :: decode ( b"\x00 \x05 \x00 " ) ;
261- assert_matches ! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ;
264+ assert ! ( matches! ( packet, Err ( ref e) if matches!( e, Error :: InvalidPacket ) ) ) ;
262265}
263266
264267#[ test]
0 commit comments