]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/numeric-method-autoexport.rs
3e3391b034210c2eecd84dd2c5831799768d685c
[rust.git] / src / test / run-pass / numeric-method-autoexport.rs
1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // no-pretty-expanded
12
13 // This file is intended to test only that methods are automatically
14 // reachable for each numeric type, for each exported impl, with no imports
15 // necessary. Testing the methods of the impls is done within the source
16 // file for each numeric type.
17
18 #![feature(core)]
19
20 use std::ops::Add;
21 use std::num::ToPrimitive;
22
23 pub fn main() {
24 // ints
25     // num
26     assert_eq!(15_isize.add(6_isize), 21_isize);
27     assert_eq!(15_i8.add(6i8), 21_i8);
28     assert_eq!(15_i16.add(6i16), 21_i16);
29     assert_eq!(15_i32.add(6i32), 21_i32);
30     assert_eq!(15_i64.add(6i64), 21_i64);
31
32 // uints
33     // num
34     assert_eq!(15_usize.add(6_usize), 21_usize);
35     assert_eq!(15_u8.add(6u8), 21_u8);
36     assert_eq!(15_u16.add(6u16), 21_u16);
37     assert_eq!(15_u32.add(6u32), 21_u32);
38     assert_eq!(15_u64.add(6u64), 21_u64);
39
40 // floats
41     // num
42     assert_eq!(10_f32.to_i32().unwrap(), 10);
43     assert_eq!(10_f64.to_i32().unwrap(), 10);
44 }