Skip to content

Commit a18ae19

Browse files
committed
Unify assert_eq!(…)/assert_ne!(…) to take args in order of …!(actual, expected)
While there isn't an explicit convention for this in Rust the stdlib docs all use `…!(actual, expected)`, making it a sort of implicit convention.
1 parent 958c0c4 commit a18ae19

File tree

78 files changed

+751
-751
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+751
-751
lines changed

data/src/data_channel/data_channel_test.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,12 @@ async fn test_data_channel_buffered_amount() -> Result<()> {
450450
}
451451

452452
let n = dc0.write(&Bytes::new()).await?;
453-
assert_eq!(0, n, "data length should match");
454-
assert_eq!(1, dc0.buffered_amount(), "incorrect bufferedAmount");
453+
assert_eq!(n, 0, "data length should match");
454+
assert_eq!(dc0.buffered_amount(), 1, "incorrect bufferedAmount");
455455

456456
let n = dc0.write(&Bytes::from_static(&[0])).await?;
457-
assert_eq!(1, n, "data length should match");
458-
assert_eq!(2, dc0.buffered_amount(), "incorrect bufferedAmount");
457+
assert_eq!(n, 1, "data length should match");
458+
assert_eq!(dc0.buffered_amount(), 2, "incorrect bufferedAmount");
459459

460460
bridge_process_at_least_one(&br).await;
461461

@@ -467,8 +467,8 @@ async fn test_data_channel_buffered_amount() -> Result<()> {
467467

468468
dc0.set_buffered_amount_low_threshold(1500);
469469
assert_eq!(
470-
1500,
471470
dc0.buffered_amount_low_threshold(),
471+
1500,
472472
"incorrect bufferedAmountLowThreshold"
473473
);
474474
let n_cbs2 = Arc::clone(&n_cbs);
@@ -549,28 +549,28 @@ async fn test_stats() -> Result<()> {
549549
let mut bytes_sent = 0;
550550

551551
let n = dc0.write(&Bytes::from(sbuf.clone())).await?;
552-
assert_eq!(sbuf.len(), n, "data length should match");
552+
assert_eq!(n, sbuf.len(), "data length should match");
553553
bytes_sent += n;
554554

555555
assert_eq!(dc0.bytes_sent(), bytes_sent);
556556
assert_eq!(dc0.messages_sent(), 1);
557557

558558
let n = dc0.write(&Bytes::from(sbuf.clone())).await?;
559-
assert_eq!(sbuf.len(), n, "data length should match");
559+
assert_eq!(n, sbuf.len(), "data length should match");
560560
bytes_sent += n;
561561

562562
assert_eq!(dc0.bytes_sent(), bytes_sent);
563563
assert_eq!(dc0.messages_sent(), 2);
564564

565565
let n = dc0.write(&Bytes::from_static(&[0])).await?;
566-
assert_eq!(1, n, "data length should match");
566+
assert_eq!(n, 1, "data length should match");
567567
bytes_sent += n;
568568

569569
assert_eq!(dc0.bytes_sent(), bytes_sent);
570570
assert_eq!(dc0.messages_sent(), 3);
571571

572572
let n = dc0.write(&Bytes::from_static(&[])).await?;
573-
assert_eq!(0, n, "data length should match");
573+
assert_eq!(n, 0, "data length should match");
574574
bytes_sent += n;
575575

576576
assert_eq!(dc0.bytes_sent(), bytes_sent);
@@ -581,28 +581,28 @@ async fn test_stats() -> Result<()> {
581581
let mut bytes_read = 0;
582582

583583
let n = dc1.read(&mut rbuf[..]).await?;
584-
assert_eq!(sbuf.len(), n, "data length should match");
584+
assert_eq!(n, sbuf.len(), "data length should match");
585585
bytes_read += n;
586586

587587
assert_eq!(dc1.bytes_received(), bytes_read);
588588
assert_eq!(dc1.messages_received(), 1);
589589

590590
let n = dc1.read(&mut rbuf[..]).await?;
591-
assert_eq!(sbuf.len(), n, "data length should match");
591+
assert_eq!(n, sbuf.len(), "data length should match");
592592
bytes_read += n;
593593

594594
assert_eq!(dc1.bytes_received(), bytes_read);
595595
assert_eq!(dc1.messages_received(), 2);
596596

597597
let n = dc1.read(&mut rbuf[..]).await?;
598-
assert_eq!(1, n, "data length should match");
598+
assert_eq!(n, 1, "data length should match");
599599
bytes_read += n;
600600

601601
assert_eq!(dc1.bytes_received(), bytes_read);
602602
assert_eq!(dc1.messages_received(), 3);
603603

604604
let n = dc1.read(&mut rbuf[..]).await?;
605-
assert_eq!(0, n, "data length should match");
605+
assert_eq!(n, 0, "data length should match");
606606
bytes_read += n;
607607

608608
assert_eq!(dc1.bytes_received(), bytes_read);

data/src/message/message_test.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,9 @@ fn test_message_unmarshal_ack_success() -> Result<()> {
4646
fn test_message_unmarshal_invalid_message_type() {
4747
let mut bytes = Bytes::from_static(&[0x01]);
4848
let expected = Error::InvalidMessageType(0x01);
49-
let actual = Message::unmarshal(&mut bytes);
50-
if let Err(err) = actual {
51-
assert_eq!(expected, err);
52-
} else {
53-
panic!("expected err, but got ok");
54-
}
49+
let result = Message::unmarshal(&mut bytes);
50+
let actual = result.expect_err("expected err, but got ok");
51+
assert_eq!(actual, expected);
5552
}
5653

5754
#[test]

dtls/src/crypto/crypto_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn test_generate_key_signature() -> Result<()> {
9797
)?;
9898

9999
assert_eq!(
100-
expected_signature, signature,
100+
signature, expected_signature,
101101
"Signature generation failed \nexp {:?} \nactual {:?} ",
102102
expected_signature, signature
103103
);
@@ -134,8 +134,8 @@ fn test_ccm_encryption_and_decryption() -> Result<()> {
134134
let cipher_text = ccm.encrypt(&rlh, &raw)?;
135135

136136
assert_eq!(
137-
[0, 27],
138137
&cipher_text[RECORD_LAYER_HEADER_SIZE - 2..RECORD_LAYER_HEADER_SIZE],
138+
[0, 27],
139139
"RecordLayer size updating failed \nexp: {:?} \nactual {:?} ",
140140
[0, 27],
141141
&cipher_text[RECORD_LAYER_HEADER_SIZE - 2..RECORD_LAYER_HEADER_SIZE]

ice/src/external_ip_mapper/external_ip_mapper_test.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ fn test_external_ip_mapper_new_external_ip_mapper() -> Result<()> {
2727
assert_eq!(m.candidate_type, CandidateType::Host, "should match");
2828
assert!(m.ipv4_mapping.ip_sole.is_some());
2929
assert!(m.ipv6_mapping.ip_sole.is_none());
30-
assert_eq!(0, m.ipv4_mapping.ip_map.len(), "should match");
31-
assert_eq!(0, m.ipv6_mapping.ip_map.len(), "should match");
30+
assert_eq!(m.ipv4_mapping.ip_map.len(), 0, "should match");
31+
assert_eq!(m.ipv6_mapping.ip_map.len(), 0, "should match");
3232

3333
// IPv4 with no explicit local IP, using CandidateTypeServerReflexive
3434
let m =
@@ -40,29 +40,29 @@ fn test_external_ip_mapper_new_external_ip_mapper() -> Result<()> {
4040
);
4141
assert!(m.ipv4_mapping.ip_sole.is_some());
4242
assert!(m.ipv6_mapping.ip_sole.is_none());
43-
assert_eq!(0, m.ipv4_mapping.ip_map.len(), "should match");
44-
assert_eq!(0, m.ipv6_mapping.ip_map.len(), "should match");
43+
assert_eq!(m.ipv4_mapping.ip_map.len(), 0, "should match");
44+
assert_eq!(m.ipv6_mapping.ip_map.len(), 0, "should match");
4545

4646
// IPv4 with no explicit local IP, defaults to CandidateTypeHost
4747
let m = ExternalIpMapper::new(CandidateType::Unspecified, &["2601:4567::5678".to_owned()])?
4848
.unwrap();
49-
assert_eq!(CandidateType::Host, m.candidate_type, "should match");
49+
assert_eq!(m.candidate_type, CandidateType::Host, "should match");
5050
assert!(m.ipv4_mapping.ip_sole.is_none());
5151
assert!(m.ipv6_mapping.ip_sole.is_some());
52-
assert_eq!(0, m.ipv4_mapping.ip_map.len(), "should match");
53-
assert_eq!(0, m.ipv6_mapping.ip_map.len(), "should match");
52+
assert_eq!(m.ipv4_mapping.ip_map.len(), 0, "should match");
53+
assert_eq!(m.ipv6_mapping.ip_map.len(), 0, "should match");
5454

5555
// IPv4 and IPv6 in the mix
5656
let m = ExternalIpMapper::new(
5757
CandidateType::Unspecified,
5858
&["1.2.3.4".to_owned(), "2601:4567::5678".to_owned()],
5959
)?
6060
.unwrap();
61-
assert_eq!(CandidateType::Host, m.candidate_type, "should match");
61+
assert_eq!(m.candidate_type, CandidateType::Host, "should match");
6262
assert!(m.ipv4_mapping.ip_sole.is_some());
6363
assert!(m.ipv6_mapping.ip_sole.is_some());
64-
assert_eq!(0, m.ipv4_mapping.ip_map.len(), "should match");
65-
assert_eq!(0, m.ipv6_mapping.ip_map.len(), "should match");
64+
assert_eq!(m.ipv4_mapping.ip_map.len(), 0, "should match");
65+
assert_eq!(m.ipv6_mapping.ip_map.len(), 0, "should match");
6666

6767
// Unsupported candidate type - CandidateTypePeerReflexive
6868
let result = ExternalIpMapper::new(CandidateType::PeerReflexive, &["1.2.3.4".to_owned()]);
@@ -105,11 +105,11 @@ fn test_external_ip_mapper_new_external_ip_mapper_with_explicit_local_ip() -> Re
105105
// IPv4 with explicit local IP, defaults to CandidateTypeHost
106106
let m = ExternalIpMapper::new(CandidateType::Unspecified, &["1.2.3.4/10.0.0.1".to_owned()])?
107107
.unwrap();
108-
assert_eq!(CandidateType::Host, m.candidate_type, "should match");
108+
assert_eq!(m.candidate_type, CandidateType::Host, "should match");
109109
assert!(m.ipv4_mapping.ip_sole.is_none());
110110
assert!(m.ipv6_mapping.ip_sole.is_none());
111-
assert_eq!(1, m.ipv4_mapping.ip_map.len(), "should match");
112-
assert_eq!(0, m.ipv6_mapping.ip_map.len(), "should match");
111+
assert_eq!(m.ipv4_mapping.ip_map.len(), 1, "should match");
112+
assert_eq!(m.ipv6_mapping.ip_map.len(), 0, "should match");
113113

114114
// Cannot assign two ext IPs for one local IPv4
115115
let result = ExternalIpMapper::new(
@@ -179,11 +179,11 @@ fn test_external_ip_mapper_find_external_ip_without_explicit_local_ip() -> Resul
179179

180180
// find external IPv4
181181
let ext_ip = m.find_external_ip("10.0.0.1")?;
182-
assert_eq!("1.2.3.4", ext_ip.to_string(), "should match");
182+
assert_eq!(ext_ip.to_string(), "1.2.3.4", "should match");
183183

184184
// find external IPv6
185185
let ext_ip = m.find_external_ip("fe80::0001")?; // use '0001' instead of '1' on purpse
186-
assert_eq!("2200::1", ext_ip.to_string(), "should match");
186+
assert_eq!(ext_ip.to_string(), "2200::1", "should match");
187187

188188
// Bad local IP string
189189
let result = m.find_external_ip("really.bad");
@@ -208,20 +208,20 @@ fn test_external_ip_mapper_find_external_ip_with_explicit_local_ip() -> Result<(
208208

209209
// find external IPv4
210210
let ext_ip = m.find_external_ip("10.0.0.1")?;
211-
assert_eq!("1.2.3.4", ext_ip.to_string(), "should match");
211+
assert_eq!(ext_ip.to_string(), "1.2.3.4", "should match");
212212

213213
let ext_ip = m.find_external_ip("10.0.0.2")?;
214-
assert_eq!("1.2.3.5", ext_ip.to_string(), "should match");
214+
assert_eq!(ext_ip.to_string(), "1.2.3.5", "should match");
215215

216216
let result = m.find_external_ip("10.0.0.3");
217217
assert!(result.is_err(), "should fail");
218218

219219
// find external IPv6
220220
let ext_ip = m.find_external_ip("fe80::0001")?; // use '0001' instead of '1' on purpse
221-
assert_eq!("2200::1", ext_ip.to_string(), "should match");
221+
assert_eq!(ext_ip.to_string(), "2200::1", "should match");
222222

223223
let ext_ip = m.find_external_ip("fe80::0002")?; // use '0002' instead of '2' on purpse
224-
assert_eq!("2200::2", ext_ip.to_string(), "should match");
224+
assert_eq!(ext_ip.to_string(), "2200::2", "should match");
225225

226226
let result = m.find_external_ip("fe80::3");
227227
assert!(result.is_err(), "should fail");

ice/src/mdns/mdns_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ async fn test_multicast_dns_static_host_name() -> Result<()> {
9090
..Default::default()
9191
};
9292
if let Err(err) = Agent::new(cfg0).await {
93-
assert_eq!(Error::ErrInvalidMulticastDnshostName, err);
93+
assert_eq!(err, Error::ErrInvalidMulticastDnshostName);
9494
} else {
9595
panic!("expected error, but got ok");
9696
}

ice/src/network_type/network_type_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,6 @@ fn test_network_type_to_string() {
9393
];
9494

9595
for (network_type, expected_string) in tests {
96-
assert_eq!(expected_string, network_type.to_string());
96+
assert_eq!(network_type.to_string(), expected_string);
9797
}
9898
}

ice/src/priority/priority_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn test_priority_get_from() -> Result<()> {
77
let mut p = PriorityAttr::default();
88
let result = p.get_from(&m);
99
if let Err(err) = result {
10-
assert_eq!(stun::Error::ErrAttributeNotFound, err, "unexpected error");
10+
assert_eq!(err, stun::Error::ErrAttributeNotFound, "unexpected error");
1111
} else {
1212
panic!("expected error, but got ok");
1313
}

ice/src/state/state_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ fn test_connected_state_string() -> Result<()> {
1616

1717
for (connection_state, expected_string) in tests {
1818
assert_eq!(
19-
expected_string,
2019
connection_state.to_string(),
20+
expected_string,
2121
"testCase: {} vs {}",
2222
expected_string,
2323
connection_state,
@@ -38,8 +38,8 @@ fn test_gathering_state_string() -> Result<()> {
3838

3939
for (gathering_state, expected_string) in tests {
4040
assert_eq!(
41-
expected_string,
4241
gathering_state.to_string(),
42+
expected_string,
4343
"testCase: {} vs {}",
4444
expected_string,
4545
gathering_state,

ice/src/tcp_type/tcp_type_test.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ use crate::error::Result;
33

44
#[test]
55
fn test_tcp_type() -> Result<()> {
6-
//assert_eq!(TCPType::Unspecified, tcpType)
7-
assert_eq!(TcpType::Active, TcpType::from("active"));
8-
assert_eq!(TcpType::Passive, TcpType::from("passive"));
9-
assert_eq!(TcpType::SimultaneousOpen, TcpType::from("so"));
10-
assert_eq!(TcpType::Unspecified, TcpType::from("something else"));
6+
//assert_eq!(tcpType, TCPType::Unspecified)
7+
assert_eq!(TcpType::from("active"), TcpType::Active);
8+
assert_eq!(TcpType::from("passive"), TcpType::Passive);
9+
assert_eq!(TcpType::from("so"), TcpType::SimultaneousOpen);
10+
assert_eq!(TcpType::from("something else"), TcpType::Unspecified);
1111

12-
assert_eq!("unspecified", TcpType::Unspecified.to_string());
13-
assert_eq!("active", TcpType::Active.to_string());
14-
assert_eq!("passive", TcpType::Passive.to_string());
15-
assert_eq!("so", TcpType::SimultaneousOpen.to_string());
12+
assert_eq!(TcpType::Unspecified.to_string(), "unspecified");
13+
assert_eq!(TcpType::Active.to_string(), "active");
14+
assert_eq!(TcpType::Passive.to_string(), "passive");
15+
assert_eq!(TcpType::SimultaneousOpen.to_string(), "so");
1616

1717
Ok(())
1818
}

ice/src/url/url_test.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ fn test_parse_url_success() -> Result<()> {
8989
{
9090
let url = Url::parse_url(raw_url)?;
9191

92-
assert_eq!(expected_scheme, url.scheme, "testCase: {:?}", raw_url);
92+
assert_eq!(url.scheme, expected_scheme, "testCase: {:?}", raw_url);
9393
assert_eq!(
9494
expected_url_string,
9595
url.to_string(),
9696
"testCase: {:?}",
9797
raw_url
9898
);
99-
assert_eq!(expected_secure, url.is_secure(), "testCase: {:?}", raw_url);
100-
assert_eq!(expected_host, url.host, "testCase: {:?}", raw_url);
101-
assert_eq!(expected_port, url.port, "testCase: {:?}", raw_url);
102-
assert_eq!(expected_proto, url.proto, "testCase: {:?}", raw_url);
99+
assert_eq!(url.is_secure(), expected_secure, "testCase: {:?}", raw_url);
100+
assert_eq!(url.host, expected_host, "testCase: {:?}", raw_url);
101+
assert_eq!(url.port, expected_port, "testCase: {:?}", raw_url);
102+
assert_eq!(url.proto, expected_proto, "testCase: {:?}", raw_url);
103103
}
104104

105105
Ok(())

interceptor/src/nack/generator/generator_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async fn test_generator_interceptor() -> Result<()> {
4242
.await
4343
.expect("A read packet")
4444
.expect("Not an error");
45-
assert_eq!(seq_num, r.header.sequence_number);
45+
assert_eq!(r.header.sequence_number, seq_num);
4646
}
4747

4848
tokio::time::sleep(INTERVAL * 2).await; // wait for at least 2 nack packets
@@ -54,8 +54,8 @@ async fn test_generator_interceptor() -> Result<()> {
5454
.await
5555
.expect("Write rtcp");
5656
if let Some(p) = r[0].as_any().downcast_ref::<TransportLayerNack>() {
57-
assert_eq!(13, p.nacks[0].packet_id);
58-
assert_eq!(0b10, p.nacks[0].lost_packets); // we want packets: 13, 15 (not packet 17, because skipLastN is setReceived to 2)
57+
assert_eq!(p.nacks[0].packet_id, 13);
58+
assert_eq!(p.nacks[0].lost_packets, 0b10); // we want packets: 13, 15 (not packet 17, because skipLastN is setReceived to 2)
5959
} else {
6060
assert!(false, "single packet RTCP Compound Packet expected");
6161
}

interceptor/src/nack/responder/responder_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async fn test_responder_interceptor() -> Result<()> {
3838
let p = timeout_or_fail(Duration::from_millis(10), stream.written_rtp())
3939
.await
4040
.expect("A packet");
41-
assert_eq!(seq_num, p.header.sequence_number);
41+
assert_eq!(p.header.sequence_number, seq_num);
4242
}
4343

4444
stream
@@ -58,7 +58,7 @@ async fn test_responder_interceptor() -> Result<()> {
5858
for seq_num in [11, 12, 15] {
5959
if let Ok(r) = tokio::time::timeout(Duration::from_millis(50), stream.written_rtp()).await {
6060
if let Some(p) = r {
61-
assert_eq!(seq_num, p.header.sequence_number);
61+
assert_eq!(p.header.sequence_number, seq_num);
6262
} else {
6363
assert!(
6464
false,

0 commit comments

Comments
 (0)