Skip to content

Commit

Permalink
test: array match for geo arrays geo match for geo only
Browse files Browse the repository at this point in the history
  • Loading branch information
jayy-lmao committed Nov 6, 2024
1 parent 83dcf2a commit ece19be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 14 additions & 1 deletion sqlx-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,17 @@ macro_rules! test_type {
}
};

($name:ident<$ty:ty>($db:ident, $($text:literal @= $value:expr),+ $(,)?)) => {
($name:ident<$ty:ty>($db:ident, $($text:literal ~= $value:expr),+ $(,)?)) => {
paste::item! {
$crate::__test_prepared_type!($name<$ty>($db, $crate::[< $db _query_for_test_prepared_geometric_type >]!(), $($text == $value),+));
}
};
($name:ident<$ty:ty>($db:ident, $($text:literal = $value:expr),+ $(,)?)) => {
paste::item! {
$crate::__test_prepared_type!($name<$ty>($db, $crate::[< $db _query_for_test_prepared_geometric_type >]!(), $($text == $value),+));
}
};


($name:ident($db:ident, $($text:literal == $value:expr),+ $(,)?)) => {
$crate::test_type!($name<$name>($db, $($text == $value),+));
Expand Down Expand Up @@ -233,6 +239,13 @@ macro_rules! Postgres_query_for_test_prepared_type {

#[macro_export]
macro_rules! Postgres_query_for_test_prepared_geometric_type {
() => {
"SELECT ({0} ~= $1)::int4, {0}, $2"
};
}

#[macro_export]
macro_rules! Postgres_query_for_test_prepared_geometric_array_type {
() => {
"SELECT ({0} = $1)::int4, {0}, $2"
};
Expand Down
6 changes: 3 additions & 3 deletions tests/postgres/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,13 @@ test_type!(_cube<Vec<sqlx::postgres::types::PgCube>>(Postgres,

#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))]
test_type!(point<sqlx::postgres::types::PgPoint>(Postgres,
"point(2.2,-3.4)" @= sqlx::postgres::types::PgPoint { x: 2.2, y:-3.4 },
"point(2.2,-3.4)" ~= sqlx::postgres::types::PgPoint { x: 2.2, y:-3.4 },
));

#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))]
test_type!(_point<Vec<sqlx::postgres::types::PgPoint>>(Postgres,
"array[point(2,3),point(2.1,3.4)]" @= vec![sqlx::postgres::types::PgPoint { x:2., y: 3. }, sqlx::postgres::types::PgPoint { x:2.1, y: 3.4 }],
"array[point(2.2,-3.4)]" @= vec![sqlx::postgres::types::PgPoint { x: 2.2, y: -3.4 }],
"array[point(2,3),point(2.1,3.4)]" = vec![sqlx::postgres::types::PgPoint { x:2., y: 3. }, sqlx::postgres::types::PgPoint { x:2.1, y: 3.4 }],
"array[point(2.2,-3.4)]" = vec![sqlx::postgres::types::PgPoint { x: 2.2, y: -3.4 }],
));

#[cfg(feature = "rust_decimal")]
Expand Down

0 comments on commit ece19be

Please sign in to comment.