Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

gleam / format / src / tests / use_.rs
4.7 kB 360 lines
1// SPDX-License-Identifier: Apache-2.0 2// SPDX-FileCopyrightText: 2022 The Gleam contributors 3 4use crate::{assert_format, assert_format_rewrite}; 5 6#[test] 7fn use_1() { 8 assert_format!( 9 r#"pub fn main() { 10 use <- benchmark("thingy") 11 todo 12} 13"# 14 ); 15} 16 17#[test] 18fn use_2() { 19 assert_format!( 20 r#"pub fn main() { 21 use user <- login() 22 todo 23} 24"# 25 ); 26} 27 28#[test] 29fn use_3() { 30 assert_format!( 31 r#"pub fn main() { 32 use one, two, three, four <- get_multiple_things() 33 todo 34} 35"# 36 ); 37} 38 39#[test] 40fn use_4() { 41 assert_format!( 42 r#"pub fn main() { 43 use 44 one, 45 two, 46 three, 47 four, 48 five, 49 six, 50 seven, 51 eight, 52 nine, 53 ten, 54 eleven, 55 twelve, 56 thirteen 57 <- get_multiple_things_with_a_longer_function 58 todo 59} 60"# 61 ); 62} 63 64#[test] 65fn use_5() { 66 assert_format!( 67 r#"pub fn main() { 68 use 69 one, 70 two, 71 three, 72 four, 73 five, 74 six, 75 seven, 76 eight, 77 nine, 78 ten, 79 eleven, 80 twelve, 81 thirteen 82 <- get_multiple_things_with_a_longer_function(a, b, c, d) 83 todo 84} 85"# 86 ); 87} 88 89#[test] 90fn use_6() { 91 assert_format!( 92 r#"pub fn main() { 93 use 94 one, 95 two, 96 three, 97 four, 98 five, 99 six, 100 seven, 101 eight, 102 nine, 103 ten, 104 eleven, 105 twelve, 106 thirteen 107 <- get_multiple_things_with_a_longer_function( 108 "one", 109 "two", 110 "three", 111 "four", 112 "five", 113 "six", 114 "seven", 115 "eight", 116 ) 117 todo 118} 119"# 120 ); 121} 122 123#[test] 124fn pipe_call() { 125 assert_format!( 126 r#"pub fn main() { 127 use <- 128 a 129 |> b 130 c 131} 132"# 133 ); 134} 135 136#[test] 137fn use_pipe_everything() { 138 assert_format!( 139 r#"pub fn main() { 140 { 141 use <- a 142 todo 143 } 144 |> b 145 c 146} 147"# 148 ); 149} 150 151#[test] 152fn long_right_hand_side_0_arguments() { 153 assert_format!( 154 r#"pub fn main() { 155 use <- some_really_long_function_call( 156 "one", 157 "two", 158 "three", 159 "four", 160 "five", 161 "six", 162 "seven", 163 "eight", 164 ) 165 todo 166} 167"# 168 ); 169} 170 171#[test] 172fn long_right_hand_side_1_argument() { 173 assert_format!( 174 r#"pub fn main() { 175 use x <- some_really_long_function_call( 176 "one", 177 "two", 178 "three", 179 "four", 180 "five", 181 "six", 182 "seven", 183 "eight", 184 ) 185 todo 186} 187"# 188 ); 189} 190 191#[test] 192fn long_right_hand_side_2_arguments() { 193 assert_format!( 194 r#"pub fn main() { 195 use x, y <- some_really_long_function_call( 196 "one", 197 "two", 198 "three", 199 "four", 200 "five", 201 "six", 202 "seven", 203 "eight", 204 ) 205 todo 206} 207"# 208 ); 209} 210 211#[test] 212fn arity_1_var_call() { 213 assert_format!( 214 r#"pub fn main() { 215 use x, y <- await( 216 file.read() 217 |> promise.map(something), 218 ) 219 todo 220} 221"# 222 ); 223} 224 225#[test] 226fn arity_1_access_call() { 227 assert_format!( 228 r#"pub fn main() { 229 use x, y <- promise.await( 230 file.read() 231 |> promise.map(something), 232 ) 233 todo 234} 235"# 236 ); 237} 238 239#[test] 240fn patterns() { 241 assert_format!( 242 r#"pub fn main() { 243 use Box(x) <- apply(Box(1)) 244 x 245} 246"# 247 ); 248} 249 250#[test] 251fn patterns_with_annotation() { 252 assert_format!( 253 r#"pub fn main() { 254 use Box(x): Box(Int) <- apply(Box(1)) 255 x 256} 257"# 258 ); 259} 260 261#[test] 262fn long_patterns() { 263 assert_format!( 264 r#"pub fn main() { 265 use 266 Box( 267 xxxxxxxxxxxxxxxxxxxxxxx, 268 yyyyyyyyyyyyyyyyyyyyyyyyyyy, 269 zzzzzzzzzzzzzzzzzzzzzzzzzzzz, 270 ) 271 <- apply(Box(1)) 272 x 273} 274"# 275 ); 276} 277 278#[test] 279fn multiple_long_patterns() { 280 assert_format!( 281 r#"pub fn main() { 282 use 283 Box( 284 xxxxxxxxxxxxxxxxxxxxxxx, 285 yyyyyyyyyyyyyyyyyyyyyyyyyyy, 286 zzzzzzzzzzzzzzzzzzzzzzzzzzzz, 287 ), 288 Box(_), 289 Box(_), 290 Box(_) 291 <- apply(Box(1)) 292 x 293} 294"# 295 ); 296} 297 298#[test] 299fn multiple_long_patterns_with_annotations() { 300 assert_format!( 301 r#"pub fn main() { 302 use 303 Box( 304 xxxxxxxxxxxxxxxxxxxxxxx, 305 yyyyyyyyyyyyyyyyyyyyyyyyyyy, 306 zzzzzzzzzzzzzzzzzzzzzzzzzzzz, 307 ): Box(Int, Bool, String), 308 Box(_) 309 <- apply(Box(1)) 310 x 311} 312"# 313 ); 314} 315 316#[test] 317fn multiple_long_annotations() { 318 assert_format!( 319 r#"pub fn main() { 320 use 321 Box(_, _): Box( 322 Xxzxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, 323 Yyyyyyyyyyyyyyyyyyyyyyyy, 324 ), 325 Box(_) 326 <- apply(Box(1)) 327 x 328} 329"# 330 ); 331} 332 333// https://github.com/gleam-lang/gleam/issues/2114 334#[test] 335fn comment() { 336 assert_format!( 337 r#"fn main() { 338 // comment 339 use x <- result.then(y) 340 todo 341} 342"# 343 ); 344} 345 346// https://github.com/gleam-lang/gleam/issues/3605 347#[test] 348fn use_with_empty_callback_body_is_rewritten_to_have_a_todo() { 349 assert_format_rewrite!( 350 r#"fn main() { 351 use wibble, wobble <- woo 352} 353"#, 354 r#"fn main() { 355 use wibble, wobble <- woo 356 todo 357} 358"# 359 ); 360}