fmt: cleanup and expand tests for ternary if (#8333)

pull/8338/head
Lukas Neubert 2021-01-25 14:22:08 +01:00 committed by GitHub
parent 1c9950c84a
commit b2f2f387dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 24 deletions

View File

@ -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
}
}
}

View File

@ -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 }

View File

@ -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'
}
}

View File

@ -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' }
}

View File

@ -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'
}
}