]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass-fulldeps/macro-quote-cond.rs
f1dcec8af6906a5478fabcce97cc7a8c58a690fe
[rust.git] / src / test / run-pass-fulldeps / macro-quote-cond.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 // aux-build:cond_plugin.rs
12 // ignore-stage1
13
14 #![feature(use_extern_macros, proc_macro_non_items)]
15
16 extern crate cond_plugin;
17
18 use cond_plugin::cond;
19
20 fn fact(n : i64) -> i64 {
21     if n == 0 {
22         1
23     } else {
24         n * fact(n - 1)
25     }
26 }
27
28 fn fact_cond(n : i64) -> i64 {
29   cond!(
30     ((n == 0) 1)
31     (else (n * fact_cond(n-1)))
32   )
33 }
34
35 fn fib(n : i64) -> i64 {
36   if n == 0 || n == 1 {
37       1
38   } else {
39       fib(n-1) + fib(n-2)
40   }
41 }
42
43 fn fib_cond(n : i64) -> i64 {
44   cond!(
45     ((n == 0) 1)
46     ((n == 1) 1)
47     (else (fib_cond(n-1) + fib_cond(n-2)))
48   )
49 }
50
51 fn main() {
52     assert_eq!(fact(3), fact_cond(3));
53     assert_eq!(fact(5), fact_cond(5));
54     assert_eq!(fib(5), fib_cond(5));
55     assert_eq!(fib(8), fib_cond(8));
56 }