about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-05-01 10:24:21 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-05-07 08:16:14 -0700
commit4686cf201804c999fbc24fa3a3245e9c4dc4afe1 (patch)
tree80cc184be48d9b1468ff025081be9eb1c7c3bc32
parentc9447c5d955b7e575451002810a9c3d652022ff9 (diff)
downloadrust-4686cf201804c999fbc24fa3a3245e9c4dc4afe1.tar.gz
rust-4686cf201804c999fbc24fa3a3245e9c4dc4afe1.zip
core: Bring char/finally test style up to date
-rw-r--r--src/libcore/char.rs311
-rw-r--r--src/libcore/finally.rs87
2 files changed, 202 insertions, 196 deletions
diff --git a/src/libcore/char.rs b/src/libcore/char.rs
index 7a52af82403..9c00b6babc1 100644
--- a/src/libcore/char.rs
+++ b/src/libcore/char.rs
@@ -680,175 +680,178 @@ impl Default for char {
     fn default() -> char { '\x00' }
 }
 
-#[test]
-fn test_is_lowercase() {
-    assert!('a'.is_lowercase());
-    assert!('ö'.is_lowercase());
-    assert!('ß'.is_lowercase());
-    assert!(!'Ü'.is_lowercase());
-    assert!(!'P'.is_lowercase());
-}
-
-#[test]
-fn test_is_uppercase() {
-    assert!(!'h'.is_uppercase());
-    assert!(!'ä'.is_uppercase());
-    assert!(!'ß'.is_uppercase());
-    assert!('Ö'.is_uppercase());
-    assert!('T'.is_uppercase());
-}
+#[cfg(test)]
+mod test {
+    #[test]
+    fn test_is_lowercase() {
+        assert!('a'.is_lowercase());
+        assert!('ö'.is_lowercase());
+        assert!('ß'.is_lowercase());
+        assert!(!'Ü'.is_lowercase());
+        assert!(!'P'.is_lowercase());
+    }
 
-#[test]
-fn test_is_whitespace() {
-    assert!(' '.is_whitespace());
-    assert!('\u2007'.is_whitespace());
-    assert!('\t'.is_whitespace());
-    assert!('\n'.is_whitespace());
-    assert!(!'a'.is_whitespace());
-    assert!(!'_'.is_whitespace());
-    assert!(!'\u0000'.is_whitespace());
-}
+    #[test]
+    fn test_is_uppercase() {
+        assert!(!'h'.is_uppercase());
+        assert!(!'ä'.is_uppercase());
+        assert!(!'ß'.is_uppercase());
+        assert!('Ö'.is_uppercase());
+        assert!('T'.is_uppercase());
+    }
 
-#[test]
-fn test_to_digit() {
-    assert_eq!('0'.to_digit(10u), Some(0u));
-    assert_eq!('1'.to_digit(2u), Some(1u));
-    assert_eq!('2'.to_digit(3u), Some(2u));
-    assert_eq!('9'.to_digit(10u), Some(9u));
-    assert_eq!('a'.to_digit(16u), Some(10u));
-    assert_eq!('A'.to_digit(16u), Some(10u));
-    assert_eq!('b'.to_digit(16u), Some(11u));
-    assert_eq!('B'.to_digit(16u), Some(11u));
-    assert_eq!('z'.to_digit(36u), Some(35u));
-    assert_eq!('Z'.to_digit(36u), Some(35u));
-    assert_eq!(' '.to_digit(10u), None);
-    assert_eq!('$'.to_digit(36u), None);
-}
+    #[test]
+    fn test_is_whitespace() {
+        assert!(' '.is_whitespace());
+        assert!('\u2007'.is_whitespace());
+        assert!('\t'.is_whitespace());
+        assert!('\n'.is_whitespace());
+        assert!(!'a'.is_whitespace());
+        assert!(!'_'.is_whitespace());
+        assert!(!'\u0000'.is_whitespace());
+    }
 
-#[test]
-fn test_to_lowercase() {
-    assert_eq!('A'.to_lowercase(), 'a');
-    assert_eq!('Ö'.to_lowercase(), 'ö');
-    assert_eq!('ß'.to_lowercase(), 'ß');
-    assert_eq!('Ü'.to_lowercase(), 'ü');
-    assert_eq!('💩'.to_lowercase(), '💩');
-    assert_eq!('Σ'.to_lowercase(), 'σ');
-    assert_eq!('Τ'.to_lowercase(), 'τ');
-    assert_eq!('Ι'.to_lowercase(), 'ι');
-    assert_eq!('Γ'.to_lowercase(), 'γ');
-    assert_eq!('Μ'.to_lowercase(), 'μ');
-    assert_eq!('Α'.to_lowercase(), 'α');
-    assert_eq!('Σ'.to_lowercase(), 'σ');
-}
+    #[test]
+    fn test_to_digit() {
+        assert_eq!('0'.to_digit(10u), Some(0u));
+        assert_eq!('1'.to_digit(2u), Some(1u));
+        assert_eq!('2'.to_digit(3u), Some(2u));
+        assert_eq!('9'.to_digit(10u), Some(9u));
+        assert_eq!('a'.to_digit(16u), Some(10u));
+        assert_eq!('A'.to_digit(16u), Some(10u));
+        assert_eq!('b'.to_digit(16u), Some(11u));
+        assert_eq!('B'.to_digit(16u), Some(11u));
+        assert_eq!('z'.to_digit(36u), Some(35u));
+        assert_eq!('Z'.to_digit(36u), Some(35u));
+        assert_eq!(' '.to_digit(10u), None);
+        assert_eq!('$'.to_digit(36u), None);
+    }
 
-#[test]
-fn test_to_uppercase() {
-    assert_eq!('a'.to_uppercase(), 'A');
-    assert_eq!('ö'.to_uppercase(), 'Ö');
-    assert_eq!('ß'.to_uppercase(), 'ß'); // not ẞ: Latin capital letter sharp s
-    assert_eq!('ü'.to_uppercase(), 'Ü');
-    assert_eq!('💩'.to_uppercase(), '💩');
-
-    assert_eq!('σ'.to_uppercase(), 'Σ');
-    assert_eq!('τ'.to_uppercase(), 'Τ');
-    assert_eq!('ι'.to_uppercase(), 'Ι');
-    assert_eq!('γ'.to_uppercase(), 'Γ');
-    assert_eq!('μ'.to_uppercase(), 'Μ');
-    assert_eq!('α'.to_uppercase(), 'Α');
-    assert_eq!('ς'.to_uppercase(), 'Σ');
-}
+    #[test]
+    fn test_to_lowercase() {
+        assert_eq!('A'.to_lowercase(), 'a');
+        assert_eq!('Ö'.to_lowercase(), 'ö');
+        assert_eq!('ß'.to_lowercase(), 'ß');
+        assert_eq!('Ü'.to_lowercase(), 'ü');
+        assert_eq!('💩'.to_lowercase(), '💩');
+        assert_eq!('Σ'.to_lowercase(), 'σ');
+        assert_eq!('Τ'.to_lowercase(), 'τ');
+        assert_eq!('Ι'.to_lowercase(), 'ι');
+        assert_eq!('Γ'.to_lowercase(), 'γ');
+        assert_eq!('Μ'.to_lowercase(), 'μ');
+        assert_eq!('Α'.to_lowercase(), 'α');
+        assert_eq!('Σ'.to_lowercase(), 'σ');
+    }
 
-#[test]
-fn test_is_control() {
-    assert!('\u0000'.is_control());
-    assert!('\u0003'.is_control());
-    assert!('\u0006'.is_control());
-    assert!('\u0009'.is_control());
-    assert!('\u007f'.is_control());
-    assert!('\u0092'.is_control());
-    assert!(!'\u0020'.is_control());
-    assert!(!'\u0055'.is_control());
-    assert!(!'\u0068'.is_control());
-}
+    #[test]
+    fn test_to_uppercase() {
+        assert_eq!('a'.to_uppercase(), 'A');
+        assert_eq!('ö'.to_uppercase(), 'Ö');
+        assert_eq!('ß'.to_uppercase(), 'ß'); // not ẞ: Latin capital letter sharp s
+        assert_eq!('ü'.to_uppercase(), 'Ü');
+        assert_eq!('💩'.to_uppercase(), '💩');
+
+        assert_eq!('σ'.to_uppercase(), 'Σ');
+        assert_eq!('τ'.to_uppercase(), 'Τ');
+        assert_eq!('ι'.to_uppercase(), 'Ι');
+        assert_eq!('γ'.to_uppercase(), 'Γ');
+        assert_eq!('μ'.to_uppercase(), 'Μ');
+        assert_eq!('α'.to_uppercase(), 'Α');
+        assert_eq!('ς'.to_uppercase(), 'Σ');
+    }
 
-#[test]
-fn test_is_digit() {
-   assert!('2'.is_digit());
-   assert!('7'.is_digit());
-   assert!(!'c'.is_digit());
-   assert!(!'i'.is_digit());
-   assert!(!'z'.is_digit());
-   assert!(!'Q'.is_digit());
-}
+    #[test]
+    fn test_is_control() {
+        assert!('\u0000'.is_control());
+        assert!('\u0003'.is_control());
+        assert!('\u0006'.is_control());
+        assert!('\u0009'.is_control());
+        assert!('\u007f'.is_control());
+        assert!('\u0092'.is_control());
+        assert!(!'\u0020'.is_control());
+        assert!(!'\u0055'.is_control());
+        assert!(!'\u0068'.is_control());
+    }
 
-#[test]
-fn test_escape_default() {
-    fn string(c: char) -> ~str {
-        let mut result = StrBuf::new();
-        escape_default(c, |c| { result.push_char(c); });
-        return result.into_owned();
+    #[test]
+    fn test_is_digit() {
+       assert!('2'.is_digit());
+       assert!('7'.is_digit());
+       assert!(!'c'.is_digit());
+       assert!(!'i'.is_digit());
+       assert!(!'z'.is_digit());
+       assert!(!'Q'.is_digit());
     }
-    assert_eq!(string('\n'), "\\n".to_owned());
-    assert_eq!(string('\r'), "\\r".to_owned());
-    assert_eq!(string('\''), "\\'".to_owned());
-    assert_eq!(string('"'), "\\\"".to_owned());
-    assert_eq!(string(' '), " ".to_owned());
-    assert_eq!(string('a'), "a".to_owned());
-    assert_eq!(string('~'), "~".to_owned());
-    assert_eq!(string('\x00'), "\\x00".to_owned());
-    assert_eq!(string('\x1f'), "\\x1f".to_owned());
-    assert_eq!(string('\x7f'), "\\x7f".to_owned());
-    assert_eq!(string('\xff'), "\\xff".to_owned());
-    assert_eq!(string('\u011b'), "\\u011b".to_owned());
-    assert_eq!(string('\U0001d4b6'), "\\U0001d4b6".to_owned());
-}
 
-#[test]
-fn test_escape_unicode() {
-    fn string(c: char) -> ~str {
-        let mut result = StrBuf::new();
-        escape_unicode(c, |c| { result.push_char(c); });
-        return result.into_owned();
+    #[test]
+    fn test_escape_default() {
+        fn string(c: char) -> ~str {
+            let mut result = StrBuf::new();
+            escape_default(c, |c| { result.push_char(c); });
+            return result.into_owned();
+        }
+        assert_eq!(string('\n'), "\\n".to_owned());
+        assert_eq!(string('\r'), "\\r".to_owned());
+        assert_eq!(string('\''), "\\'".to_owned());
+        assert_eq!(string('"'), "\\\"".to_owned());
+        assert_eq!(string(' '), " ".to_owned());
+        assert_eq!(string('a'), "a".to_owned());
+        assert_eq!(string('~'), "~".to_owned());
+        assert_eq!(string('\x00'), "\\x00".to_owned());
+        assert_eq!(string('\x1f'), "\\x1f".to_owned());
+        assert_eq!(string('\x7f'), "\\x7f".to_owned());
+        assert_eq!(string('\xff'), "\\xff".to_owned());
+        assert_eq!(string('\u011b'), "\\u011b".to_owned());
+        assert_eq!(string('\U0001d4b6'), "\\U0001d4b6".to_owned());
     }
-    assert_eq!(string('\x00'), "\\x00".to_owned());
-    assert_eq!(string('\n'), "\\x0a".to_owned());
-    assert_eq!(string(' '), "\\x20".to_owned());
-    assert_eq!(string('a'), "\\x61".to_owned());
-    assert_eq!(string('\u011b'), "\\u011b".to_owned());
-    assert_eq!(string('\U0001d4b6'), "\\U0001d4b6".to_owned());
-}
 
-#[test]
-fn test_to_str() {
-    use to_str::ToStr;
-    let s = 't'.to_str();
-    assert_eq!(s, "t".to_owned());
-}
+    #[test]
+    fn test_escape_unicode() {
+        fn string(c: char) -> ~str {
+            let mut result = StrBuf::new();
+            escape_unicode(c, |c| { result.push_char(c); });
+            return result.into_owned();
+        }
+        assert_eq!(string('\x00'), "\\x00".to_owned());
+        assert_eq!(string('\n'), "\\x0a".to_owned());
+        assert_eq!(string(' '), "\\x20".to_owned());
+        assert_eq!(string('a'), "\\x61".to_owned());
+        assert_eq!(string('\u011b'), "\\u011b".to_owned());
+        assert_eq!(string('\U0001d4b6'), "\\U0001d4b6".to_owned());
+    }
 
-#[test]
-fn test_encode_utf8() {
-    fn check(input: char, expect: &[u8]) {
-        let mut buf = [0u8, ..4];
-        let n = input.encode_utf8(buf /* as mut slice! */);
-        assert_eq!(buf.slice_to(n), expect);
+    #[test]
+    fn test_to_str() {
+        use to_str::ToStr;
+        let s = 't'.to_str();
+        assert_eq!(s, "t".to_owned());
     }
 
-    check('x', [0x78]);
-    check('\u00e9', [0xc3, 0xa9]);
-    check('\ua66e', [0xea, 0x99, 0xae]);
-    check('\U0001f4a9', [0xf0, 0x9f, 0x92, 0xa9]);
-}
+    #[test]
+    fn test_encode_utf8() {
+        fn check(input: char, expect: &[u8]) {
+            let mut buf = [0u8, ..4];
+            let n = input.encode_utf8(buf /* as mut slice! */);
+            assert_eq!(buf.slice_to(n), expect);
+        }
 
-#[test]
-fn test_encode_utf16() {
-    fn check(input: char, expect: &[u16]) {
-        let mut buf = [0u16, ..2];
-        let n = input.encode_utf16(buf /* as mut slice! */);
-        assert_eq!(buf.slice_to(n), expect);
+        check('x', [0x78]);
+        check('\u00e9', [0xc3, 0xa9]);
+        check('\ua66e', [0xea, 0x99, 0xae]);
+        check('\U0001f4a9', [0xf0, 0x9f, 0x92, 0xa9]);
     }
 
-    check('x', [0x0078]);
-    check('\u00e9', [0x00e9]);
-    check('\ua66e', [0xa66e]);
-    check('\U0001f4a9', [0xd83d, 0xdca9]);
+    #[test]
+    fn test_encode_utf16() {
+        fn check(input: char, expect: &[u16]) {
+            let mut buf = [0u16, ..2];
+            let n = input.encode_utf16(buf /* as mut slice! */);
+            assert_eq!(buf.slice_to(n), expect);
+        }
+
+        check('x', [0x0078]);
+        check('\u00e9', [0x00e9]);
+        check('\ua66e', [0xa66e]);
+        check('\U0001f4a9', [0xd83d, 0xdca9]);
+    }
 }
diff --git a/src/libcore/finally.rs b/src/libcore/finally.rs
index 6d02e6e3a17..ff167f20fff 100644
--- a/src/libcore/finally.rs
+++ b/src/libcore/finally.rs
@@ -117,49 +117,52 @@ impl<'a,A> Drop for Finallyalizer<'a,A> {
     }
 }
 
-#[test]
-fn test_success() {
-    let mut i = 0;
-    try_finally(
-        &mut i, (),
-        |i, ()| {
-            *i = 10;
-        },
-        |i| {
-            assert!(!failing());
-            assert_eq!(*i, 10);
-            *i = 20;
-        });
-    assert_eq!(i, 20);
-}
+#[cfg(test)]
+mod test {
+    #[test]
+    fn test_success() {
+        let mut i = 0;
+        try_finally(
+            &mut i, (),
+            |i, ()| {
+                *i = 10;
+            },
+            |i| {
+                assert!(!failing());
+                assert_eq!(*i, 10);
+                *i = 20;
+            });
+        assert_eq!(i, 20);
+    }
 
-#[test]
-#[should_fail]
-fn test_fail() {
-    let mut i = 0;
-    try_finally(
-        &mut i, (),
-        |i, ()| {
-            *i = 10;
-            fail!();
-        },
-        |i| {
-            assert!(failing());
-            assert_eq!(*i, 10);
-        })
-}
+    #[test]
+    #[should_fail]
+    fn test_fail() {
+        let mut i = 0;
+        try_finally(
+            &mut i, (),
+            |i, ()| {
+                *i = 10;
+                fail!();
+            },
+            |i| {
+                assert!(failing());
+                assert_eq!(*i, 10);
+            })
+    }
 
-#[test]
-fn test_retval() {
-    let mut closure: || -> int = || 10;
-    let i = closure.finally(|| { });
-    assert_eq!(i, 10);
-}
+    #[test]
+    fn test_retval() {
+        let mut closure: || -> int = || 10;
+        let i = closure.finally(|| { });
+        assert_eq!(i, 10);
+    }
 
-#[test]
-fn test_compact() {
-    fn do_some_fallible_work() {}
-    fn but_always_run_this_function() { }
-    let mut f = do_some_fallible_work;
-    f.finally(but_always_run_this_function);
+    #[test]
+    fn test_compact() {
+        fn do_some_fallible_work() {}
+        fn but_always_run_this_function() { }
+        let mut f = do_some_fallible_work;
+        f.finally(but_always_run_this_function);
+    }
 }