Skip to content

Commit fe163d2

Browse files
committed
Add test cases related to rust-lang#2896 and rust-lang#3528
1 parent c223d41 commit fe163d2

File tree

2 files changed

+98
-2
lines changed

2 files changed

+98
-2
lines changed

tests/source/issue-CastComments.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
/* Tests proper formatting of pre and post cast ("as") comments */
1+
/*****
2+
* Tests for proper formatting of pre and post cast ("as") comments
3+
******/
24

35
// Test 1
46
fn main() {
@@ -48,3 +50,49 @@ let x = 1 /* as foo yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy */
4850
as/* as bar xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
4951
i32;
5052
}
53+
54+
55+
/*****
56+
* Tests for not leaving trailing spaces related to cast comments (related to #2896?)
57+
******/
58+
// Test 10 - note the extra blank at the end of the 2nd line
59+
fn main() {
60+
if 0 == 1
61+
/* x */ as i32 {} }
62+
63+
// Test 11 - note the extra blank at the end of the 2nd line
64+
fn main() {
65+
if 0 == ' '
66+
as i32 {} }
67+
68+
// Test 10 - note the extra blank at the end of the 2nd line
69+
fn main() {
70+
if 0 == ' ' /* x */
71+
as i32 {} }
72+
73+
74+
/*****
75+
* Tests for not moving "as" to new line unnecessarily - from #3528
76+
******/
77+
fn get_old_backends(old_toml_config: &toml::Value) -> Option<Vec<Box<dyn Backend>>> {
78+
old_toml_config.as_table().and_then(|table| {
79+
table
80+
.get("backends")
81+
.and_then(|backends| backends.as_table())
82+
.map(|backends| {
83+
backends
84+
.into_iter()
85+
.filter_map(|(key, value)| match AvailableBackend::from(key.as_str()) {
86+
AvailableBackend::Git => Some(Box::new(Git {
87+
config: value.clone().try_into::<GitConfig>().unwrap(),
88+
})
89+
as Box<dyn Backend>),
90+
AvailableBackend::Github => Some(Box::new(Github {
91+
config: value.clone().try_into::<GithubConfig>().unwrap(),
92+
})
93+
as Box<dyn Backend>),
94+
})
95+
.collect()
96+
})
97+
})
98+
}

tests/target/issue-CastComments.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
/* Tests proper formatting of pre and post cast ("as") comments */
1+
/*****
2+
* Tests for proper formatting of pre and post cast ("as") comments
3+
******/
24

35
// Test 1
46
fn main() {
@@ -49,3 +51,49 @@ fn main() {
4951
as /* as bar xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
5052
i32;
5153
}
54+
55+
/*****
56+
* Tests for not leaving trailing spaces related to cast comments (related to #2896?)
57+
******/
58+
// Test 10 - note the extra blank at the end of the 2nd line
59+
fn main() {
60+
if 0 == 1 /* x */ as i32 {}
61+
}
62+
63+
// Test 11 - note the extra blank at the end of the 2nd line
64+
fn main() {
65+
if 0 == ' ' as i32 {}
66+
}
67+
68+
// Test 10 - note the extra blank at the end of the 2nd line
69+
fn main() {
70+
if 0 == ' ' /* x */ as i32 {}
71+
}
72+
73+
/*****
74+
* Tests for not moving "as" to new line unnecessarily - from #3528
75+
******/
76+
fn get_old_backends(old_toml_config: &toml::Value) -> Option<Vec<Box<dyn Backend>>> {
77+
old_toml_config.as_table().and_then(|table| {
78+
table
79+
.get("backends")
80+
.and_then(|backends| backends.as_table())
81+
.map(|backends| {
82+
backends
83+
.into_iter()
84+
.filter_map(|(key, value)| match AvailableBackend::from(key.as_str()) {
85+
AvailableBackend::Git => {
86+
Some(Box::new(Git {
87+
config: value.clone().try_into::<GitConfig>().unwrap(),
88+
}) as Box<dyn Backend>)
89+
}
90+
AvailableBackend::Github => {
91+
Some(Box::new(Github {
92+
config: value.clone().try_into::<GithubConfig>().unwrap(),
93+
}) as Box<dyn Backend>)
94+
}
95+
})
96+
.collect()
97+
})
98+
})
99+
}

0 commit comments

Comments
 (0)