summary refs log tree commit diff
path: root/src/libcore/num
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2013-04-16 01:08:52 +1000
committerHuon Wilson <dbau.pp+github@gmail.com>2013-04-16 09:57:47 +1000
commitd3be98e9f5e721b53dccd0a43c2ff58ddd32ac47 (patch)
tree2c1730e5ca7b3352854e92b51a7d0b44e5984438 /src/libcore/num
parentf10cf26e25c75e148d86dd151a210d9f4a7ece2f (diff)
downloadrust-d3be98e9f5e721b53dccd0a43c2ff58ddd32ac47.tar.gz
rust-d3be98e9f5e721b53dccd0a43c2ff58ddd32ac47.zip
libcore,std,syntax,rustc: move tests into `mod tests`, make them private (no pub mod or pub fn).
Diffstat (limited to 'src/libcore/num')
-rw-r--r--src/libcore/num/float.rs395
-rw-r--r--src/libcore/num/int-template.rs317
-rw-r--r--src/libcore/num/uint-template.rs316
3 files changed, 522 insertions, 506 deletions
diff --git a/src/libcore/num/float.rs b/src/libcore/num/float.rs
index 87d04b05087..488756787b5 100644
--- a/src/libcore/num/float.rs
+++ b/src/libcore/num/float.rs
@@ -29,7 +29,6 @@ use from_str;
 
 #[cfg(notest)] use cmp::{Eq, Ord};
 #[cfg(notest)] use ops;
-#[cfg(test)] use option::{Some, None};
 
 pub use f64::{add, sub, mul, div, rem, lt, le, eq, ne, ge, gt};
 pub use f64::logarithm;
@@ -142,7 +141,7 @@ pub fn to_str_radix(num: float, radix: uint) -> ~str {
     let (r, special) = strconv::to_str_common(
         &num, radix, true, strconv::SignNeg, strconv::DigAll);
     if special { fail!(~"number has a special value, \
-                      try to_str_radix_special() if those are expected") }
+                         try to_str_radix_special() if those are expected") }
     r
 }
 
@@ -177,12 +176,6 @@ pub fn to_str_exact(num: float, digits: uint) -> ~str {
     r
 }
 
-#[test]
-pub fn test_to_str_exact_do_decimal() {
-    let s = to_str_exact(5.0, 4u);
-    assert!(s == ~"5.0000");
-}
-
 /**
  * Converts a float to a string with a maximum number of
  * significant digits
@@ -474,195 +467,205 @@ impl ops::Neg<float> for float {
     fn neg(&self) -> float { -*self }
 }
 
-#[test]
-pub fn test_from_str() {
-   assert!(from_str(~"3") == Some(3.));
-   assert!(from_str(~"3.14") == Some(3.14));
-   assert!(from_str(~"+3.14") == Some(3.14));
-   assert!(from_str(~"-3.14") == Some(-3.14));
-   assert!(from_str(~"2.5E10") == Some(25000000000.));
-   assert!(from_str(~"2.5e10") == Some(25000000000.));
-   assert!(from_str(~"25000000000.E-10") == Some(2.5));
-   assert!(from_str(~".") == Some(0.));
-   assert!(from_str(~".e1") == Some(0.));
-   assert!(from_str(~".e-1") == Some(0.));
-   assert!(from_str(~"5.") == Some(5.));
-   assert!(from_str(~".5") == Some(0.5));
-   assert!(from_str(~"0.5") == Some(0.5));
-   assert!(from_str(~"-.5") == Some(-0.5));
-   assert!(from_str(~"-5") == Some(-5.));
-   assert!(from_str(~"inf") == Some(infinity));
-   assert!(from_str(~"+inf") == Some(infinity));
-   assert!(from_str(~"-inf") == Some(neg_infinity));
-   // note: NaN != NaN, hence this slightly complex test
-   match from_str(~"NaN") {
-       Some(f) => assert!(is_NaN(f)),
-       None => fail!()
-   }
-   // note: -0 == 0, hence these slightly more complex tests
-   match from_str(~"-0") {
-       Some(v) if is_zero(v) => assert!(is_negative(v)),
-       _ => fail!()
-   }
-   match from_str(~"0") {
-       Some(v) if is_zero(v) => assert!(is_positive(v)),
-       _ => fail!()
-   }
-
-   assert!(from_str(~"").is_none());
-   assert!(from_str(~"x").is_none());
-   assert!(from_str(~" ").is_none());
-   assert!(from_str(~"   ").is_none());
-   assert!(from_str(~"e").is_none());
-   assert!(from_str(~"E").is_none());
-   assert!(from_str(~"E1").is_none());
-   assert!(from_str(~"1e1e1").is_none());
-   assert!(from_str(~"1e1.1").is_none());
-   assert!(from_str(~"1e1-1").is_none());
-}
-
-#[test]
-pub fn test_from_str_hex() {
-   assert!(from_str_hex(~"a4") == Some(164.));
-   assert!(from_str_hex(~"a4.fe") == Some(164.9921875));
-   assert!(from_str_hex(~"-a4.fe") == Some(-164.9921875));
-   assert!(from_str_hex(~"+a4.fe") == Some(164.9921875));
-   assert!(from_str_hex(~"ff0P4") == Some(0xff00 as float));
-   assert!(from_str_hex(~"ff0p4") == Some(0xff00 as float));
-   assert!(from_str_hex(~"ff0p-4") == Some(0xff as float));
-   assert!(from_str_hex(~".") == Some(0.));
-   assert!(from_str_hex(~".p1") == Some(0.));
-   assert!(from_str_hex(~".p-1") == Some(0.));
-   assert!(from_str_hex(~"f.") == Some(15.));
-   assert!(from_str_hex(~".f") == Some(0.9375));
-   assert!(from_str_hex(~"0.f") == Some(0.9375));
-   assert!(from_str_hex(~"-.f") == Some(-0.9375));
-   assert!(from_str_hex(~"-f") == Some(-15.));
-   assert!(from_str_hex(~"inf") == Some(infinity));
-   assert!(from_str_hex(~"+inf") == Some(infinity));
-   assert!(from_str_hex(~"-inf") == Some(neg_infinity));
-   // note: NaN != NaN, hence this slightly complex test
-   match from_str_hex(~"NaN") {
-       Some(f) => assert!(is_NaN(f)),
-       None => fail!()
-   }
-   // note: -0 == 0, hence these slightly more complex tests
-   match from_str_hex(~"-0") {
-       Some(v) if is_zero(v) => assert!(is_negative(v)),
-       _ => fail!()
-   }
-   match from_str_hex(~"0") {
-       Some(v) if is_zero(v) => assert!(is_positive(v)),
-       _ => fail!()
-   }
-   assert!(from_str_hex(~"e") == Some(14.));
-   assert!(from_str_hex(~"E") == Some(14.));
-   assert!(from_str_hex(~"E1") == Some(225.));
-   assert!(from_str_hex(~"1e1e1") == Some(123361.));
-   assert!(from_str_hex(~"1e1.1") == Some(481.0625));
-
-   assert!(from_str_hex(~"").is_none());
-   assert!(from_str_hex(~"x").is_none());
-   assert!(from_str_hex(~" ").is_none());
-   assert!(from_str_hex(~"   ").is_none());
-   assert!(from_str_hex(~"p").is_none());
-   assert!(from_str_hex(~"P").is_none());
-   assert!(from_str_hex(~"P1").is_none());
-   assert!(from_str_hex(~"1p1p1").is_none());
-   assert!(from_str_hex(~"1p1.1").is_none());
-   assert!(from_str_hex(~"1p1-1").is_none());
-}
-
-#[test]
-pub fn test_to_str_hex() {
-   assert!(to_str_hex(164.) == ~"a4");
-   assert!(to_str_hex(164.9921875) == ~"a4.fe");
-   assert!(to_str_hex(-164.9921875) == ~"-a4.fe");
-   assert!(to_str_hex(0xff00 as float) == ~"ff00");
-   assert!(to_str_hex(-(0xff00 as float)) == ~"-ff00");
-   assert!(to_str_hex(0.) == ~"0");
-   assert!(to_str_hex(15.) == ~"f");
-   assert!(to_str_hex(-15.) == ~"-f");
-   assert!(to_str_hex(0.9375) == ~"0.f");
-   assert!(to_str_hex(-0.9375) == ~"-0.f");
-   assert!(to_str_hex(infinity) == ~"inf");
-   assert!(to_str_hex(neg_infinity) == ~"-inf");
-   assert!(to_str_hex(NaN) == ~"NaN");
-   assert!(to_str_hex(0.) == ~"0");
-   assert!(to_str_hex(-0.) == ~"-0");
-}
-
-#[test]
-pub fn test_to_str_radix() {
-   assert!(to_str_radix(36., 36u) == ~"10");
-   assert!(to_str_radix(8.125, 2u) == ~"1000.001");
-}
-
-#[test]
-pub fn test_from_str_radix() {
-   assert!(from_str_radix(~"10", 36u) == Some(36.));
-   assert!(from_str_radix(~"1000.001", 2u) == Some(8.125));
-}
-
-#[test]
-pub fn test_positive() {
-  assert!((is_positive(infinity)));
-  assert!((is_positive(1.)));
-  assert!((is_positive(0.)));
-  assert!((!is_positive(-1.)));
-  assert!((!is_positive(neg_infinity)));
-  assert!((!is_positive(1./neg_infinity)));
-  assert!((!is_positive(NaN)));
-}
-
-#[test]
-pub fn test_negative() {
-  assert!((!is_negative(infinity)));
-  assert!((!is_negative(1.)));
-  assert!((!is_negative(0.)));
-  assert!((is_negative(-1.)));
-  assert!((is_negative(neg_infinity)));
-  assert!((is_negative(1./neg_infinity)));
-  assert!((!is_negative(NaN)));
-}
-
-#[test]
-pub fn test_nonpositive() {
-  assert!((!is_nonpositive(infinity)));
-  assert!((!is_nonpositive(1.)));
-  assert!((!is_nonpositive(0.)));
-  assert!((is_nonpositive(-1.)));
-  assert!((is_nonpositive(neg_infinity)));
-  assert!((is_nonpositive(1./neg_infinity)));
-  assert!((!is_nonpositive(NaN)));
-}
-
-#[test]
-pub fn test_nonnegative() {
-  assert!((is_nonnegative(infinity)));
-  assert!((is_nonnegative(1.)));
-  assert!((is_nonnegative(0.)));
-  assert!((!is_nonnegative(-1.)));
-  assert!((!is_nonnegative(neg_infinity)));
-  assert!((!is_nonnegative(1./neg_infinity)));
-  assert!((!is_nonnegative(NaN)));
-}
-
-#[test]
-pub fn test_to_str_inf() {
-    assert!(to_str_digits(infinity, 10u) == ~"inf");
-    assert!(to_str_digits(-infinity, 10u) == ~"-inf");
-}
-
-#[test]
-pub fn test_round() {
-    assert!(round(5.8) == 6.0);
-    assert!(round(5.2) == 5.0);
-    assert!(round(3.0) == 3.0);
-    assert!(round(2.5) == 3.0);
-    assert!(round(-3.5) == -4.0);
-}
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use prelude::*;
+    #[test]
+    pub fn test_to_str_exact_do_decimal() {
+        let s = to_str_exact(5.0, 4u);
+        assert!(s == ~"5.0000");
+    }
+
+    #[test]
+    pub fn test_from_str() {
+        assert!(from_str(~"3") == Some(3.));
+        assert!(from_str(~"3.14") == Some(3.14));
+        assert!(from_str(~"+3.14") == Some(3.14));
+        assert!(from_str(~"-3.14") == Some(-3.14));
+        assert!(from_str(~"2.5E10") == Some(25000000000.));
+        assert!(from_str(~"2.5e10") == Some(25000000000.));
+        assert!(from_str(~"25000000000.E-10") == Some(2.5));
+        assert!(from_str(~".") == Some(0.));
+        assert!(from_str(~".e1") == Some(0.));
+        assert!(from_str(~".e-1") == Some(0.));
+        assert!(from_str(~"5.") == Some(5.));
+        assert!(from_str(~".5") == Some(0.5));
+        assert!(from_str(~"0.5") == Some(0.5));
+        assert!(from_str(~"-.5") == Some(-0.5));
+        assert!(from_str(~"-5") == Some(-5.));
+        assert!(from_str(~"inf") == Some(infinity));
+        assert!(from_str(~"+inf") == Some(infinity));
+        assert!(from_str(~"-inf") == Some(neg_infinity));
+        // note: NaN != NaN, hence this slightly complex test
+        match from_str(~"NaN") {
+            Some(f) => assert!(is_NaN(f)),
+            None => fail!()
+        }
+        // note: -0 == 0, hence these slightly more complex tests
+        match from_str(~"-0") {
+            Some(v) if is_zero(v) => assert!(is_negative(v)),
+            _ => fail!()
+        }
+        match from_str(~"0") {
+            Some(v) if is_zero(v) => assert!(is_positive(v)),
+            _ => fail!()
+        }
+
+        assert!(from_str(~"").is_none());
+        assert!(from_str(~"x").is_none());
+        assert!(from_str(~" ").is_none());
+        assert!(from_str(~"   ").is_none());
+        assert!(from_str(~"e").is_none());
+        assert!(from_str(~"E").is_none());
+        assert!(from_str(~"E1").is_none());
+        assert!(from_str(~"1e1e1").is_none());
+        assert!(from_str(~"1e1.1").is_none());
+        assert!(from_str(~"1e1-1").is_none());
+    }
+
+    #[test]
+    pub fn test_from_str_hex() {
+        assert!(from_str_hex(~"a4") == Some(164.));
+        assert!(from_str_hex(~"a4.fe") == Some(164.9921875));
+        assert!(from_str_hex(~"-a4.fe") == Some(-164.9921875));
+        assert!(from_str_hex(~"+a4.fe") == Some(164.9921875));
+        assert!(from_str_hex(~"ff0P4") == Some(0xff00 as float));
+        assert!(from_str_hex(~"ff0p4") == Some(0xff00 as float));
+        assert!(from_str_hex(~"ff0p-4") == Some(0xff as float));
+        assert!(from_str_hex(~".") == Some(0.));
+        assert!(from_str_hex(~".p1") == Some(0.));
+        assert!(from_str_hex(~".p-1") == Some(0.));
+        assert!(from_str_hex(~"f.") == Some(15.));
+        assert!(from_str_hex(~".f") == Some(0.9375));
+        assert!(from_str_hex(~"0.f") == Some(0.9375));
+        assert!(from_str_hex(~"-.f") == Some(-0.9375));
+        assert!(from_str_hex(~"-f") == Some(-15.));
+        assert!(from_str_hex(~"inf") == Some(infinity));
+        assert!(from_str_hex(~"+inf") == Some(infinity));
+        assert!(from_str_hex(~"-inf") == Some(neg_infinity));
+        // note: NaN != NaN, hence this slightly complex test
+        match from_str_hex(~"NaN") {
+            Some(f) => assert!(is_NaN(f)),
+            None => fail!()
+        }
+        // note: -0 == 0, hence these slightly more complex tests
+        match from_str_hex(~"-0") {
+            Some(v) if is_zero(v) => assert!(is_negative(v)),
+            _ => fail!()
+        }
+        match from_str_hex(~"0") {
+            Some(v) if is_zero(v) => assert!(is_positive(v)),
+            _ => fail!()
+        }
+        assert!(from_str_hex(~"e") == Some(14.));
+        assert!(from_str_hex(~"E") == Some(14.));
+        assert!(from_str_hex(~"E1") == Some(225.));
+        assert!(from_str_hex(~"1e1e1") == Some(123361.));
+        assert!(from_str_hex(~"1e1.1") == Some(481.0625));
+
+        assert!(from_str_hex(~"").is_none());
+        assert!(from_str_hex(~"x").is_none());
+        assert!(from_str_hex(~" ").is_none());
+        assert!(from_str_hex(~"   ").is_none());
+        assert!(from_str_hex(~"p").is_none());
+        assert!(from_str_hex(~"P").is_none());
+        assert!(from_str_hex(~"P1").is_none());
+        assert!(from_str_hex(~"1p1p1").is_none());
+        assert!(from_str_hex(~"1p1.1").is_none());
+        assert!(from_str_hex(~"1p1-1").is_none());
+    }
+
+    #[test]
+    pub fn test_to_str_hex() {
+        assert!(to_str_hex(164.) == ~"a4");
+        assert!(to_str_hex(164.9921875) == ~"a4.fe");
+        assert!(to_str_hex(-164.9921875) == ~"-a4.fe");
+        assert!(to_str_hex(0xff00 as float) == ~"ff00");
+        assert!(to_str_hex(-(0xff00 as float)) == ~"-ff00");
+        assert!(to_str_hex(0.) == ~"0");
+        assert!(to_str_hex(15.) == ~"f");
+        assert!(to_str_hex(-15.) == ~"-f");
+        assert!(to_str_hex(0.9375) == ~"0.f");
+        assert!(to_str_hex(-0.9375) == ~"-0.f");
+        assert!(to_str_hex(infinity) == ~"inf");
+        assert!(to_str_hex(neg_infinity) == ~"-inf");
+        assert!(to_str_hex(NaN) == ~"NaN");
+        assert!(to_str_hex(0.) == ~"0");
+        assert!(to_str_hex(-0.) == ~"-0");
+    }
 
+    #[test]
+    pub fn test_to_str_radix() {
+        assert!(to_str_radix(36., 36u) == ~"10");
+        assert!(to_str_radix(8.125, 2u) == ~"1000.001");
+    }
+
+    #[test]
+    pub fn test_from_str_radix() {
+        assert!(from_str_radix(~"10", 36u) == Some(36.));
+        assert!(from_str_radix(~"1000.001", 2u) == Some(8.125));
+    }
+
+    #[test]
+    pub fn test_positive() {
+        assert!((is_positive(infinity)));
+        assert!((is_positive(1.)));
+        assert!((is_positive(0.)));
+        assert!((!is_positive(-1.)));
+        assert!((!is_positive(neg_infinity)));
+        assert!((!is_positive(1./neg_infinity)));
+        assert!((!is_positive(NaN)));
+    }
+
+    #[test]
+    pub fn test_negative() {
+        assert!((!is_negative(infinity)));
+        assert!((!is_negative(1.)));
+        assert!((!is_negative(0.)));
+        assert!((is_negative(-1.)));
+        assert!((is_negative(neg_infinity)));
+        assert!((is_negative(1./neg_infinity)));
+        assert!((!is_negative(NaN)));
+    }
+
+    #[test]
+    pub fn test_nonpositive() {
+        assert!((!is_nonpositive(infinity)));
+        assert!((!is_nonpositive(1.)));
+        assert!((!is_nonpositive(0.)));
+        assert!((is_nonpositive(-1.)));
+        assert!((is_nonpositive(neg_infinity)));
+        assert!((is_nonpositive(1./neg_infinity)));
+        assert!((!is_nonpositive(NaN)));
+    }
+
+    #[test]
+    pub fn test_nonnegative() {
+        assert!((is_nonnegative(infinity)));
+        assert!((is_nonnegative(1.)));
+        assert!((is_nonnegative(0.)));
+        assert!((!is_nonnegative(-1.)));
+        assert!((!is_nonnegative(neg_infinity)));
+        assert!((!is_nonnegative(1./neg_infinity)));
+        assert!((!is_nonnegative(NaN)));
+    }
+
+    #[test]
+    pub fn test_to_str_inf() {
+        assert!(to_str_digits(infinity, 10u) == ~"inf");
+        assert!(to_str_digits(-infinity, 10u) == ~"-inf");
+    }
+
+    #[test]
+    pub fn test_round() {
+        assert!(round(5.8) == 6.0);
+        assert!(round(5.2) == 5.0);
+        assert!(round(3.0) == 3.0);
+        assert!(round(2.5) == 3.0);
+        assert!(round(-3.5) == -4.0);
+    }
+}
 
 //
 // Local Variables:
diff --git a/src/libcore/num/int-template.rs b/src/libcore/num/int-template.rs
index 6fbe44737d1..b495f9e7088 100644
--- a/src/libcore/num/int-template.rs
+++ b/src/libcore/num/int-template.rs
@@ -277,181 +277,188 @@ impl ToStrRadix for T {
     }
 }
 
-#[test]
-fn test_from_str() {
-    assert!(from_str(~"0") == Some(0 as T));
-    assert!(from_str(~"3") == Some(3 as T));
-    assert!(from_str(~"10") == Some(10 as T));
-    assert!(i32::from_str(~"123456789") == Some(123456789 as i32));
-    assert!(from_str(~"00100") == Some(100 as T));
-
-    assert!(from_str(~"-1") == Some(-1 as T));
-    assert!(from_str(~"-3") == Some(-3 as T));
-    assert!(from_str(~"-10") == Some(-10 as T));
-    assert!(i32::from_str(~"-123456789") == Some(-123456789 as i32));
-    assert!(from_str(~"-00100") == Some(-100 as T));
-
-    assert!(from_str(~" ").is_none());
-    assert!(from_str(~"x").is_none());
-}
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use super::inst::T;
+    use prelude::*;
+
+    #[test]
+    fn test_from_str() {
+        assert!(from_str(~"0") == Some(0 as T));
+        assert!(from_str(~"3") == Some(3 as T));
+        assert!(from_str(~"10") == Some(10 as T));
+        assert!(i32::from_str(~"123456789") == Some(123456789 as i32));
+        assert!(from_str(~"00100") == Some(100 as T));
+
+        assert!(from_str(~"-1") == Some(-1 as T));
+        assert!(from_str(~"-3") == Some(-3 as T));
+        assert!(from_str(~"-10") == Some(-10 as T));
+        assert!(i32::from_str(~"-123456789") == Some(-123456789 as i32));
+        assert!(from_str(~"-00100") == Some(-100 as T));
+
+        assert!(from_str(~" ").is_none());
+        assert!(from_str(~"x").is_none());
+    }
 
-#[test]
-fn test_parse_bytes() {
-    use str::to_bytes;
-    assert!(parse_bytes(to_bytes(~"123"), 10u) == Some(123 as T));
-    assert!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9 as T));
-    assert!(parse_bytes(to_bytes(~"123"), 8u) == Some(83 as T));
-    assert!(i32::parse_bytes(to_bytes(~"123"), 16u) == Some(291 as i32));
-    assert!(i32::parse_bytes(to_bytes(~"ffff"), 16u) ==
-                 Some(65535 as i32));
-    assert!(i32::parse_bytes(to_bytes(~"FFFF"), 16u) ==
-                 Some(65535 as i32));
-    assert!(parse_bytes(to_bytes(~"z"), 36u) == Some(35 as T));
-    assert!(parse_bytes(to_bytes(~"Z"), 36u) == Some(35 as T));
-
-    assert!(parse_bytes(to_bytes(~"-123"), 10u) == Some(-123 as T));
-    assert!(parse_bytes(to_bytes(~"-1001"), 2u) == Some(-9 as T));
-    assert!(parse_bytes(to_bytes(~"-123"), 8u) == Some(-83 as T));
-    assert!(i32::parse_bytes(to_bytes(~"-123"), 16u) ==
-                 Some(-291 as i32));
-    assert!(i32::parse_bytes(to_bytes(~"-ffff"), 16u) ==
-                 Some(-65535 as i32));
-    assert!(i32::parse_bytes(to_bytes(~"-FFFF"), 16u) ==
-                 Some(-65535 as i32));
-    assert!(parse_bytes(to_bytes(~"-z"), 36u) == Some(-35 as T));
-    assert!(parse_bytes(to_bytes(~"-Z"), 36u) == Some(-35 as T));
-
-    assert!(parse_bytes(to_bytes(~"Z"), 35u).is_none());
-    assert!(parse_bytes(to_bytes(~"-9"), 2u).is_none());
-}
+    #[test]
+    fn test_parse_bytes() {
+        use str::to_bytes;
+        assert!(parse_bytes(to_bytes(~"123"), 10u) == Some(123 as T));
+        assert!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9 as T));
+        assert!(parse_bytes(to_bytes(~"123"), 8u) == Some(83 as T));
+        assert!(i32::parse_bytes(to_bytes(~"123"), 16u) == Some(291 as i32));
+        assert!(i32::parse_bytes(to_bytes(~"ffff"), 16u) ==
+                Some(65535 as i32));
+        assert!(i32::parse_bytes(to_bytes(~"FFFF"), 16u) ==
+                Some(65535 as i32));
+        assert!(parse_bytes(to_bytes(~"z"), 36u) == Some(35 as T));
+        assert!(parse_bytes(to_bytes(~"Z"), 36u) == Some(35 as T));
+
+        assert!(parse_bytes(to_bytes(~"-123"), 10u) == Some(-123 as T));
+        assert!(parse_bytes(to_bytes(~"-1001"), 2u) == Some(-9 as T));
+        assert!(parse_bytes(to_bytes(~"-123"), 8u) == Some(-83 as T));
+        assert!(i32::parse_bytes(to_bytes(~"-123"), 16u) ==
+                Some(-291 as i32));
+        assert!(i32::parse_bytes(to_bytes(~"-ffff"), 16u) ==
+                Some(-65535 as i32));
+        assert!(i32::parse_bytes(to_bytes(~"-FFFF"), 16u) ==
+                Some(-65535 as i32));
+        assert!(parse_bytes(to_bytes(~"-z"), 36u) == Some(-35 as T));
+        assert!(parse_bytes(to_bytes(~"-Z"), 36u) == Some(-35 as T));
+
+        assert!(parse_bytes(to_bytes(~"Z"), 35u).is_none());
+        assert!(parse_bytes(to_bytes(~"-9"), 2u).is_none());
+    }
 
-#[test]
-fn test_to_str() {
-    assert!((to_str_radix(0 as T, 10u) == ~"0"));
-    assert!((to_str_radix(1 as T, 10u) == ~"1"));
-    assert!((to_str_radix(-1 as T, 10u) == ~"-1"));
-    assert!((to_str_radix(127 as T, 16u) == ~"7f"));
-    assert!((to_str_radix(100 as T, 10u) == ~"100"));
+    #[test]
+    fn test_to_str() {
+        assert!((to_str_radix(0 as T, 10u) == ~"0"));
+        assert!((to_str_radix(1 as T, 10u) == ~"1"));
+        assert!((to_str_radix(-1 as T, 10u) == ~"-1"));
+        assert!((to_str_radix(127 as T, 16u) == ~"7f"));
+        assert!((to_str_radix(100 as T, 10u) == ~"100"));
 
-}
+    }
 
-#[test]
-fn test_int_to_str_overflow() {
-    let mut i8_val: i8 = 127_i8;
-    assert!((i8::to_str(i8_val) == ~"127"));
+    #[test]
+    fn test_int_to_str_overflow() {
+        let mut i8_val: i8 = 127_i8;
+        assert!((i8::to_str(i8_val) == ~"127"));
 
-    i8_val += 1 as i8;
-    assert!((i8::to_str(i8_val) == ~"-128"));
+        i8_val += 1 as i8;
+        assert!((i8::to_str(i8_val) == ~"-128"));
 
-    let mut i16_val: i16 = 32_767_i16;
-    assert!((i16::to_str(i16_val) == ~"32767"));
+        let mut i16_val: i16 = 32_767_i16;
+        assert!((i16::to_str(i16_val) == ~"32767"));
 
-    i16_val += 1 as i16;
-    assert!((i16::to_str(i16_val) == ~"-32768"));
+        i16_val += 1 as i16;
+        assert!((i16::to_str(i16_val) == ~"-32768"));
 
-    let mut i32_val: i32 = 2_147_483_647_i32;
-    assert!((i32::to_str(i32_val) == ~"2147483647"));
+        let mut i32_val: i32 = 2_147_483_647_i32;
+        assert!((i32::to_str(i32_val) == ~"2147483647"));
 
-    i32_val += 1 as i32;
-    assert!((i32::to_str(i32_val) == ~"-2147483648"));
+        i32_val += 1 as i32;
+        assert!((i32::to_str(i32_val) == ~"-2147483648"));
 
-    let mut i64_val: i64 = 9_223_372_036_854_775_807_i64;
-    assert!((i64::to_str(i64_val) == ~"9223372036854775807"));
+        let mut i64_val: i64 = 9_223_372_036_854_775_807_i64;
+        assert!((i64::to_str(i64_val) == ~"9223372036854775807"));
 
-    i64_val += 1 as i64;
-    assert!((i64::to_str(i64_val) == ~"-9223372036854775808"));
-}
+        i64_val += 1 as i64;
+        assert!((i64::to_str(i64_val) == ~"-9223372036854775808"));
+    }
 
-#[test]
-fn test_int_from_str_overflow() {
-    let mut i8_val: i8 = 127_i8;
-    assert!((i8::from_str(~"127") == Some(i8_val)));
-    assert!((i8::from_str(~"128").is_none()));
+    #[test]
+    fn test_int_from_str_overflow() {
+        let mut i8_val: i8 = 127_i8;
+        assert!((i8::from_str(~"127") == Some(i8_val)));
+        assert!((i8::from_str(~"128").is_none()));
 
-    i8_val += 1 as i8;
-    assert!((i8::from_str(~"-128") == Some(i8_val)));
-    assert!((i8::from_str(~"-129").is_none()));
+        i8_val += 1 as i8;
+        assert!((i8::from_str(~"-128") == Some(i8_val)));
+        assert!((i8::from_str(~"-129").is_none()));
 
-    let mut i16_val: i16 = 32_767_i16;
-    assert!((i16::from_str(~"32767") == Some(i16_val)));
-    assert!((i16::from_str(~"32768").is_none()));
+        let mut i16_val: i16 = 32_767_i16;
+        assert!((i16::from_str(~"32767") == Some(i16_val)));
+        assert!((i16::from_str(~"32768").is_none()));
 
-    i16_val += 1 as i16;
-    assert!((i16::from_str(~"-32768") == Some(i16_val)));
-    assert!((i16::from_str(~"-32769").is_none()));
+        i16_val += 1 as i16;
+        assert!((i16::from_str(~"-32768") == Some(i16_val)));
+        assert!((i16::from_str(~"-32769").is_none()));
 
-    let mut i32_val: i32 = 2_147_483_647_i32;
-    assert!((i32::from_str(~"2147483647") == Some(i32_val)));
-    assert!((i32::from_str(~"2147483648").is_none()));
+        let mut i32_val: i32 = 2_147_483_647_i32;
+        assert!((i32::from_str(~"2147483647") == Some(i32_val)));
+        assert!((i32::from_str(~"2147483648").is_none()));
 
-    i32_val += 1 as i32;
-    assert!((i32::from_str(~"-2147483648") == Some(i32_val)));
-    assert!((i32::from_str(~"-2147483649").is_none()));
+        i32_val += 1 as i32;
+        assert!((i32::from_str(~"-2147483648") == Some(i32_val)));
+        assert!((i32::from_str(~"-2147483649").is_none()));
 
-    let mut i64_val: i64 = 9_223_372_036_854_775_807_i64;
-    assert!((i64::from_str(~"9223372036854775807") == Some(i64_val)));
-    assert!((i64::from_str(~"9223372036854775808").is_none()));
+        let mut i64_val: i64 = 9_223_372_036_854_775_807_i64;
+        assert!((i64::from_str(~"9223372036854775807") == Some(i64_val)));
+        assert!((i64::from_str(~"9223372036854775808").is_none()));
 
-    i64_val += 1 as i64;
-    assert!((i64::from_str(~"-9223372036854775808") == Some(i64_val)));
-    assert!((i64::from_str(~"-9223372036854775809").is_none()));
-}
+        i64_val += 1 as i64;
+        assert!((i64::from_str(~"-9223372036854775808") == Some(i64_val)));
+        assert!((i64::from_str(~"-9223372036854775809").is_none()));
+    }
 
-#[test]
-pub fn test_ranges() {
-    let mut l = ~[];
+    #[test]
+    fn test_ranges() {
+        let mut l = ~[];
 
-    for range(0,3) |i| {
-        l.push(i);
-    }
-    for range_rev(13,10) |i| {
-        l.push(i);
-    }
-    for range_step(20,26,2) |i| {
-        l.push(i);
-    }
-    for range_step(36,30,-2) |i| {
-        l.push(i);
-    }
-    for range_step(max_value - 2, max_value, 2) |i| {
-        l.push(i);
-    }
-    for range_step(max_value - 3, max_value, 2) |i| {
-        l.push(i);
-    }
-    for range_step(min_value + 2, min_value, -2) |i| {
-        l.push(i);
-    }
-    for range_step(min_value + 3, min_value, -2) |i| {
-        l.push(i);
-    }
-    assert_eq!(l, ~[0,1,2,
-                    13,12,11,
-                    20,22,24,
-                    36,34,32,
-                    max_value-2,
-                    max_value-3,max_value-1,
-                    min_value+2,
-                    min_value+3,min_value+1]);
-
-    // None of the `fail`s should execute.
-    for range(10,0) |_i| {
-        fail!(~"unreachable");
-    }
-    for range_rev(0,10) |_i| {
-        fail!(~"unreachable");
-    }
-    for range_step(10,0,1) |_i| {
-        fail!(~"unreachable");
-    }
-    for range_step(0,10,-1) |_i| {
-        fail!(~"unreachable");
+        for range(0,3) |i| {
+            l.push(i);
+        }
+        for range_rev(13,10) |i| {
+            l.push(i);
+        }
+        for range_step(20,26,2) |i| {
+            l.push(i);
+        }
+        for range_step(36,30,-2) |i| {
+            l.push(i);
+        }
+        for range_step(max_value - 2, max_value, 2) |i| {
+            l.push(i);
+        }
+        for range_step(max_value - 3, max_value, 2) |i| {
+            l.push(i);
+        }
+        for range_step(min_value + 2, min_value, -2) |i| {
+            l.push(i);
+        }
+        for range_step(min_value + 3, min_value, -2) |i| {
+            l.push(i);
+        }
+        assert_eq!(l, ~[0,1,2,
+                        13,12,11,
+                        20,22,24,
+                        36,34,32,
+                        max_value-2,
+                        max_value-3,max_value-1,
+                        min_value+2,
+                        min_value+3,min_value+1]);
+
+        // None of the `fail`s should execute.
+        for range(10,0) |_i| {
+            fail!(~"unreachable");
+        }
+        for range_rev(0,10) |_i| {
+            fail!(~"unreachable");
+        }
+        for range_step(10,0,1) |_i| {
+            fail!(~"unreachable");
+        }
+        for range_step(0,10,-1) |_i| {
+            fail!(~"unreachable");
+        }
     }
-}
 
-#[test]
-#[should_fail]
-#[ignore(cfg(windows))]
-fn test_range_step_zero_step() {
-    for range_step(0,10,0) |_i| {}
-}
+    #[test]
+    #[should_fail]
+    #[ignore(cfg(windows))]
+    fn test_range_step_zero_step() {
+        for range_step(0,10,0) |_i| {}
+    }
+}
\ No newline at end of file
diff --git a/src/libcore/num/uint-template.rs b/src/libcore/num/uint-template.rs
index 1cbdabafdab..af6557e9881 100644
--- a/src/libcore/num/uint-template.rs
+++ b/src/libcore/num/uint-template.rs
@@ -242,184 +242,190 @@ impl ToStrRadix for T {
     }
 }
 
-#[test]
-pub fn test_to_str() {
-    assert!(to_str_radix(0 as T, 10u) == ~"0");
-    assert!(to_str_radix(1 as T, 10u) == ~"1");
-    assert!(to_str_radix(2 as T, 10u) == ~"2");
-    assert!(to_str_radix(11 as T, 10u) == ~"11");
-    assert!(to_str_radix(11 as T, 16u) == ~"b");
-    assert!(to_str_radix(255 as T, 16u) == ~"ff");
-    assert!(to_str_radix(0xff as T, 10u) == ~"255");
-}
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use super::inst::T;
+    use prelude::*;
+    #[test]
+    pub fn test_to_str() {
+        assert!(to_str_radix(0 as T, 10u) == ~"0");
+        assert!(to_str_radix(1 as T, 10u) == ~"1");
+        assert!(to_str_radix(2 as T, 10u) == ~"2");
+        assert!(to_str_radix(11 as T, 10u) == ~"11");
+        assert!(to_str_radix(11 as T, 16u) == ~"b");
+        assert!(to_str_radix(255 as T, 16u) == ~"ff");
+        assert!(to_str_radix(0xff as T, 10u) == ~"255");
+    }
 
-#[test]
-pub fn test_from_str() {
-    assert!(from_str(~"0") == Some(0u as T));
-    assert!(from_str(~"3") == Some(3u as T));
-    assert!(from_str(~"10") == Some(10u as T));
-    assert!(u32::from_str(~"123456789") == Some(123456789 as u32));
-    assert!(from_str(~"00100") == Some(100u as T));
-
-    assert!(from_str(~"").is_none());
-    assert!(from_str(~" ").is_none());
-    assert!(from_str(~"x").is_none());
-}
+    #[test]
+    pub fn test_from_str() {
+        assert!(from_str(~"0") == Some(0u as T));
+        assert!(from_str(~"3") == Some(3u as T));
+        assert!(from_str(~"10") == Some(10u as T));
+        assert!(u32::from_str(~"123456789") == Some(123456789 as u32));
+        assert!(from_str(~"00100") == Some(100u as T));
+
+        assert!(from_str(~"").is_none());
+        assert!(from_str(~" ").is_none());
+        assert!(from_str(~"x").is_none());
+    }
 
-#[test]
-pub fn test_parse_bytes() {
-    use str::to_bytes;
-    assert!(parse_bytes(to_bytes(~"123"), 10u) == Some(123u as T));
-    assert!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9u as T));
-    assert!(parse_bytes(to_bytes(~"123"), 8u) == Some(83u as T));
-    assert!(u16::parse_bytes(to_bytes(~"123"), 16u) ==
-                 Some(291u as u16));
-    assert!(u16::parse_bytes(to_bytes(~"ffff"), 16u) ==
-                 Some(65535u as u16));
-    assert!(parse_bytes(to_bytes(~"z"), 36u) == Some(35u as T));
-
-    assert!(parse_bytes(to_bytes(~"Z"), 10u).is_none());
-    assert!(parse_bytes(to_bytes(~"_"), 2u).is_none());
-}
+    #[test]
+    pub fn test_parse_bytes() {
+        use str::to_bytes;
+        assert!(parse_bytes(to_bytes(~"123"), 10u) == Some(123u as T));
+        assert!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9u as T));
+        assert!(parse_bytes(to_bytes(~"123"), 8u) == Some(83u as T));
+        assert!(u16::parse_bytes(to_bytes(~"123"), 16u) ==
+                Some(291u as u16));
+        assert!(u16::parse_bytes(to_bytes(~"ffff"), 16u) ==
+                Some(65535u as u16));
+        assert!(parse_bytes(to_bytes(~"z"), 36u) == Some(35u as T));
+
+        assert!(parse_bytes(to_bytes(~"Z"), 10u).is_none());
+        assert!(parse_bytes(to_bytes(~"_"), 2u).is_none());
+    }
 
-#[test]
-fn test_uint_to_str_overflow() {
-    let mut u8_val: u8 = 255_u8;
-    assert!((u8::to_str(u8_val) == ~"255"));
+    #[test]
+    fn test_uint_to_str_overflow() {
+        let mut u8_val: u8 = 255_u8;
+        assert!((u8::to_str(u8_val) == ~"255"));
 
-    u8_val += 1 as u8;
-    assert!((u8::to_str(u8_val) == ~"0"));
+        u8_val += 1 as u8;
+        assert!((u8::to_str(u8_val) == ~"0"));
 
-    let mut u16_val: u16 = 65_535_u16;
-    assert!((u16::to_str(u16_val) == ~"65535"));
+        let mut u16_val: u16 = 65_535_u16;
+        assert!((u16::to_str(u16_val) == ~"65535"));
 
-    u16_val += 1 as u16;
-    assert!((u16::to_str(u16_val) == ~"0"));
+        u16_val += 1 as u16;
+        assert!((u16::to_str(u16_val) == ~"0"));
 
-    let mut u32_val: u32 = 4_294_967_295_u32;
-    assert!((u32::to_str(u32_val) == ~"4294967295"));
+        let mut u32_val: u32 = 4_294_967_295_u32;
+        assert!((u32::to_str(u32_val) == ~"4294967295"));
 
-    u32_val += 1 as u32;
-    assert!((u32::to_str(u32_val) == ~"0"));
+        u32_val += 1 as u32;
+        assert!((u32::to_str(u32_val) == ~"0"));
 
-    let mut u64_val: u64 = 18_446_744_073_709_551_615_u64;
-    assert!((u64::to_str(u64_val) == ~"18446744073709551615"));
+        let mut u64_val: u64 = 18_446_744_073_709_551_615_u64;
+        assert!((u64::to_str(u64_val) == ~"18446744073709551615"));
 
-    u64_val += 1 as u64;
-    assert!((u64::to_str(u64_val) == ~"0"));
-}
+        u64_val += 1 as u64;
+        assert!((u64::to_str(u64_val) == ~"0"));
+    }
 
-#[test]
-fn test_uint_from_str_overflow() {
-    let mut u8_val: u8 = 255_u8;
-    assert!((u8::from_str(~"255") == Some(u8_val)));
-    assert!((u8::from_str(~"256").is_none()));
+    #[test]
+    fn test_uint_from_str_overflow() {
+        let mut u8_val: u8 = 255_u8;
+        assert!((u8::from_str(~"255") == Some(u8_val)));
+        assert!((u8::from_str(~"256").is_none()));
 
-    u8_val += 1 as u8;
-    assert!((u8::from_str(~"0") == Some(u8_val)));
-    assert!((u8::from_str(~"-1").is_none()));
+        u8_val += 1 as u8;
+        assert!((u8::from_str(~"0") == Some(u8_val)));
+        assert!((u8::from_str(~"-1").is_none()));
 
-    let mut u16_val: u16 = 65_535_u16;
-    assert!((u16::from_str(~"65535") == Some(u16_val)));
-    assert!((u16::from_str(~"65536").is_none()));
+        let mut u16_val: u16 = 65_535_u16;
+        assert!((u16::from_str(~"65535") == Some(u16_val)));
+        assert!((u16::from_str(~"65536").is_none()));
 
-    u16_val += 1 as u16;
-    assert!((u16::from_str(~"0") == Some(u16_val)));
-    assert!((u16::from_str(~"-1").is_none()));
+        u16_val += 1 as u16;
+        assert!((u16::from_str(~"0") == Some(u16_val)));
+        assert!((u16::from_str(~"-1").is_none()));
 
-    let mut u32_val: u32 = 4_294_967_295_u32;
-    assert!((u32::from_str(~"4294967295") == Some(u32_val)));
-    assert!((u32::from_str(~"4294967296").is_none()));
+        let mut u32_val: u32 = 4_294_967_295_u32;
+        assert!((u32::from_str(~"4294967295") == Some(u32_val)));
+        assert!((u32::from_str(~"4294967296").is_none()));
 
-    u32_val += 1 as u32;
-    assert!((u32::from_str(~"0") == Some(u32_val)));
-    assert!((u32::from_str(~"-1").is_none()));
+        u32_val += 1 as u32;
+        assert!((u32::from_str(~"0") == Some(u32_val)));
+        assert!((u32::from_str(~"-1").is_none()));
 
-    let mut u64_val: u64 = 18_446_744_073_709_551_615_u64;
-    assert!((u64::from_str(~"18446744073709551615") == Some(u64_val)));
-    assert!((u64::from_str(~"18446744073709551616").is_none()));
+        let mut u64_val: u64 = 18_446_744_073_709_551_615_u64;
+        assert!((u64::from_str(~"18446744073709551615") == Some(u64_val)));
+        assert!((u64::from_str(~"18446744073709551616").is_none()));
 
-    u64_val += 1 as u64;
-    assert!((u64::from_str(~"0") == Some(u64_val)));
-    assert!((u64::from_str(~"-1").is_none()));
-}
+        u64_val += 1 as u64;
+        assert!((u64::from_str(~"0") == Some(u64_val)));
+        assert!((u64::from_str(~"-1").is_none()));
+    }
 
-#[test]
-#[should_fail]
-#[ignore(cfg(windows))]
-pub fn to_str_radix1() {
-    uint::to_str_radix(100u, 1u);
-}
+    #[test]
+    #[should_fail]
+    #[ignore(cfg(windows))]
+    pub fn to_str_radix1() {
+        uint::to_str_radix(100u, 1u);
+    }
 
-#[test]
-#[should_fail]
-#[ignore(cfg(windows))]
-pub fn to_str_radix37() {
-    uint::to_str_radix(100u, 37u);
-}
+    #[test]
+    #[should_fail]
+    #[ignore(cfg(windows))]
+    pub fn to_str_radix37() {
+        uint::to_str_radix(100u, 37u);
+    }
 
-#[test]
-pub fn test_ranges() {
-    let mut l = ~[];
+    #[test]
+    pub fn test_ranges() {
+        let mut l = ~[];
 
-    for range(0,3) |i| {
-        l.push(i);
-    }
-    for range_rev(13,10) |i| {
-        l.push(i);
-    }
-    for range_step(20,26,2) |i| {
-        l.push(i);
-    }
-    for range_step(36,30,-2) |i| {
-        l.push(i);
-    }
-    for range_step(max_value - 2, max_value, 2) |i| {
-        l.push(i);
-    }
-    for range_step(max_value - 3, max_value, 2) |i| {
-        l.push(i);
-    }
-    for range_step(min_value + 2, min_value, -2) |i| {
-        l.push(i);
-    }
-    for range_step(min_value + 3, min_value, -2) |i| {
-        l.push(i);
-    }
+        for range(0,3) |i| {
+            l.push(i);
+        }
+        for range_rev(13,10) |i| {
+            l.push(i);
+        }
+        for range_step(20,26,2) |i| {
+            l.push(i);
+        }
+        for range_step(36,30,-2) |i| {
+            l.push(i);
+        }
+        for range_step(max_value - 2, max_value, 2) |i| {
+            l.push(i);
+        }
+        for range_step(max_value - 3, max_value, 2) |i| {
+            l.push(i);
+        }
+        for range_step(min_value + 2, min_value, -2) |i| {
+            l.push(i);
+        }
+        for range_step(min_value + 3, min_value, -2) |i| {
+            l.push(i);
+        }
 
-    assert_eq!(l, ~[0,1,2,
-                    13,12,11,
-                    20,22,24,
-                    36,34,32,
-                    max_value-2,
-                    max_value-3,max_value-1,
-                    min_value+2,
-                    min_value+3,min_value+1]);
-
-    // None of the `fail`s should execute.
-    for range(0,0) |_i| {
-        fail!(~"unreachable");
-    }
-    for range_rev(0,0) |_i| {
-        fail!(~"unreachable");
+        assert_eq!(l, ~[0,1,2,
+                        13,12,11,
+                        20,22,24,
+                        36,34,32,
+                        max_value-2,
+                        max_value-3,max_value-1,
+                        min_value+2,
+                        min_value+3,min_value+1]);
+
+        // None of the `fail`s should execute.
+        for range(0,0) |_i| {
+            fail!(~"unreachable");
+        }
+        for range_rev(0,0) |_i| {
+            fail!(~"unreachable");
+        }
+        for range_step(10,0,1) |_i| {
+            fail!(~"unreachable");
+        }
+        for range_step(0,1,-10) |_i| {
+            fail!(~"unreachable");
+        }
     }
-    for range_step(10,0,1) |_i| {
-        fail!(~"unreachable");
+
+    #[test]
+    #[should_fail]
+    #[ignore(cfg(windows))]
+    fn test_range_step_zero_step_up() {
+        for range_step(0,10,0) |_i| {}
     }
-    for range_step(0,1,-10) |_i| {
-        fail!(~"unreachable");
+    #[test]
+    #[should_fail]
+    #[ignore(cfg(windows))]
+    fn test_range_step_zero_step_down() {
+        for range_step(0,-10,0) |_i| {}
     }
-}
-
-#[test]
-#[should_fail]
-#[ignore(cfg(windows))]
-fn test_range_step_zero_step_up() {
-    for range_step(0,10,0) |_i| {}
-}
-#[test]
-#[should_fail]
-#[ignore(cfg(windows))]
-fn test_range_step_zero_step_down() {
-    for range_step(0,-10,0) |_i| {}
-}
+}
\ No newline at end of file