forked from rust-postgres/rust-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
33 lines (28 loc) · 859 Bytes
/
Copy pathlib.rs
File metadata and controls
33 lines (28 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#![cfg(test)]
use postgres::Client;
use postgres_types::{FromSqlOwned, ToSql};
use std::fmt;
mod composites;
mod domains;
mod enums;
mod transparent;
pub fn test_type<T, S>(conn: &mut Client, sql_type: &str, checks: &[(T, S)])
where
T: PartialEq + FromSqlOwned + ToSql + Sync,
S: fmt::Display,
{
for &(ref val, ref repr) in checks.iter() {
let stmt = conn
.prepare(&*format!("SELECT {}::{}", *repr, sql_type))
.unwrap();
let result = conn.query_one(&stmt, &[]).unwrap().get(0);
assert_eq!(val, &result);
let stmt = conn.prepare(&*format!("SELECT $1::{}", sql_type)).unwrap();
let result = conn.query_one(&stmt, &[val]).unwrap().get(0);
assert_eq!(val, &result);
}
}
#[test]
fn compile_fail() {
trybuild::TestCases::new().compile_fail("src/compile-fail/*.rs");
}