]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass-fulldeps/macro-quote-cond.rs
New upstream version 1.31.0~beta.4+dfsg1
[rustc.git] / src / test / run-pass-fulldeps / macro-quote-cond.rs
CommitLineData
9e0c209e
SL
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
0bf4aa26 11#![allow(unused_parens)]
9e0c209e
SL
12// aux-build:cond_plugin.rs
13// ignore-stage1
14
0bf4aa26 15#![feature(proc_macro_hygiene)]
041b39d2
XL
16
17extern crate cond_plugin;
18
19use cond_plugin::cond;
9e0c209e
SL
20
21fn fact(n : i64) -> i64 {
22 if n == 0 {
23 1
24 } else {
25 n * fact(n - 1)
26 }
27}
28
29fn fact_cond(n : i64) -> i64 {
30 cond!(
31 ((n == 0) 1)
32 (else (n * fact_cond(n-1)))
33 )
34}
35
36fn fib(n : i64) -> i64 {
37 if n == 0 || n == 1 {
38 1
39 } else {
40 fib(n-1) + fib(n-2)
41 }
42}
43
44fn fib_cond(n : i64) -> i64 {
45 cond!(
46 ((n == 0) 1)
47 ((n == 1) 1)
48 (else (fib_cond(n-1) + fib_cond(n-2)))
49 )
50}
51
52fn main() {
53 assert_eq!(fact(3), fact_cond(3));
54 assert_eq!(fact(5), fact_cond(5));
55 assert_eq!(fib(5), fib_cond(5));
56 assert_eq!(fib(8), fib_cond(8));
57}