|
1 | | -use sqlx_exasol::types::geo_types::{Geometry, Line, LineString, Point}; |
| 1 | +use sqlx::types::geo_types::{GeometryCollection, Rect, Triangle}; |
| 2 | +use sqlx_exasol::types::geo_types::{ |
| 3 | + Geometry, Line, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon, |
| 4 | +}; |
2 | 5 |
|
3 | 6 | use crate::{test_type_array, test_type_valid}; |
4 | 7 |
|
5 | | -// TODO: Write EMPTY types tests too |
| 8 | +test_type_valid!(geometry_point<Geometry>::"GEOMETRY"::( |
| 9 | + "'POINT (1 2)'" => Geometry::Point(Point::new(1.0, 2.0)), |
| 10 | + // This is how [`geo-types`] represents an empty [`Point`]. |
| 11 | + "'POINT EMPTY'" => Geometry::MultiPoint(MultiPoint::<f64>::empty()) |
| 12 | +)); |
| 13 | +test_type_valid!(geometry_linestring<Geometry>::"GEOMETRY"::( |
| 14 | + "'LINESTRING (1 2, 3 4)'" => |
| 15 | + Geometry::LineString(LineString(vec![(1.0, 2.0).into(), (3.0, 4.0).into()])), |
| 16 | + "'LINESTRING EMPTY'" => |
| 17 | + Geometry::LineString(LineString::<f64>::empty()), |
| 18 | + "'LINEARRING (1 2, 3 4, 5 6, 1 2)'" => |
| 19 | + Geometry::LineString(LineString(vec![(1.0, 2.0).into(), (3.0, 4.0).into(), (5.0, 6.0).into(), (1.0, 2.0).into()])), |
| 20 | + "'LINEARRING EMPTY'" => |
| 21 | + Geometry::LineString(LineString::<f64>::empty()) |
| 22 | +)); |
| 23 | +test_type_valid!(geometry_polygon<Geometry>::"GEOMETRY"::( |
| 24 | +"'POLYGON((1 2, 3 4, 5 6, 1 2))'" => |
| 25 | +Geometry::Polygon(Polygon::new( |
| 26 | + LineString(vec![(1.0, 2.0).into(), (3.0, 4.0).into(), (5.0, 6.0).into()]), |
| 27 | + Vec::new()) |
| 28 | +), |
| 29 | +"'POLYGON((5 1, 5 5, 10 5, 5 1), (6 2, 6 3, 7 3, 7 2, 6 2))'" => |
| 30 | +Geometry::Polygon(Polygon::new( |
| 31 | + LineString(vec![(5.0, 1.0).into(), (5.0, 5.0).into(), (10.0, 5.0).into()]), |
| 32 | + vec![LineString(vec![(6.0, 2.0).into(), (6.0, 3.0).into(), (7.0, 3.0).into(), (7.0, 2.0).into()])])), |
| 33 | +"'POLYGON EMPTY'" => |
| 34 | +Geometry::Polygon(Polygon::<f64>::empty()) |
| 35 | +)); |
6 | 36 |
|
7 | | -test_type_valid!(geometry_point<Geometry>::"GEOMETRY"::("'POINT (1 2)'" => Geometry::Point(Point::new(1.0, 2.0)))); |
8 | | -test_type_valid!(geometry_line<Geometry>::"GEOMETRY"::("'LINESTRING (1 2,3 4)'" => Geometry::Line(Line::new((1.0, 2.0), (3.0, 4.0))))); |
9 | | -test_type_valid!(geometry_linestring<Geometry>::"GEOMETRY"::("'LINESTRING (1 2,3 4)'" => Geometry::LineString(LineString(vec![(1.0, 2.0).into(), (3.0, 4.0).into()])))); |
10 | | -// test_type_valid!(geometry_linearring<Geometry>::"GEOMETRY"::("'LINESTRING (1 2,3 4)'" => |
11 | | -// Geometry::LineString(LineString(vec![(1.0, 2.0).into(), (3.0, 4.0).into()])))); test_type_valid! |
12 | | -// (geometry_polygon<Geometry>::"GEOMETRY"::("'LINESTRING (1 2,3 4)'" => |
13 | | -// Geometry::LineString(LineString(vec![(1.0, 2.0).into(), (3.0, 4.0).into()])))); test_type_valid! |
14 | | -// (geometry_multilinestring<Geometry>::"GEOMETRY"::("'LINESTRING (1 2,3 4)'" => |
15 | | -// Geometry::LineString(LineString(vec![(1.0, 2.0).into(), (3.0, 4.0).into()])))); test_type_valid! |
16 | | -// (geometry_multipoint<Geometry>::"GEOMETRY"::("'LINESTRING (1 2,3 4)'" => |
17 | | -// Geometry::LineString(LineString(vec![(1.0, 2.0).into(), (3.0, 4.0).into()])))); test_type_valid! |
18 | | -// (geometry_multipolygon<Geometry>::"GEOMETRY"::("'LINESTRING (1 2,3 4)'" => |
19 | | -// Geometry::LineString(LineString(vec![(1.0, 2.0).into(), (3.0, 4.0).into()])))); test_type_valid! |
20 | | -// (geometry_geometry_collection<Geometry>::"GEOMETRY"::("'LINESTRING (1 2,3 4)'" => |
21 | | -// Geometry::LineString(LineString(vec![(1.0, 2.0).into(), (3.0, 4.0).into()])))); test_type_valid! |
22 | | -// (geometry_rect<Geometry>::"GEOMETRY"::("'LINESTRING (1 2,3 4)'" => |
23 | | -// Geometry::LineString(LineString(vec![(1.0, 2.0).into(), (3.0, 4.0).into()])))); test_type_valid! |
24 | | -// (geometry_triangle<Geometry>::"GEOMETRY"::("'LINESTRING (1 2,3 4)'" => |
25 | | -// Geometry::LineString(LineString(vec![(1.0, 2.0).into(), (3.0, 4.0).into()])))); |
| 37 | +test_type_valid!(geometry_multilinestring<Geometry>::"GEOMETRY"::( |
| 38 | +"'MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))'" => |
| 39 | +Geometry::MultiLineString(MultiLineString::new(vec![ |
| 40 | + LineString(vec![(1.0, 2.0).into(), (3.0, 4.0).into()]), |
| 41 | + LineString(vec![(5.0, 6.0).into(), (7.0, 8.0).into()])])), |
| 42 | +"'MULTILINESTRING EMPTY'" => |
| 43 | +Geometry::MultiLineString(MultiLineString::<f64>::empty()) |
| 44 | +)); |
| 45 | +test_type_valid!(geometry_multipoint<Geometry>::"GEOMETRY"::( |
| 46 | + "'MULTIPOINT (1 2, 3 4)'" => |
| 47 | + Geometry::MultiPoint(MultiPoint::new(vec![Point::new(1.0, 2.0), Point::new(3.0, 4.0)])), |
| 48 | + "'MULTIPOINT EMPTY'" => |
| 49 | + Geometry::MultiPoint(MultiPoint::<f64>::empty()) |
| 50 | +)); |
| 51 | +test_type_valid!(geometry_multipolygon<Geometry>::"GEOMETRY"::( |
| 52 | +"'MULTIPOLYGON (((1 2, 3 4, 5 6, 1 2)), ((5 1, 5 5, 10 5, 5 1), (6 2, 6 3, 7 3, 7 2, 6 2)))'" => |
| 53 | +Geometry::MultiPolygon(MultiPolygon::new(vec![ |
| 54 | + Polygon::new( |
| 55 | + LineString(vec![(1.0, 2.0).into(), (3.0, 4.0).into(), (5.0, 6.0).into()]), |
| 56 | + Vec::new() |
| 57 | + ), |
| 58 | + Polygon::new( |
| 59 | + LineString(vec![(5.0, 1.0).into(), (5.0, 5.0).into(), (10.0, 5.0).into()]), |
| 60 | + vec![LineString(vec![(6.0, 2.0).into(), (6.0, 3.0).into(), (7.0, 3.0).into(), (7.0, 2.0).into()])] |
| 61 | + )])), |
| 62 | +"'MULTIPOLYGON EMPTY'" => |
| 63 | +Geometry::MultiPolygon(MultiPolygon::<f64>::empty()) |
| 64 | +)); |
| 65 | +test_type_valid!(geometry_geometry_collection<Geometry>::"GEOMETRY"::( |
| 66 | +"'GEOMETRYCOLLECTION (POINT(1 2), LINESTRING(1 2, 3 4))'" => |
| 67 | +Geometry::GeometryCollection(GeometryCollection(vec![ |
| 68 | + Geometry::Point(Point::new(1.0, 2.0)), |
| 69 | + Geometry::LineString(LineString(vec![(1.0, 2.0).into(), (3.0, 4.0).into()]))])), |
| 70 | +"'GEOMETRYCOLLECTION EMPTY'" => |
| 71 | +Geometry::GeometryCollection(GeometryCollection::<f64>::empty()) |
| 72 | +)); |
| 73 | + |
| 74 | +test_type_valid!(geometry_linestring_special<Geometry>::"GEOMETRY"::( |
| 75 | + "'LINESTRING (1 2,3 4)'" => |
| 76 | + Geometry::Line(Line::new((1.0, 2.0), (3.0, 4.0))) => |
| 77 | + Geometry::LineString(LineString(vec![(1.0, 2.0).into(), (3.0, 4.0).into()])) |
| 78 | +)); |
| 79 | +test_type_valid!(geometry_polygon_special<Geometry>::"GEOMETRY"::( |
| 80 | +"'POLYGON ((5 1, 5 5, 10 5, 10 1, 5 1))'" => |
| 81 | +Geometry::Rect(Rect::new((5.0, 5.0), (10.0, 1.0))) => |
| 82 | +Geometry::Polygon(Polygon::new( |
| 83 | + LineString(vec![ |
| 84 | + (5.0, 1.0).into(), |
| 85 | + (5.0, 5.0).into(), |
| 86 | + (10.0, 5.0).into(), |
| 87 | + (10.0, 1.0).into(), |
| 88 | + ]), |
| 89 | + Vec::new())) |
| 90 | +)); |
| 91 | + |
| 92 | +// Defined in Counter-ClockWise order (CCW). |
| 93 | +test_type_valid!(geometry_triangle<Geometry>::"GEOMETRY"::( |
| 94 | +"'POLYGON ((10 1, 10 5, 5 1, 10 1))'" => |
| 95 | +Geometry::Triangle(Triangle::new( |
| 96 | + (10.0, 1.0).into(), |
| 97 | + (10.0, 5.0).into(), |
| 98 | + (5.0, 1.0).into(), |
| 99 | +)) => |
| 100 | +Geometry::Polygon(Polygon::new( |
| 101 | + LineString(vec![ |
| 102 | + (10.0, 1.0).into(), |
| 103 | + (10.0, 5.0).into(), |
| 104 | + (5.0, 1.0).into(), |
| 105 | + ]), |
| 106 | + Vec::new())) |
| 107 | +)); |
26 | 108 |
|
27 | 109 | test_type_valid!(geometry_option<Option<Geometry>>::"GEOMETRY"::("''" => None::<Geometry>, "NULL" => None::<Geometry>, "'POINT (1 2)'" => Some(Geometry::Point(Point::new(1.0, 2.0))))); |
28 | 110 |
|
|
0 commit comments