fmt: cleanup and expand tests for ternary if (#8333)
							parent
							
								
									1c9950c84a
								
							
						
					
					
						commit
						b2f2f387dc
					
				|  | @ -1,20 +0,0 @@ | ||||||
| fn main() { |  | ||||||
| 	sprogress := if b.no_cstep { |  | ||||||
| 		'TMP1/${b.nexpected_steps:1d}' |  | ||||||
| 	} else { |  | ||||||
| 		'${b.cstep:1d}/${b.nexpected_steps:1d}' |  | ||||||
| 	} |  | ||||||
| 	b := if bar { |  | ||||||
| 		// comment
 |  | ||||||
| 		'some str' |  | ||||||
| 	} else { |  | ||||||
| 		'other str' |  | ||||||
| 	} |  | ||||||
| 	_ := if true { |  | ||||||
| 		Foo{} |  | ||||||
| 	} else { |  | ||||||
| 		Foo{ |  | ||||||
| 			x: 5 |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|  | @ -1,4 +0,0 @@ | ||||||
| a, b := if true { 'a', 'b' } else { 'b', 'a' } |  | ||||||
| _ := if false { Foo{} } else { Foo{5, 6} } |  | ||||||
| arr := [0, 1] |  | ||||||
| arr << if true { 2 } else { 3 } |  | ||||||
|  | @ -0,0 +1,33 @@ | ||||||
|  | fn main() { | ||||||
|  | 	// This line is too long
 | ||||||
|  | 	sprogress := if b.no_cstep { | ||||||
|  | 		'TMP1/${b.nexpected_steps:1d}' | ||||||
|  | 	} else { | ||||||
|  | 		'${b.cstep:1d}/${b.nexpected_steps:1d}' | ||||||
|  | 	} | ||||||
|  | 	// Normal struct inits
 | ||||||
|  | 	_ := if true { | ||||||
|  | 		Foo{} | ||||||
|  | 	} else { | ||||||
|  | 		Foo{ | ||||||
|  | 			x: 5 | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	_ := if some_cond { | ||||||
|  | 		Bar{ | ||||||
|  | 			a: 'bar' | ||||||
|  | 			b: 'also bar' | ||||||
|  | 		} | ||||||
|  | 	} else { | ||||||
|  | 		Bar{} | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | fn condition_is_very_long_infix() { | ||||||
|  | 	val := if the_first_condition && this_is_required_too | ||||||
|  | 		&& (another_cond || foobar_to_exceed_the_max_len) { | ||||||
|  | 		'true' | ||||||
|  | 	} else { | ||||||
|  | 		'false' | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | @ -0,0 +1,13 @@ | ||||||
|  | fn main() { | ||||||
|  | 	// This line is too long
 | ||||||
|  | 	sprogress := if b.no_cstep { 'TMP1/${b.nexpected_steps:1d}' } else { '${b.cstep:1d}/${b.nexpected_steps:1d}' } | ||||||
|  | 	// Normal struct inits
 | ||||||
|  | 	_ := if true { Foo{} } else { Foo{ | ||||||
|  | 		x: 5 | ||||||
|  | 	} } | ||||||
|  | 	_ := if some_cond { Bar{ a: 'bar', b: 'also bar'} } else { Bar{} } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | fn condition_is_very_long_infix() { | ||||||
|  | 	val := if the_first_condition && this_is_required_too && (another_cond || foobar_to_exceed_the_max_len) { 'true' } else { 'false' } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,20 @@ | ||||||
|  | fn valid_single_line() { | ||||||
|  | 	// Variable initialization
 | ||||||
|  | 	a, b := if true { 'a', 'b' } else { 'b', 'a' } | ||||||
|  | 	// Variable assignment
 | ||||||
|  | 	mut x := 'abc' | ||||||
|  | 	x = if x == 'def' { 'ghi' } else { 'def' } | ||||||
|  | 	// Array pushes
 | ||||||
|  | 	[0, 1] << if true { 2 } else { 3 } | ||||||
|  | 	// Empty or literal syntax struct inits
 | ||||||
|  | 	_ := if false { Foo{} } else { Foo{5, 6} } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | fn requires_multiple_lines() { | ||||||
|  | 	b := if bar { | ||||||
|  | 		// with comments inside
 | ||||||
|  | 		'some str' | ||||||
|  | 	} else { | ||||||
|  | 		'other str' | ||||||
|  | 	} | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue