]> git.lizzy.rs Git - rust.git/blob - tests/target/chains-visual.rs
Add visual indent tests for chains
[rust.git] / tests / target / chains-visual.rs
1 // rustfmt-chain_indent: Visual
2 // rustfmt-chain_base_indent: Visual
3 // Test chain formatting.
4
5 fn main() {
6     // Don't put chains on a single line if it wasn't so in source.
7     let a = b.c
8              .d
9              .1
10              .foo(|x| x + 1);
11
12     bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
13                        .ddddddddddddddddddddddddddd();
14
15     bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
16                        .ddddddddddddddddddddddddddd
17                        .eeeeeeee();
18
19     // Test case where first chain element isn't a path, but is shorter than
20     // the size of a tab.
21     x().y(|| match cond() {
22         true => (),
23         false => (),
24     });
25
26     loong_func().quux(move || if true {
27         1
28     } else {
29         2
30     });
31
32     some_fuuuuuuuuunction().method_call_a(aaaaa, bbbbb, |c| {
33         let x = c;
34         x
35     });
36
37     some_fuuuuuuuuunction()
38         .method_call_a(aaaaa, bbbbb, |c| {
39             let x = c;
40             x
41         })
42         .method_call_b(aaaaa, bbbbb, |c| {
43             let x = c;
44             x
45         });
46
47     fffffffffffffffffffffffffffffffffff(a, {
48         SCRIPT_TASK_ROOT.with(|root| {
49             *root.borrow_mut() = Some(&script_task);
50         });
51     });
52
53     let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum = xxxxxxx.map(|x| x + 5)
54                                                                           .map(|x| x / 2)
55                                                                           .fold(0,
56                                                                                 |acc, x| acc + x);
57
58     aaaaaaaaaaaaaaaa.map(|x| {
59                         x += 1;
60                         x
61                     })
62                     .filter(some_mod::some_filter)
63 }
64
65 fn floaters() {
66     let z = Foo {
67         field1: val1,
68         field2: val2,
69     };
70
71     let x = Foo {
72                 field1: val1,
73                 field2: val2,
74             }
75             .method_call()
76             .method_call();
77
78     let y = if cond {
79                 val1
80             } else {
81                 val2
82             }
83             .method_call();
84
85     {
86         match x {
87             PushParam => {
88                 // params are 1-indexed
89                 stack.push(mparams[match cur.to_digit(10) {
90                                Some(d) => d as usize - 1,
91                                None => return Err("bad param number".to_owned()),
92                            }]
93                            .clone());
94             }
95         }
96     }
97
98     if cond {
99         some();
100     } else {
101         none();
102     }
103     .bar()
104     .baz();
105
106     Foo { x: val }
107         .baz(|| {
108             // force multiline
109         })
110         .quux();
111
112     Foo {
113         y: i_am_multi_line,
114         z: ok,
115     }
116     .baz(|| {
117         // force multiline
118     })
119     .quux();
120
121     a +
122     match x {
123         true => "yay!",
124         false => "boo!",
125     }
126     .bar()
127 }
128
129 fn is_replaced_content() -> bool {
130     constellat.send(ConstellationMsg::ViewportConstrained(self.id, constraints))
131               .unwrap();
132 }
133
134 fn issue587() {
135     a.b::<()>(c);
136
137     std::mem::transmute(dl.symbol::<()>("init").unwrap())
138 }