PageRenderTime 21ms CodeModel.GetById 11ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/src/test/run-pass/expr-block-generic.rs

http://github.com/jruderman/rust
Rust | 26 lines | 15 code | 9 blank | 2 comment | 2 complexity | 2c54168649c031f62bc7957164b38d5f MD5 | raw file
 1
 2
 3
 4// -*- rust -*-
 5
 6// Tests for standalone blocks as expressions with dynamic type sizes
 7type compare<T> = fn@(T, T) -> bool;
 8
 9fn test_generic<T: copy>(expected: T, eq: compare<T>) {
10    let actual: T = { expected };
11    assert (eq(expected, actual));
12}
13
14fn test_bool() {
15    fn compare_bool(&&b1: bool, &&b2: bool) -> bool { return b1 == b2; }
16    test_generic::<bool>(true, compare_bool);
17}
18
19fn test_rec() {
20    type t = {a: int, b: int};
21
22    fn compare_rec(t1: t, t2: t) -> bool { return t1 == t2; }
23    test_generic::<t>({a: 1, b: 2}, compare_rec);
24}
25
26fn main() { test_bool(); test_rec(); }