From 5257a5b284038d704011c90f14140c16c5a37f7d Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 13:12:30 -0500 Subject: [PATCH] libcoretest: remove unnecessary `as_slice()` calls --- src/libcoretest/cell.rs | 8 +- src/libcoretest/char.rs | 38 +++---- src/libcoretest/fmt/num.rs | 210 ++++++++++++++++++------------------- src/libcoretest/option.rs | 8 +- src/libcoretest/result.rs | 4 +- src/libcoretest/tuple.rs | 6 +- 6 files changed, 137 insertions(+), 137 deletions(-) diff --git a/src/libcoretest/cell.rs b/src/libcoretest/cell.rs index 6444cf7ee0e..54da6264bb0 100644 --- a/src/libcoretest/cell.rs +++ b/src/libcoretest/cell.rs @@ -29,10 +29,10 @@ fn smoketest_cell() { #[test] fn cell_has_sensible_show() { let x = Cell::new("foo bar"); - assert!(format!("{}", x).as_slice().contains(x.get())); + assert!(format!("{}", x).contains(x.get())); x.set("baz qux"); - assert!(format!("{}", x).as_slice().contains(x.get())); + assert!(format!("{}", x).contains(x.get())); } #[test] @@ -40,11 +40,11 @@ fn ref_and_refmut_have_sensible_show() { let refcell = RefCell::new("foo"); let refcell_refmut = refcell.borrow_mut(); - assert!(format!("{}", refcell_refmut).as_slice().contains("foo")); + assert!(format!("{}", refcell_refmut).contains("foo")); drop(refcell_refmut); let refcell_ref = refcell.borrow(); - assert!(format!("{}", refcell_ref).as_slice().contains("foo")); + assert!(format!("{}", refcell_ref).contains("foo")); drop(refcell_ref); } diff --git a/src/libcoretest/char.rs b/src/libcoretest/char.rs index 507ddf65e55..e5561bebb22 100644 --- a/src/libcoretest/char.rs +++ b/src/libcoretest/char.rs @@ -121,31 +121,31 @@ fn test_escape_default() { return result; } let s = string('\n'); - assert_eq!(s.as_slice(), "\\n"); + assert_eq!(s, "\\n"); let s = string('\r'); - assert_eq!(s.as_slice(), "\\r"); + assert_eq!(s, "\\r"); let s = string('\''); - assert_eq!(s.as_slice(), "\\'"); + assert_eq!(s, "\\'"); let s = string('"'); - assert_eq!(s.as_slice(), "\\\""); + assert_eq!(s, "\\\""); let s = string(' '); - assert_eq!(s.as_slice(), " "); + assert_eq!(s, " "); let s = string('a'); - assert_eq!(s.as_slice(), "a"); + assert_eq!(s, "a"); let s = string('~'); - assert_eq!(s.as_slice(), "~"); + assert_eq!(s, "~"); let s = string('\x00'); - assert_eq!(s.as_slice(), "\\x00"); + assert_eq!(s, "\\x00"); let s = string('\x1f'); - assert_eq!(s.as_slice(), "\\x1f"); + assert_eq!(s, "\\x1f"); let s = string('\x7f'); - assert_eq!(s.as_slice(), "\\x7f"); + assert_eq!(s, "\\x7f"); let s = string('\u00ff'); - assert_eq!(s.as_slice(), "\\u00ff"); + assert_eq!(s, "\\u00ff"); let s = string('\u011b'); - assert_eq!(s.as_slice(), "\\u011b"); + assert_eq!(s, "\\u011b"); let s = string('\U0001d4b6'); - assert_eq!(s.as_slice(), "\\U0001d4b6"); + assert_eq!(s, "\\U0001d4b6"); } #[test] @@ -156,17 +156,17 @@ fn test_escape_unicode() { return result; } let s = string('\x00'); - assert_eq!(s.as_slice(), "\\x00"); + assert_eq!(s, "\\x00"); let s = string('\n'); - assert_eq!(s.as_slice(), "\\x0a"); + assert_eq!(s, "\\x0a"); let s = string(' '); - assert_eq!(s.as_slice(), "\\x20"); + assert_eq!(s, "\\x20"); let s = string('a'); - assert_eq!(s.as_slice(), "\\x61"); + assert_eq!(s, "\\x61"); let s = string('\u011b'); - assert_eq!(s.as_slice(), "\\u011b"); + assert_eq!(s, "\\u011b"); let s = string('\U0001d4b6'); - assert_eq!(s.as_slice(), "\\U0001d4b6"); + assert_eq!(s, "\\U0001d4b6"); } #[test] diff --git a/src/libcoretest/fmt/num.rs b/src/libcoretest/fmt/num.rs index 3b43d6ad33b..1e28933becd 100644 --- a/src/libcoretest/fmt/num.rs +++ b/src/libcoretest/fmt/num.rs @@ -16,136 +16,136 @@ fn test_format_int() { // Formatting integers should select the right implementation based off // the type of the argument. Also, hex/octal/binary should be defined // for integers, but they shouldn't emit the negative sign. - assert!(format!("{}", 1i).as_slice() == "1"); - assert!(format!("{}", 1i8).as_slice() == "1"); - assert!(format!("{}", 1i16).as_slice() == "1"); - assert!(format!("{}", 1i32).as_slice() == "1"); - assert!(format!("{}", 1i64).as_slice() == "1"); - assert!(format!("{}", -1i).as_slice() == "-1"); - assert!(format!("{}", -1i8).as_slice() == "-1"); - assert!(format!("{}", -1i16).as_slice() == "-1"); - assert!(format!("{}", -1i32).as_slice() == "-1"); - assert!(format!("{}", -1i64).as_slice() == "-1"); - assert!(format!("{:b}", 1i).as_slice() == "1"); - assert!(format!("{:b}", 1i8).as_slice() == "1"); - assert!(format!("{:b}", 1i16).as_slice() == "1"); - assert!(format!("{:b}", 1i32).as_slice() == "1"); - assert!(format!("{:b}", 1i64).as_slice() == "1"); - assert!(format!("{:x}", 1i).as_slice() == "1"); - assert!(format!("{:x}", 1i8).as_slice() == "1"); - assert!(format!("{:x}", 1i16).as_slice() == "1"); - assert!(format!("{:x}", 1i32).as_slice() == "1"); - assert!(format!("{:x}", 1i64).as_slice() == "1"); - assert!(format!("{:X}", 1i).as_slice() == "1"); - assert!(format!("{:X}", 1i8).as_slice() == "1"); - assert!(format!("{:X}", 1i16).as_slice() == "1"); - assert!(format!("{:X}", 1i32).as_slice() == "1"); - assert!(format!("{:X}", 1i64).as_slice() == "1"); - assert!(format!("{:o}", 1i).as_slice() == "1"); - assert!(format!("{:o}", 1i8).as_slice() == "1"); - assert!(format!("{:o}", 1i16).as_slice() == "1"); - assert!(format!("{:o}", 1i32).as_slice() == "1"); - assert!(format!("{:o}", 1i64).as_slice() == "1"); + assert!(format!("{}", 1i) == "1"); + assert!(format!("{}", 1i8) == "1"); + assert!(format!("{}", 1i16) == "1"); + assert!(format!("{}", 1i32) == "1"); + assert!(format!("{}", 1i64) == "1"); + assert!(format!("{}", -1i) == "-1"); + assert!(format!("{}", -1i8) == "-1"); + assert!(format!("{}", -1i16) == "-1"); + assert!(format!("{}", -1i32) == "-1"); + assert!(format!("{}", -1i64) == "-1"); + assert!(format!("{:b}", 1i) == "1"); + assert!(format!("{:b}", 1i8) == "1"); + assert!(format!("{:b}", 1i16) == "1"); + assert!(format!("{:b}", 1i32) == "1"); + assert!(format!("{:b}", 1i64) == "1"); + assert!(format!("{:x}", 1i) == "1"); + assert!(format!("{:x}", 1i8) == "1"); + assert!(format!("{:x}", 1i16) == "1"); + assert!(format!("{:x}", 1i32) == "1"); + assert!(format!("{:x}", 1i64) == "1"); + assert!(format!("{:X}", 1i) == "1"); + assert!(format!("{:X}", 1i8) == "1"); + assert!(format!("{:X}", 1i16) == "1"); + assert!(format!("{:X}", 1i32) == "1"); + assert!(format!("{:X}", 1i64) == "1"); + assert!(format!("{:o}", 1i) == "1"); + assert!(format!("{:o}", 1i8) == "1"); + assert!(format!("{:o}", 1i16) == "1"); + assert!(format!("{:o}", 1i32) == "1"); + assert!(format!("{:o}", 1i64) == "1"); - assert!(format!("{}", 1u).as_slice() == "1"); - assert!(format!("{}", 1u8).as_slice() == "1"); - assert!(format!("{}", 1u16).as_slice() == "1"); - assert!(format!("{}", 1u32).as_slice() == "1"); - assert!(format!("{}", 1u64).as_slice() == "1"); - assert!(format!("{:b}", 1u).as_slice() == "1"); - assert!(format!("{:b}", 1u8).as_slice() == "1"); - assert!(format!("{:b}", 1u16).as_slice() == "1"); - assert!(format!("{:b}", 1u32).as_slice() == "1"); - assert!(format!("{:b}", 1u64).as_slice() == "1"); - assert!(format!("{:x}", 1u).as_slice() == "1"); - assert!(format!("{:x}", 1u8).as_slice() == "1"); - assert!(format!("{:x}", 1u16).as_slice() == "1"); - assert!(format!("{:x}", 1u32).as_slice() == "1"); - assert!(format!("{:x}", 1u64).as_slice() == "1"); - assert!(format!("{:X}", 1u).as_slice() == "1"); - assert!(format!("{:X}", 1u8).as_slice() == "1"); - assert!(format!("{:X}", 1u16).as_slice() == "1"); - assert!(format!("{:X}", 1u32).as_slice() == "1"); - assert!(format!("{:X}", 1u64).as_slice() == "1"); - assert!(format!("{:o}", 1u).as_slice() == "1"); - assert!(format!("{:o}", 1u8).as_slice() == "1"); - assert!(format!("{:o}", 1u16).as_slice() == "1"); - assert!(format!("{:o}", 1u32).as_slice() == "1"); - assert!(format!("{:o}", 1u64).as_slice() == "1"); + assert!(format!("{}", 1u) == "1"); + assert!(format!("{}", 1u8) == "1"); + assert!(format!("{}", 1u16) == "1"); + assert!(format!("{}", 1u32) == "1"); + assert!(format!("{}", 1u64) == "1"); + assert!(format!("{:b}", 1u) == "1"); + assert!(format!("{:b}", 1u8) == "1"); + assert!(format!("{:b}", 1u16) == "1"); + assert!(format!("{:b}", 1u32) == "1"); + assert!(format!("{:b}", 1u64) == "1"); + assert!(format!("{:x}", 1u) == "1"); + assert!(format!("{:x}", 1u8) == "1"); + assert!(format!("{:x}", 1u16) == "1"); + assert!(format!("{:x}", 1u32) == "1"); + assert!(format!("{:x}", 1u64) == "1"); + assert!(format!("{:X}", 1u) == "1"); + assert!(format!("{:X}", 1u8) == "1"); + assert!(format!("{:X}", 1u16) == "1"); + assert!(format!("{:X}", 1u32) == "1"); + assert!(format!("{:X}", 1u64) == "1"); + assert!(format!("{:o}", 1u) == "1"); + assert!(format!("{:o}", 1u8) == "1"); + assert!(format!("{:o}", 1u16) == "1"); + assert!(format!("{:o}", 1u32) == "1"); + assert!(format!("{:o}", 1u64) == "1"); // Test a larger number - assert!(format!("{:b}", 55i).as_slice() == "110111"); - assert!(format!("{:o}", 55i).as_slice() == "67"); - assert!(format!("{}", 55i).as_slice() == "55"); - assert!(format!("{:x}", 55i).as_slice() == "37"); - assert!(format!("{:X}", 55i).as_slice() == "37"); + assert!(format!("{:b}", 55i) == "110111"); + assert!(format!("{:o}", 55i) == "67"); + assert!(format!("{}", 55i) == "55"); + assert!(format!("{:x}", 55i) == "37"); + assert!(format!("{:X}", 55i) == "37"); } #[test] fn test_format_int_zero() { - assert!(format!("{}", 0i).as_slice() == "0"); - assert!(format!("{:b}", 0i).as_slice() == "0"); - assert!(format!("{:o}", 0i).as_slice() == "0"); - assert!(format!("{:x}", 0i).as_slice() == "0"); - assert!(format!("{:X}", 0i).as_slice() == "0"); + assert!(format!("{}", 0i) == "0"); + assert!(format!("{:b}", 0i) == "0"); + assert!(format!("{:o}", 0i) == "0"); + assert!(format!("{:x}", 0i) == "0"); + assert!(format!("{:X}", 0i) == "0"); - assert!(format!("{}", 0u).as_slice() == "0"); - assert!(format!("{:b}", 0u).as_slice() == "0"); - assert!(format!("{:o}", 0u).as_slice() == "0"); - assert!(format!("{:x}", 0u).as_slice() == "0"); - assert!(format!("{:X}", 0u).as_slice() == "0"); + assert!(format!("{}", 0u) == "0"); + assert!(format!("{:b}", 0u) == "0"); + assert!(format!("{:o}", 0u) == "0"); + assert!(format!("{:x}", 0u) == "0"); + assert!(format!("{:X}", 0u) == "0"); } #[test] fn test_format_int_flags() { - assert!(format!("{:3}", 1i).as_slice() == " 1"); - assert!(format!("{:>3}", 1i).as_slice() == " 1"); - assert!(format!("{:>+3}", 1i).as_slice() == " +1"); - assert!(format!("{:<3}", 1i).as_slice() == "1 "); - assert!(format!("{:#}", 1i).as_slice() == "1"); - assert!(format!("{:#x}", 10i).as_slice() == "0xa"); - assert!(format!("{:#X}", 10i).as_slice() == "0xA"); - assert!(format!("{:#5x}", 10i).as_slice() == " 0xa"); - assert!(format!("{:#o}", 10i).as_slice() == "0o12"); - assert!(format!("{:08x}", 10i).as_slice() == "0000000a"); - assert!(format!("{:8x}", 10i).as_slice() == " a"); - assert!(format!("{:<8x}", 10i).as_slice() == "a "); - assert!(format!("{:>8x}", 10i).as_slice() == " a"); - assert!(format!("{:#08x}", 10i).as_slice() == "0x00000a"); - assert!(format!("{:08}", -10i).as_slice() == "-0000010"); - assert!(format!("{:x}", -1u8).as_slice() == "ff"); - assert!(format!("{:X}", -1u8).as_slice() == "FF"); - assert!(format!("{:b}", -1u8).as_slice() == "11111111"); - assert!(format!("{:o}", -1u8).as_slice() == "377"); - assert!(format!("{:#x}", -1u8).as_slice() == "0xff"); - assert!(format!("{:#X}", -1u8).as_slice() == "0xFF"); - assert!(format!("{:#b}", -1u8).as_slice() == "0b11111111"); - assert!(format!("{:#o}", -1u8).as_slice() == "0o377"); + assert!(format!("{:3}", 1i) == " 1"); + assert!(format!("{:>3}", 1i) == " 1"); + assert!(format!("{:>+3}", 1i) == " +1"); + assert!(format!("{:<3}", 1i) == "1 "); + assert!(format!("{:#}", 1i) == "1"); + assert!(format!("{:#x}", 10i) == "0xa"); + assert!(format!("{:#X}", 10i) == "0xA"); + assert!(format!("{:#5x}", 10i) == " 0xa"); + assert!(format!("{:#o}", 10i) == "0o12"); + assert!(format!("{:08x}", 10i) == "0000000a"); + assert!(format!("{:8x}", 10i) == " a"); + assert!(format!("{:<8x}", 10i) == "a "); + assert!(format!("{:>8x}", 10i) == " a"); + assert!(format!("{:#08x}", 10i) == "0x00000a"); + assert!(format!("{:08}", -10i) == "-0000010"); + assert!(format!("{:x}", -1u8) == "ff"); + assert!(format!("{:X}", -1u8) == "FF"); + assert!(format!("{:b}", -1u8) == "11111111"); + assert!(format!("{:o}", -1u8) == "377"); + assert!(format!("{:#x}", -1u8) == "0xff"); + assert!(format!("{:#X}", -1u8) == "0xFF"); + assert!(format!("{:#b}", -1u8) == "0b11111111"); + assert!(format!("{:#o}", -1u8) == "0o377"); } #[test] fn test_format_int_sign_padding() { - assert!(format!("{:+5}", 1i).as_slice() == " +1"); - assert!(format!("{:+5}", -1i).as_slice() == " -1"); - assert!(format!("{:05}", 1i).as_slice() == "00001"); - assert!(format!("{:05}", -1i).as_slice() == "-0001"); - assert!(format!("{:+05}", 1i).as_slice() == "+0001"); - assert!(format!("{:+05}", -1i).as_slice() == "-0001"); + assert!(format!("{:+5}", 1i) == " +1"); + assert!(format!("{:+5}", -1i) == " -1"); + assert!(format!("{:05}", 1i) == "00001"); + assert!(format!("{:05}", -1i) == "-0001"); + assert!(format!("{:+05}", 1i) == "+0001"); + assert!(format!("{:+05}", -1i) == "-0001"); } #[test] fn test_format_int_twos_complement() { use core::{i8, i16, i32, i64}; - assert!(format!("{}", i8::MIN).as_slice() == "-128"); - assert!(format!("{}", i16::MIN).as_slice() == "-32768"); - assert!(format!("{}", i32::MIN).as_slice() == "-2147483648"); - assert!(format!("{}", i64::MIN).as_slice() == "-9223372036854775808"); + assert!(format!("{}", i8::MIN) == "-128"); + assert!(format!("{}", i16::MIN) == "-32768"); + assert!(format!("{}", i32::MIN) == "-2147483648"); + assert!(format!("{}", i64::MIN) == "-9223372036854775808"); } #[test] fn test_format_radix() { - assert!(format!("{:04}", radix(3i, 2)).as_slice() == "0011"); - assert!(format!("{}", radix(55i, 36)).as_slice() == "1j"); + assert!(format!("{:04}", radix(3i, 2)) == "0011"); + assert!(format!("{}", radix(55i, 36)) == "1j"); } #[test] diff --git a/src/libcoretest/option.rs b/src/libcoretest/option.rs index a5927d47eb0..86fc25c9d91 100644 --- a/src/libcoretest/option.rs +++ b/src/libcoretest/option.rs @@ -28,10 +28,10 @@ fn test_get_ptr() { #[test] fn test_get_str() { let x = "test".to_string(); - let addr_x = x.as_slice().as_ptr(); + let addr_x = x.as_ptr(); let opt = Some(x); let y = opt.unwrap(); - let addr_y = y.as_slice().as_ptr(); + let addr_y = y.as_ptr(); assert_eq!(addr_x, addr_y); } @@ -135,7 +135,7 @@ fn test_or_else() { fn test_unwrap() { assert_eq!(Some(1i).unwrap(), 1); let s = Some("hello".to_string()).unwrap(); - assert_eq!(s.as_slice(), "hello"); + assert_eq!(s, "hello"); } #[test] @@ -266,4 +266,4 @@ fn test_cloned() { assert_eq!(opt_ref_ref.clone(), Some(&val1_ref)); assert_eq!(opt_ref_ref.clone().cloned(), Some(&val1)); assert_eq!(opt_ref_ref.cloned().cloned(), Some(1u32)); -} \ No newline at end of file +} diff --git a/src/libcoretest/result.rs b/src/libcoretest/result.rs index 92124e2f299..415cd4e7dcf 100644 --- a/src/libcoretest/result.rs +++ b/src/libcoretest/result.rs @@ -93,9 +93,9 @@ pub fn test_fmt_default() { let err: Result = Err("Err"); let s = format!("{}", ok); - assert_eq!(s.as_slice(), "Ok(100)"); + assert_eq!(s, "Ok(100)"); let s = format!("{}", err); - assert_eq!(s.as_slice(), "Err(Err)"); + assert_eq!(s, "Err(Err)"); } #[test] diff --git a/src/libcoretest/tuple.rs b/src/libcoretest/tuple.rs index be71e42ae9a..c53d82de23c 100644 --- a/src/libcoretest/tuple.rs +++ b/src/libcoretest/tuple.rs @@ -84,9 +84,9 @@ fn test_tuple_cmp() { #[test] fn test_show() { let s = format!("{}", (1i,)); - assert_eq!(s.as_slice(), "(1,)"); + assert_eq!(s, "(1,)"); let s = format!("{}", (1i, true)); - assert_eq!(s.as_slice(), "(1, true)"); + assert_eq!(s, "(1, true)"); let s = format!("{}", (1i, "hi", true)); - assert_eq!(s.as_slice(), "(1, hi, true)"); + assert_eq!(s, "(1, hi, true)"); }