diff --git a/tests/source/issue-CastComments.rs b/tests/source/issue-CastComments.rs index a2c448b7936..31c5dc20d64 100644 --- a/tests/source/issue-CastComments.rs +++ b/tests/source/issue-CastComments.rs @@ -1,4 +1,6 @@ -/* Tests proper formatting of pre and post cast ("as") comments */ +/***** + * Tests for proper formatting of pre and post cast ("as") comments + ******/ // Test 1 fn main() { @@ -48,3 +50,49 @@ let x = 1 /* as foo yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy */ as/* as bar xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ i32; } + + +/***** + * Tests for not leaving trailing spaces related to cast comments (related to #2896?) + ******/ +// Test 10 - note the extra blank at the end of the 2nd line +fn main() { + if 0 == 1 + /* x */ as i32 {} } + +// Test 11 - note the extra blank at the end of the 2nd line +fn main() { + if 0 == ' ' + as i32 {} } + +// Test 10 - note the extra blank at the end of the 2nd line +fn main() { + if 0 == ' ' /* x */ + as i32 {} } + + +/***** + * Tests for not moving "as" to new line unnecessarily - from #3528 + ******/ +fn get_old_backends(old_toml_config: &toml::Value) -> Option>> { + old_toml_config.as_table().and_then(|table| { + table + .get("backends") + .and_then(|backends| backends.as_table()) + .map(|backends| { + backends + .into_iter() + .filter_map(|(key, value)| match AvailableBackend::from(key.as_str()) { + AvailableBackend::Git => Some(Box::new(Git { + config: value.clone().try_into::().unwrap(), + }) + as Box), + AvailableBackend::Github => Some(Box::new(Github { + config: value.clone().try_into::().unwrap(), + }) + as Box), + }) + .collect() + }) + }) +} diff --git a/tests/target/issue-CastComments.rs b/tests/target/issue-CastComments.rs index e84df671d73..7cee40a6722 100644 --- a/tests/target/issue-CastComments.rs +++ b/tests/target/issue-CastComments.rs @@ -1,4 +1,6 @@ -/* Tests proper formatting of pre and post cast ("as") comments */ +/***** + * Tests for proper formatting of pre and post cast ("as") comments + ******/ // Test 1 fn main() { @@ -49,3 +51,49 @@ fn main() { as /* as bar xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ i32; } + +/***** + * Tests for not leaving trailing spaces related to cast comments (related to #2896?) + ******/ +// Test 10 - note the extra blank at the end of the 2nd line +fn main() { + if 0 == 1 /* x */ as i32 {} +} + +// Test 11 - note the extra blank at the end of the 2nd line +fn main() { + if 0 == ' ' as i32 {} +} + +// Test 10 - note the extra blank at the end of the 2nd line +fn main() { + if 0 == ' ' /* x */ as i32 {} +} + +/***** + * Tests for not moving "as" to new line unnecessarily - from #3528 + ******/ +fn get_old_backends(old_toml_config: &toml::Value) -> Option>> { + old_toml_config.as_table().and_then(|table| { + table + .get("backends") + .and_then(|backends| backends.as_table()) + .map(|backends| { + backends + .into_iter() + .filter_map(|(key, value)| match AvailableBackend::from(key.as_str()) { + AvailableBackend::Git => { + Some(Box::new(Git { + config: value.clone().try_into::().unwrap(), + }) as Box) + } + AvailableBackend::Github => { + Some(Box::new(Github { + config: value.clone().try_into::().unwrap(), + }) as Box) + } + }) + .collect() + }) + }) +}