From 2793b4090c2acef5380bfb6f972f79a3d338f968 Mon Sep 17 00:00:00 2001 From: Connor Brewster Date: Mon, 14 Mar 2016 20:05:20 -0600 Subject: [PATCH] Added tests --- src/items.rs | 11 +++++------ src/visitor.rs | 15 ++++++++------- tests/source/impls.rs | 16 ++++++++++------ tests/source/trait.rs | 6 ++++++ tests/source/where-trailing-comma.rs | 3 +-- tests/target/impls.rs | 4 ++++ tests/target/trait.rs | 9 +++++++++ tests/target/where-trailing-comma.rs | 5 +++-- 8 files changed, 46 insertions(+), 23 deletions(-) diff --git a/src/items.rs b/src/items.rs index ccf99c5dae7..5f8345593ee 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1034,9 +1034,7 @@ pub fn rewrite_associated_type(prefix: &str, let bounds: &[_] = &ty_param_bounds.as_slice(); let bound_str = bounds.iter() .filter_map(|ty_bound| { - ty_bound.rewrite(context, - context.config.max_width, - indent) + ty_bound.rewrite(context, context.config.max_width, indent) }) .collect::>() .join(" + "); @@ -1052,7 +1050,8 @@ pub fn rewrite_associated_type(prefix: &str, if let Some(ty) = ty_opt { let ty_str = try_opt!(ty.rewrite(context, context.config.max_width - context.block_indent.width() - - prefix.len() - 2, + prefix.len() - + 2, context.block_indent)); Some(format!("{} = {};", prefix, ty_str)) } else { @@ -1083,7 +1082,8 @@ pub fn rewrite_associated_static(prefix: &str, let lhs = format!("{}{} =", prefix, ty_str); // 1 = ; let remaining_width = context.config.max_width - context.block_indent.width() - 1; - rewrite_assign_rhs(context, lhs, expr, remaining_width, context.block_indent).map(|s| s + ";") + rewrite_assign_rhs(context, lhs, expr, remaining_width, context.block_indent) + .map(|s| s + ";") } else { let lhs = format!("{}{};", prefix, ty_str); Some(lhs) @@ -1740,7 +1740,6 @@ fn rewrite_where_clause(context: &RewriteContext, config: context.config, }; let preds_str = try_opt!(write_list(&item_vec, &fmt)); - println!("{:?}", preds_str); let end_length = if terminator == "{" { // If the brace is on the next line we don't need to count it otherwise it needs two diff --git a/src/visitor.rs b/src/visitor.rs index 2339a47dd21..5db7b396032 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -21,7 +21,8 @@ use config::Config; use rewrite::{Rewrite, RewriteContext}; use comment::rewrite_comment; use macros::rewrite_macro; -use items::{rewrite_static, rewrite_associated_static, rewrite_associated_type, rewrite_type_alias, format_impl, format_trait}; +use items::{rewrite_static, rewrite_associated_static, rewrite_associated_type, + rewrite_type_alias, format_impl, format_trait}; pub struct FmtVisitor<'a> { pub parse_session: &'a ParseSess, @@ -316,12 +317,12 @@ impl<'a> FmtVisitor<'a> { match ti.node { ast::TraitItemKind::Const(ref ty, ref expr) => { let rewrite = rewrite_associated_static("const", - ast::Visibility::Inherited, - ti.ident, - ty, - ast::Mutability::Immutable, - expr, - &self.get_context()); + ast::Visibility::Inherited, + ti.ident, + ty, + ast::Mutability::Immutable, + expr, + &self.get_context()); self.push_rewrite(ti.span, rewrite); } ast::TraitItemKind::Method(ref sig, None) => { diff --git a/tests/source/impls.rs b/tests/source/impls.rs index d04b5ce1eeb..9f34db7ae07 100644 --- a/tests/source/impls.rs +++ b/tests/source/impls.rs @@ -1,6 +1,10 @@ impl Foo for Bar { fn foo() { "hi" } } pub impl Foo for Bar { + // Associated Constants + const Baz: i32 = 16; + // Associated Types + type FooBar = usize; // Comment 1 fn foo() { "hi" } // Comment 2 @@ -9,20 +13,20 @@ pub impl Foo for Bar { } pub unsafe impl<'a, 'b, X, Y: Foo> !Foo<'a, X> for Bar<'b, Y> where X: Foo<'a, Z> { - fn foo() { "hi" } + fn foo() { "hi" } } impl<'a, 'b, X, Y: Foo> Foo<'a, X> for Bar<'b, Y> where X: Fooooooooooooooooooooooooooooo<'a, Z> { - fn foo() { "hi" } + fn foo() { "hi" } } impl<'a, 'b, X, Y: Foo> Foo<'a, X> for Bar<'b, Y> where X: Foooooooooooooooooooooooooooo<'a, Z> { - fn foo() { "hi" } + fn foo() { "hi" } } -impl Foo for Bar where T: Baz +impl Foo for Bar where T: Baz { } @@ -38,8 +42,8 @@ impl Boo { fn boo() {} // FOO - - + + } mod a { diff --git a/tests/source/trait.rs b/tests/source/trait.rs index 49b314358f2..3fb6a1b85e2 100644 --- a/tests/source/trait.rs +++ b/tests/source/trait.rs @@ -37,3 +37,9 @@ trait Test { } trait T<> {} + +trait Foo { type Bar: Baz;} + +trait ConstCheck:Foo where T: Baz { + const J: i32; +} diff --git a/tests/source/where-trailing-comma.rs b/tests/source/where-trailing-comma.rs index 8f951d199e4..c2c1a3185bc 100644 --- a/tests/source/where-trailing-comma.rs +++ b/tests/source/where-trailing-comma.rs @@ -20,7 +20,7 @@ struct Pair where T: P, S: P + Q { struct TupPair (S, T) where T: P, S: P + Q; -enum E where S: P, T: P { +enum E where S: P, T: P { A {a: T}, } @@ -30,7 +30,6 @@ extern "C" { fn f(x: T, y: S) -> T where T: P, S: Q; } -// Note: trait declarations are not fully formatted (issue #78) trait Q where T: P, S: R { fn f(self, x: T, y: S, z: U) -> Self where U: P, V: P; diff --git a/tests/target/impls.rs b/tests/target/impls.rs index 33bc7481905..c81de4d40fe 100644 --- a/tests/target/impls.rs +++ b/tests/target/impls.rs @@ -5,6 +5,10 @@ impl Foo for Bar { } pub impl Foo for Bar { + // Associated Constants + const Baz: i32 = 16; + // Associated Types + type FooBar = usize; // Comment 1 fn foo() { "hi" diff --git a/tests/target/trait.rs b/tests/target/trait.rs index 32389431284..f784fa14530 100644 --- a/tests/target/trait.rs +++ b/tests/target/trait.rs @@ -36,3 +36,12 @@ trait Test { } trait T {} + +trait Foo { + type Bar: Baz; +} + +trait ConstCheck: Foo where T: Baz +{ + const J: i32; +} diff --git a/tests/target/where-trailing-comma.rs b/tests/target/where-trailing-comma.rs index bd7108f992a..c8682237ae6 100644 --- a/tests/target/where-trailing-comma.rs +++ b/tests/target/where-trailing-comma.rs @@ -48,8 +48,9 @@ extern "C" { S: Q; } -// Note: trait declarations are not fully formatted (issue #78) -trait Q where T: P, S: R +trait Q + where T: P, + S: R, { fn f(self, x: T, y: S, z: U) -> Self where U: P,