From 31b90ccc657a5468de6bdffea8d309f502cd0d07 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 21 Jun 2018 12:19:54 +0200 Subject: Fix formatting with cargo fmt --- testing/tests/filters.rs | 29 +++++++++++++++++------------ testing/tests/hello.rs | 3 ++- testing/tests/inheritance.rs | 17 ++++++++++------- testing/tests/loops.rs | 9 ++++++--- testing/tests/matches.rs | 5 +++-- testing/tests/methods.rs | 1 - testing/tests/operators.rs | 2 -- testing/tests/rocket.rs | 2 +- testing/tests/simple.rs | 42 +++++++++++++++++++++--------------------- testing/tests/vars.rs | 6 ++++-- 10 files changed, 64 insertions(+), 52 deletions(-) (limited to 'testing') diff --git a/testing/tests/filters.rs b/testing/tests/filters.rs index fc8c99f..96f03f6 100644 --- a/testing/tests/filters.rs +++ b/testing/tests/filters.rs @@ -6,7 +6,6 @@ extern crate serde_json; use askama::Template; use serde_json::Value; - #[derive(Template)] #[template(path = "filters.html")] struct TestTemplate { @@ -25,7 +24,6 @@ fn filter_escape() { ); } - #[derive(Template)] #[template(path = "format.html", escape = "none")] struct FormatTemplate<'a> { @@ -38,7 +36,6 @@ fn filter_format() { assert_eq!(t.render().unwrap(), "\"formatted\""); } - #[derive(Template)] #[template(source = "{{ s|myfilter }}", ext = "txt")] struct MyFilterTemplate<'a> { @@ -62,7 +59,6 @@ fn test_my_filter() { assert_eq!(t.render().unwrap(), "faa"); } - #[derive(Template)] #[template(path = "filters_join.html")] struct JoinTemplate<'a> { @@ -71,7 +67,9 @@ struct JoinTemplate<'a> { #[test] fn test_join() { - let t = JoinTemplate { s: &["foo", "bar", "bazz"] }; + let t = JoinTemplate { + s: &["foo", "bar", "bazz"], + }; assert_eq!(t.render().unwrap(), "foo, bar, bazz"); } @@ -83,11 +81,12 @@ struct VecJoinTemplate { #[test] fn test_vec_join() { - let t = VecJoinTemplate { s: vec!["foo".into(), "bar".into(), "bazz".into()] }; + let t = VecJoinTemplate { + s: vec!["foo".into(), "bar".into(), "bazz".into()], + }; assert_eq!(t.render().unwrap(), "foo, bar, bazz"); } - #[derive(Template)] #[template(path = "json.html")] struct JsonTemplate<'a> { @@ -98,7 +97,10 @@ struct JsonTemplate<'a> { #[test] fn test_json() { let val = json!({"arr": [ "one", 2, true, null ]}); - let t = JsonTemplate { foo: "a", bar: &val }; + let t = JsonTemplate { + foo: "a", + bar: &val, + }; // Note: the json filter lacks a way to specify initial indentation assert_eq!( t.render().unwrap(), @@ -116,7 +118,6 @@ fn test_json() { ); } - #[derive(Template)] #[template(source = "{{ x|mytrim|safe }}", ext = "html")] struct NestedFilterTemplate { @@ -125,11 +126,12 @@ struct NestedFilterTemplate { #[test] fn test_nested_filter_ref() { - let t = NestedFilterTemplate { x: " floo & bar".to_string() }; + let t = NestedFilterTemplate { + x: " floo & bar".to_string(), + }; assert_eq!(t.render().unwrap(), "floo & bar"); } - #[derive(Template)] #[template(source = "{% let p = baz.print(foo.as_ref()) %}{{ p|upper }}", ext = "html")] struct FilterLetFilterTemplate { @@ -147,6 +149,9 @@ impl Baz { #[test] fn test_filter_let_filter() { - let t = FilterLetFilterTemplate { foo: " bar ".to_owned(), baz: Baz {} }; + let t = FilterLetFilterTemplate { + foo: " bar ".to_owned(), + baz: Baz {}, + }; assert_eq!(t.render().unwrap(), "BAR"); } diff --git a/testing/tests/hello.rs b/testing/tests/hello.rs index 0d0c976..09a2e22 100644 --- a/testing/tests/hello.rs +++ b/testing/tests/hello.rs @@ -6,7 +6,8 @@ use askama::Template; #[derive(Template)] // this will generate the code... #[template(path = "hello.html")] // using the template in this path, relative // to the templates dir in the crate root -struct HelloTemplate<'a> { // the name of the struct can be anything +struct HelloTemplate<'a> { + // the name of the struct can be anything name: &'a str, // the field name should match the variable name // in your template } diff --git a/testing/tests/inheritance.rs b/testing/tests/inheritance.rs index 6e032ba..2fd69c6 100644 --- a/testing/tests/inheritance.rs +++ b/testing/tests/inheritance.rs @@ -23,14 +23,15 @@ fn test_use_base_directly() { #[test] fn test_simple_extends() { - let t = ChildTemplate { _parent: BaseTemplate { title: "Bar" } }; + let t = ChildTemplate { + _parent: BaseTemplate { title: "Bar" }, + }; assert_eq!( t.render().unwrap(), "Bar\n(Bar) Content goes here\nFoo\nCopyright 2017" ); } - pub mod parent { use askama::Template; #[derive(Template)] @@ -41,8 +42,8 @@ pub mod parent { } pub mod child { - use askama::Template; use super::parent::*; + use askama::Template; #[derive(Template)] #[template(path = "child.html")] pub struct ChildTemplate<'a> { @@ -52,15 +53,15 @@ pub mod child { #[test] fn test_different_module() { - let t = child::ChildTemplate { _parent: parent::BaseTemplate { title: "a" } }; + let t = child::ChildTemplate { + _parent: parent::BaseTemplate { title: "a" }, + }; assert_eq!( t.render().unwrap(), "a\n(a) Content goes here\nFoo\nCopyright 2017" ); } - - #[derive(Template)] #[template(path = "nested-base.html")] struct NestedBaseTemplate {} @@ -73,6 +74,8 @@ struct NestedChildTemplate { #[test] fn test_nested_blocks() { - let t = NestedChildTemplate { _parent: NestedBaseTemplate {} }; + let t = NestedChildTemplate { + _parent: NestedBaseTemplate {}, + }; assert_eq!(t.render().unwrap(), "\ndurpy\n"); } diff --git a/testing/tests/loops.rs b/testing/tests/loops.rs index 987f26a..32f0aca 100644 --- a/testing/tests/loops.rs +++ b/testing/tests/loops.rs @@ -11,11 +11,12 @@ struct ForTemplate<'a> { #[test] fn test_for() { - let s = ForTemplate { strings: vec!["A", "alfa", "1"] }; + let s = ForTemplate { + strings: vec!["A", "alfa", "1"], + }; assert_eq!(s.render().unwrap(), "0. A\n1. alfa\n2. 1\n"); } - #[derive(Template)] #[template(path = "nested-for.html")] struct NestedForTemplate<'a> { @@ -26,6 +27,8 @@ struct NestedForTemplate<'a> { fn test_nested_for() { let alpha = vec!["a", "b", "c"]; let numbers = vec!["one", "two"]; - let s = NestedForTemplate { seqs: vec![&alpha, &numbers] }; + let s = NestedForTemplate { + seqs: vec![&alpha, &numbers], + }; assert_eq!(s.render().unwrap(), "1\n 0a1b2c2\n 0one1two"); } diff --git a/testing/tests/matches.rs b/testing/tests/matches.rs index 9fae70c..9ea1d72 100644 --- a/testing/tests/matches.rs +++ b/testing/tests/matches.rs @@ -15,7 +15,6 @@ struct MatchOptRefTemplate<'a> { item: &'a Option<&'a str>, } - #[test] fn test_match_option() { let s = MatchOptTemplate { item: Some("foo") }; @@ -79,7 +78,9 @@ struct MatchCustomEnumTemplate { #[test] fn test_match_custom_enum() { - let s = MatchCustomEnumTemplate { color: Color::Rgb(160, 0, 255) }; + let s = MatchCustomEnumTemplate { + color: Color::Rgb(160, 0, 255), + }; assert_eq!(s.render().unwrap(), "\n\nColorful: #A000FF\n"); } diff --git a/testing/tests/methods.rs b/testing/tests/methods.rs index 5ed5fd1..d1e391f 100644 --- a/testing/tests/methods.rs +++ b/testing/tests/methods.rs @@ -21,7 +21,6 @@ fn test_self_method() { assert_eq!(t.render().unwrap(), "foo"); } - #[derive(Template)] #[template(source = "{{ self.get_s() }} {{ t.get_s() }}", ext = "txt")] struct NestedSelfMethodTemplate<'a> { diff --git a/testing/tests/operators.rs b/testing/tests/operators.rs index de51677..edeb32a 100644 --- a/testing/tests/operators.rs +++ b/testing/tests/operators.rs @@ -17,7 +17,6 @@ fn test_compare() { assert_eq!(t.render().unwrap(), "tf\ntf\ntf\ntf\ntf\ntf"); } - #[derive(Template)] #[template(path = "operators.html")] struct OperatorsTemplate { @@ -32,7 +31,6 @@ fn test_operators() { assert_eq!(t.render().unwrap(), "muldivmodaddrshlshbandbxorborandor"); } - #[derive(Template)] #[template(path = "precedence.html")] struct PrecedenceTemplate {} diff --git a/testing/tests/rocket.rs b/testing/tests/rocket.rs index 19c1d78..c613311 100644 --- a/testing/tests/rocket.rs +++ b/testing/tests/rocket.rs @@ -8,8 +8,8 @@ extern crate rocket; use askama::Template; -use rocket::local::Client; use rocket::http::{ContentType, Status}; +use rocket::local::Client; #[derive(Template)] #[template(path = "hello.html")] diff --git a/testing/tests/simple.rs b/testing/tests/simple.rs index afd82e9..28a6a0a 100644 --- a/testing/tests/simple.rs +++ b/testing/tests/simple.rs @@ -3,7 +3,6 @@ extern crate askama; use askama::Template; - #[derive(Template)] #[template(path = "simple.html")] struct VariablesTemplate<'a> { @@ -28,7 +27,6 @@ fn test_variables() { ); } - #[derive(Template)] #[template(path = "if.html")] struct IfTemplate { @@ -41,7 +39,6 @@ fn test_if() { assert_eq!(s.render().unwrap(), "true"); } - #[derive(Template)] #[template(path = "else.html")] struct ElseTemplate { @@ -54,7 +51,6 @@ fn test_else() { assert_eq!(s.render().unwrap(), "false"); } - #[derive(Template)] #[template(path = "else-if.html")] struct ElseIfTemplate { @@ -64,11 +60,13 @@ struct ElseIfTemplate { #[test] fn test_else_if() { - let s = ElseIfTemplate { cond: false, check: true }; + let s = ElseIfTemplate { + cond: false, + check: true, + }; assert_eq!(s.render().unwrap(), "checked"); } - #[derive(Template)] #[template(path = "literals.html")] struct LiteralsTemplate {} @@ -79,7 +77,6 @@ fn test_literals() { assert_eq!(s.render().unwrap(), "a"); } - struct Holder { a: usize, } @@ -92,7 +89,9 @@ struct AttrTemplate { #[test] fn test_attr() { - let t = AttrTemplate { inner: Holder { a: 5 } }; + let t = AttrTemplate { + inner: Holder { a: 5 }, + }; assert_eq!(t.render().unwrap(), "5"); } @@ -104,11 +103,12 @@ struct TupleAttrTemplate<'a> { #[test] fn test_tuple_attr() { - let t = TupleAttrTemplate { tuple: ("foo", "bar") }; + let t = TupleAttrTemplate { + tuple: ("foo", "bar"), + }; assert_eq!(t.render().unwrap(), "foobar"); } - struct NestedHolder { holder: Holder, } @@ -121,11 +121,14 @@ struct NestedAttrTemplate { #[test] fn test_nested_attr() { - let t = NestedAttrTemplate { inner: NestedHolder { holder: Holder { a: 5 } } }; + let t = NestedAttrTemplate { + inner: NestedHolder { + holder: Holder { a: 5 }, + }, + }; assert_eq!(t.render().unwrap(), "5"); } - #[derive(Template)] #[template(path = "option.html")] struct OptionTemplate<'a> { @@ -140,11 +143,12 @@ fn test_option() { assert_eq!(none.render().unwrap(), "none"); } - #[derive(Template)] #[template(path = "generics.html")] struct GenericsTemplate - where U: std::fmt::Display { +where + U: std::fmt::Display, +{ t: T, u: U, } @@ -155,7 +159,6 @@ fn test_generics() { assert_eq!(t.render().unwrap(), "a42"); } - #[derive(Template)] #[template(path = "composition.html")] struct CompositionTemplate { @@ -164,11 +167,12 @@ struct CompositionTemplate { #[test] fn test_composition() { - let t = CompositionTemplate { foo: IfTemplate { cond: true } }; + let t = CompositionTemplate { + foo: IfTemplate { cond: true }, + }; assert_eq!(t.render().unwrap(), "composed: true"); } - #[derive(PartialEq, Eq)] enum Alphabet { Alpha, @@ -186,7 +190,6 @@ fn test_path_compare() { assert_eq!(t.render().unwrap(), "true"); } - #[derive(Template)] #[template(source = "{% for i in [\"a\", \"\"] %}{{ i }}{% endfor %}", ext = "txt")] struct ArrayTemplate {} @@ -197,7 +200,6 @@ fn test_slice_literal() { assert_eq!(t.render().unwrap(), "a"); } - #[derive(Template)] #[template(source = " {# foo -#} ", ext = "txt")] struct CommentTemplate {} @@ -208,7 +210,6 @@ fn test_comment() { assert_eq!(t.render().unwrap(), " "); } - #[derive(Template)] #[template(source = "{% if !foo %}Hello{% endif %}", ext = "txt")] struct NegationTemplate { @@ -221,7 +222,6 @@ fn test_negation() { assert_eq!(t.render().unwrap(), "Hello"); } - #[derive(Template)] #[template(source = "{% if foo > -2 %}Hello{% endif %}", ext = "txt")] struct MinusTemplate { diff --git a/testing/tests/vars.rs b/testing/tests/vars.rs index 39a1415..81263da 100644 --- a/testing/tests/vars.rs +++ b/testing/tests/vars.rs @@ -15,7 +15,6 @@ fn test_let() { assert_eq!(t.render().unwrap(), "foo"); } - #[derive(Template)] #[template(path = "let-decl.html")] struct LetDeclTemplate<'a> { @@ -25,6 +24,9 @@ struct LetDeclTemplate<'a> { #[test] fn test_let_decl() { - let t = LetDeclTemplate { cond: false, s: "bar" }; + let t = LetDeclTemplate { + cond: false, + s: "bar", + }; assert_eq!(t.render().unwrap(), "bar"); } -- cgit