summary refs log tree commit diff
path: root/src/test/run-pass/dst-struct-reflect.rs
blob: 2028ebf64c217afd68e71edeaa0a015d23183188 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// FIXME(15049) Re-enable this test.
// ignore-test
// Test that structs with unsized fields work with {:?} reflection.

extern crate debug;

struct Fat<Sized? T> {
    f1: int,
    f2: &'static str,
    ptr: T
}

// x is a fat pointer
fn reflect(x: &Fat<[int]>, cmp: &str) {
    // Don't test this result because reflecting unsized fields is undefined for now.
    let _s = format!("{:?}", x);
    let s = format!("{:?}", &x.ptr);
    assert!(s == cmp.to_string())

    println!("{:?}", x);
    println!("{:?}", &x.ptr);
}

fn reflect_0(x: &Fat<[int]>) {
    let _s = format!("{:?}", x.ptr[0]);
    println!("{:?}", x.ptr[0]);
}

pub fn main() {
    // With a vec of ints.
    let f1 = Fat { f1: 5, f2: "some str", ptr: [1, 2, 3] };
    reflect(&f1, "&[1, 2, 3]");
    reflect_0(&f1);
    let f2 = &f1;
    reflect(f2, "&[1, 2, 3]");
    reflect_0(f2);
    let f3: &Fat<[int]> = f2;
    reflect(f3, "&[1, 2, 3]");
    reflect_0(f3);
    let f4: &Fat<[int]> = &f1;
    reflect(f4, "&[1, 2, 3]");
    reflect_0(f4);
    let f5: &Fat<[int]> = &Fat { f1: 5, f2: "some str", ptr: [1, 2, 3] };
    reflect(f5, "&[1, 2, 3]");
    reflect_0(f5);

    // Zero size vec.
    let f5: &Fat<[int]> = &Fat { f1: 5, f2: "some str", ptr: [] };
    reflect(f5, "&[]");
}