Skip to content

Commit d57a571

Browse files
committed
Auto merge of #21862 - iKevinY:libstd-ascii-tests, r=brson
I also noticed that all of the tests iterate through values up to 500. Just out of curiosity, was the choice of 500 arbitrary? I was thinking that it might make more sense to iterate up to 127 due to ASCII's character range (or if non-ASCII characters are being tested intentionally, either 255 or 511 for a nice `2^n - 1` value).
2 parents 134e00b + 00d1873 commit d57a571

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

src/libstd/ascii.rs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -338,21 +338,18 @@ mod tests {
338338
assert!("".is_ascii());
339339
assert!("a".is_ascii());
340340
assert!(!"\u{2009}".is_ascii());
341-
342341
}
343342

344343
#[test]
345344
fn test_to_ascii_uppercase() {
346345
assert_eq!("url()URL()uRl()ürl".to_ascii_uppercase(), "URL()URL()URL()üRL");
347346
assert_eq!("hıKß".to_ascii_uppercase(), "HıKß");
348347

349-
let mut i = 0;
350-
while i <= 500 {
348+
for i in 0u32..501 {
351349
let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 }
352350
else { i };
353351
assert_eq!((from_u32(i).unwrap()).to_string().to_ascii_uppercase(),
354352
(from_u32(upper).unwrap()).to_string());
355-
i += 1;
356353
}
357354
}
358355

@@ -362,13 +359,11 @@ mod tests {
362359
// Dotted capital I, Kelvin sign, Sharp S.
363360
assert_eq!("HİKß".to_ascii_lowercase(), "hİKß");
364361

365-
let mut i = 0;
366-
while i <= 500 {
362+
for i in 0u32..501 {
367363
let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 }
368364
else { i };
369365
assert_eq!((from_u32(i).unwrap()).to_string().to_ascii_lowercase(),
370366
(from_u32(lower).unwrap()).to_string());
371-
i += 1;
372367
}
373368
}
374369

@@ -378,13 +373,11 @@ mod tests {
378373
"URL()URL()URL()üRL".to_string());
379374
assert_eq!(("hıKß".to_string()).into_ascii_uppercase(), "HıKß");
380375

381-
let mut i = 0;
382-
while i <= 500 {
376+
for i in 0u32..501 {
383377
let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 }
384378
else { i };
385379
assert_eq!((from_u32(i).unwrap()).to_string().into_ascii_uppercase(),
386380
(from_u32(upper).unwrap()).to_string());
387-
i += 1;
388381
}
389382
}
390383

@@ -395,13 +388,11 @@ mod tests {
395388
// Dotted capital I, Kelvin sign, Sharp S.
396389
assert_eq!(("HİKß".to_string()).into_ascii_lowercase(), "hİKß");
397390

398-
let mut i = 0;
399-
while i <= 500 {
391+
for i in 0u32..501 {
400392
let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 }
401393
else { i };
402394
assert_eq!((from_u32(i).unwrap()).to_string().into_ascii_lowercase(),
403395
(from_u32(lower).unwrap()).to_string());
404-
i += 1;
405396
}
406397
}
407398

@@ -415,14 +406,11 @@ mod tests {
415406
assert!(!"K".eq_ignore_ascii_case("k"));
416407
assert!(!"ß".eq_ignore_ascii_case("s"));
417408

418-
let mut i = 0;
419-
while i <= 500 {
420-
let c = i;
421-
let lower = if 'A' as u32 <= c && c <= 'Z' as u32 { c + 'a' as u32 - 'A' as u32 }
422-
else { c };
409+
for i in 0u32..501 {
410+
let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 }
411+
else { i };
423412
assert!((from_u32(i).unwrap()).to_string().eq_ignore_ascii_case(
424413
&from_u32(lower).unwrap().to_string()));
425-
i += 1;
426414
}
427415
}
428416
}

0 commit comments

Comments
 (0)