diff options
| author | Brendan Zabarauskas <bjzaba@yahoo.com.au> | 2013-04-13 23:59:52 +1000 |
|---|---|---|
| committer | Brendan Zabarauskas <bjzaba@yahoo.com.au> | 2013-04-14 01:14:02 +1000 |
| commit | 947ba206e10126be8a03afd58039a99430a824fd (patch) | |
| tree | c65ec74866635e65dddeac0bdf6de54dfc34c4fe | |
| parent | 353ce872e287edf3764ca416d2a8cd8e1f54329b (diff) | |
| download | rust-947ba206e10126be8a03afd58039a99430a824fd.tar.gz rust-947ba206e10126be8a03afd58039a99430a824fd.zip | |
Add a test to show how NumCast can be used in type parameters
| -rw-r--r-- | src/libcore/num/num.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/libcore/num/num.rs b/src/libcore/num/num.rs index 50894b85a49..a2570943682 100644 --- a/src/libcore/num/num.rs +++ b/src/libcore/num/num.rs @@ -240,4 +240,27 @@ macro_rules! test_cast_20( #[test] fn test_int_cast() { test_cast_20!(20i) } #[test] fn test_f32_cast() { test_cast_20!(20f32) } #[test] fn test_f64_cast() { test_cast_20!(20f64) } -#[test] fn test_float_cast() { test_cast_20!(20f) } \ No newline at end of file +#[test] fn test_float_cast() { test_cast_20!(20f) } + +#[test] +fn test_generic_cast() { + use ops::Add; + + fn add_2<T: Add<T,T> + NumCast>(n: T) -> T { + n + cast(2) + } + + assert!(add_2(1u) == 3u); + assert!(add_2(1u8) == 3u8); + assert!(add_2(1u16) == 3u16); + assert!(add_2(1u32) == 3u32); + assert!(add_2(1u64) == 3u64); + assert!(add_2(1i) == 3i); + assert!(add_2(1i8) == 3i8); + assert!(add_2(1i16) == 3i16); + assert!(add_2(1i32) == 3i32); + assert!(add_2(1i64) == 3i64); + assert!(add_2(1f) == 3f); + assert!(add_2(1f32) == 3f32); + assert!(add_2(1f64) == 3f64); +} |
