Debian Codegraph @

tests/std_unstable.rs

raw symbols SCIP
1 /*
2 Copyright ⓒ 2015 rust-custom-derive contributors.
3
4 Licensed under the MIT license (see LICENSE or <http://opensource.org
5 /licenses/MIT>) or the Apache License, Version 2.0 (see LICENSE of
6 <http://www.apache.org/licenses/LICENSE-2.0>), at your option. All
7 files in the project carrying such notice may not be copied, modified,
8 or distributed except according to those terms.
9 */
10 #![cfg(feature="std-unstable")]
11 #![allow(deprecated)]
12 #![cfg_attr(feature="std-unstable", feature(zero_one))]
13 #![cfg_attr(feature="std-unstable", feature(iter_arith_traits))]
14
15 #[macro_use] extern crate custom_derive;
16 #[macro_use] extern crate newtype_derive;
17
18 use std::num::{One, Zero};
19
20 custom_derive! {
21 #[derive(
22 Clone, Eq, PartialEq, Debug,
23 NewtypeOne, NewtypeZero,
24 NewtypeSum, NewtypeSum(&Self),
25 NewtypeProduct, NewtypeProduct(&Self),
26 )]
27 struct Dummy(i32);
28 }
29
30 #[test]
31 fn test_one_zero() {
32 assert_eq!(Dummy::zero(), Dummy(0));
33 assert_eq!(Dummy::one(), Dummy(1));
34 }
35
36 #[test]
37 fn test_sum_product() {
38 let dummies = &[Dummy(2), Dummy(3)];
39 assert_eq!(dummies.into_iter().sum::<Dummy>(), Dummy(5));
40 assert_eq!(dummies.into_iter().cloned().sum::<Dummy>(), Dummy(5));
41 assert_eq!(dummies.into_iter().product::<Dummy>(), Dummy(6));
42 assert_eq!(dummies.into_iter().cloned().product::<Dummy>(), Dummy(6));
43 }