Skip to content

Commit

Permalink
Add test cases related to rust-lang#2896 and rust-lang#3528
Browse files Browse the repository at this point in the history
  • Loading branch information
davidBar-On committed Aug 31, 2020
1 parent c223d41 commit fe163d2
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 2 deletions.
50 changes: 49 additions & 1 deletion tests/source/issue-CastComments.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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<Vec<Box<dyn Backend>>> {
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::<GitConfig>().unwrap(),
})
as Box<dyn Backend>),
AvailableBackend::Github => Some(Box::new(Github {
config: value.clone().try_into::<GithubConfig>().unwrap(),
})
as Box<dyn Backend>),
})
.collect()
})
})
}
50 changes: 49 additions & 1 deletion tests/target/issue-CastComments.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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<Vec<Box<dyn Backend>>> {
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::<GitConfig>().unwrap(),
}) as Box<dyn Backend>)
}
AvailableBackend::Github => {
Some(Box::new(Github {
config: value.clone().try_into::<GithubConfig>().unwrap(),
}) as Box<dyn Backend>)
}
})
.collect()
})
})
}

0 comments on commit fe163d2

Please sign in to comment.