Added tests

This commit is contained in:
Connor Brewster 2016-03-14 20:05:20 -06:00
parent 7ba43ff06e
commit 2793b4090c
8 changed files with 46 additions and 23 deletions

View File

@ -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::<Vec<String>>()
.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

View File

@ -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) => {

View File

@ -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<Bar>> !Foo<'a, X> for Bar<'b, Y> where X: Foo<'a, Z> {
fn foo() { "hi" }
fn foo() { "hi" }
}
impl<'a, 'b, X, Y: Foo<Bar>> Foo<'a, X> for Bar<'b, Y> where X: Fooooooooooooooooooooooooooooo<'a, Z>
{
fn foo() { "hi" }
fn foo() { "hi" }
}
impl<'a, 'b, X, Y: Foo<Bar>> Foo<'a, X> for Bar<'b, Y> where X: Foooooooooooooooooooooooooooo<'a, Z>
{
fn foo() { "hi" }
fn foo() { "hi" }
}
impl<T> Foo for Bar<T> where T: Baz
impl<T> Foo for Bar<T> where T: Baz
{
}
@ -38,8 +42,8 @@ impl Boo {
fn boo() {}
// FOO
}
mod a {

View File

@ -37,3 +37,9 @@ trait Test {
}
trait T<> {}
trait Foo { type Bar: Baz;}
trait ConstCheck<T>:Foo where T: Baz {
const J: i32;
}

View File

@ -20,7 +20,7 @@ struct Pair<S, T> where T: P, S: P + Q {
struct TupPair<S, T> (S, T) where T: P, S: P + Q;
enum E<S, T> where S: P, T: P {
enum E<S, T> where S: P, T: P {
A {a: T},
}
@ -30,7 +30,6 @@ extern "C" {
fn f<S, T>(x: T, y: S) -> T where T: P, S: Q;
}
// Note: trait declarations are not fully formatted (issue #78)
trait Q<S, T> where T: P, S: R
{
fn f<U, V>(self, x: T, y: S, z: U) -> Self where U: P, V: P;

View File

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

View File

@ -36,3 +36,12 @@ trait Test {
}
trait T {}
trait Foo {
type Bar: Baz;
}
trait ConstCheck<T>: Foo where T: Baz
{
const J: i32;
}

View File

@ -48,8 +48,9 @@ extern "C" {
S: Q;
}
// Note: trait declarations are not fully formatted (issue #78)
trait Q<S, T> where T: P, S: R
trait Q<S, T>
where T: P,
S: R,
{
fn f<U, V>(self, x: T, y: S, z: U) -> Self
where U: P,