Skip to content

Commit e9445b7

Browse files
killercupweiznich
authored andcommitted
Add more infer schema tests
1 parent 118ae38 commit e9445b7

1 file changed

Lines changed: 58 additions & 11 deletions

File tree

diesel_cli/src/pretty_printing.rs

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ mod tests {
9191
use super::format_schema;
9292

9393
macro_rules! test_pretty_printing {
94-
($($name: ident: $input: expr => $expected: expr);*) => {
94+
($($name:ident: $input:expr => $expected:expr);*) => {
9595
$(
9696
#[test]
9797
fn $name() {
@@ -101,22 +101,68 @@ mod tests {
101101
)*
102102
}
103103
}
104+
104105
test_pretty_printing! {
105-
test_remove_whitespace_colon: ":: diesel :: types :: Text" =>
106+
test_increase_indent:
107+
"{" =>
108+
"{\n ";
109+
110+
test_decrease_indent:
111+
"{abc,}" =>
112+
"{\n abc,\n}\n";
113+
114+
test_newline_after_comma:
115+
"," =>
116+
",\n";
117+
118+
test_newline_after_semicolon:
119+
";" =>
120+
";\n";
121+
122+
test_remove_whitespace_macro_call:
123+
"table ! { }" =>
124+
"table! {\n}\n";
125+
126+
test_remove_whitespace_path_segments:
127+
":: diesel :: types :: Text" =>
106128
"::diesel::types::Text";
107-
test_format_nullable: "Nullable < :: diesel :: types :: Text >" =>
129+
130+
test_remove_whitespace_parenthesis:
131+
"foo ( 42 )" =>
132+
"foo(42)";
133+
134+
test_remove_whitespace_angular_brackets:
135+
"Option < i32 >" =>
136+
"Option<i32>";
137+
138+
test_remove_whitespace_before_comma:
139+
"id -> Int4 , username -> Varchar" =>
140+
"id -> Int4,\nusername -> Varchar";
141+
142+
test_format_nullable:
143+
"Nullable < :: diesel :: types :: Text >" =>
108144
"Nullable<::diesel::types::Text>";
109-
test_format_nullable_multispace: "Nullable < Integer >" => "Nullable<Integer>";
110-
test_newline_after_comma: "," => ",\n";
111-
test_increase_indent: "{" => "{\n ";
112-
test_decrease_indent: "{abc,}" => "{\n abc,\n}\n";
113-
test_format_arrow: "created_at -> :: diesel :: types :: Timestamp" =>
145+
146+
test_format_nullable_multispace:
147+
"Nullable < Integer >" =>
148+
"Nullable<Integer>";
149+
150+
test_format_arrow:
151+
"created_at -> :: diesel :: types :: Timestamp" =>
114152
"created_at -> ::diesel::types::Timestamp";
115-
test_format_full_line: "created_at -> :: diesel :: types :: Timestamp ," =>
153+
154+
test_format_full_line:
155+
"created_at -> :: diesel :: types :: Timestamp ," =>
116156
"created_at -> ::diesel::types::Timestamp,\n";
117-
test_format_include_line: "pub use self :: infer_locks :: * ;" =>
157+
158+
test_format_include_line:
159+
"pub use self :: infer_locks :: * ;" =>
118160
"pub use self::infer_locks::*;\n";
119-
test_format_generated_mod: "mod infer_users { table ! { users ( id ) { id -> :: diesel :: types :: Int4 , username -> :: diesel :: types :: Varchar , password -> :: diesel :: types :: Varchar , } } } pub use self :: infer_users :: * ;" =>
161+
162+
test_format_generated_mod:
163+
"mod infer_users { table ! { users ( id ) { id -> :: diesel :: types :: Int4 , \
164+
username -> :: diesel :: types :: Varchar , password -> :: diesel :: types :: Varchar \
165+
, } } } pub use self :: infer_users :: * ;" =>
120166
r"mod infer_users {
121167
table! {
122168
users(id) {
@@ -128,5 +174,6 @@ r"mod infer_users {
128174
}
129175
pub use self::infer_users::*;
130176
"
177+
131178
}
132179
}

0 commit comments

Comments
 (0)