@@ -4,6 +4,10 @@ test_that("regular wkt works", {
44 aa <- check_wkt(' POLYGON((30.1 10.1, 10 20, 20 60, 60 60, 30.1 10.1))' )
55 bb <- check_wkt(' POINT(30.1 10.1)' )
66 cc <- check_wkt(' LINESTRING(3 4,10 50,20 25)' )
7+ mm <- check_wkt(' MULTIPOLYGON (((-86.1328125 59.459488841393735, -56.953125 59.459488841393735, -27.7734375 59.459488841393735, -27.7734375 34.38154915808676, -27.7734375 9.303609474779796, -56.953125 9.303609474779796, -86.1328125 9.303609474779796, -86.1328125 34.38154915808676, -86.1328125 59.459488841393735)), ((78.3984375 54.690225821818856, 56.42578125 45.86648167444278, 34.453125 37.04273752706671, 15.8203125 6.671845441515563, -2.8125 -23.699046644035587, 41.484375 -27.589246771779514, 85.78125 -31.47944689952344, 101.953125 -8.508652190421842, 118.125 14.462142518679757, 112.32421875 36.59973091797452, 106.5234375 58.737319317269275, 106.5234375 58.737319317269275, 106.5234375 58.737319317269275, 92.4609375 56.71377256954406, 78.3984375 54.690225821818856)))' )
8+
9+ expect_is(mm , " character" )
10+ expect_equal(mm , ' MULTIPOLYGON (((-86.1328125 59.459488841393735, -56.953125 59.459488841393735, -27.7734375 59.459488841393735, -27.7734375 34.38154915808676, -27.7734375 9.303609474779796, -56.953125 9.303609474779796, -86.1328125 9.303609474779796, -86.1328125 34.38154915808676, -86.1328125 59.459488841393735)), ((78.3984375 54.690225821818856, 56.42578125 45.86648167444278, 34.453125 37.04273752706671, 15.8203125 6.671845441515563, -2.8125 -23.699046644035587, 41.484375 -27.589246771779514, 85.78125 -31.47944689952344, 101.953125 -8.508652190421842, 118.125 14.462142518679757, 112.32421875 36.59973091797452, 106.5234375 58.737319317269275, 106.5234375 58.737319317269275, 106.5234375 58.737319317269275, 92.4609375 56.71377256954406, 78.3984375 54.690225821818856)))' )
711
812 expect_is(aa , " character" )
913 expect_equal(aa , ' POLYGON((30.1 10.1, 10 20, 20 60, 60 60, 30.1 10.1))' )
@@ -40,10 +44,71 @@ test_that("many wkt's, semi-colon separated, for many repeated geometry args", {
4044
4145
4246test_that(" bad WKT fails well" , {
47+ # Non-numeric coordinates
4348 expect_error(
4449 check_wkt(' POLYGON((30.1 10.1, 10 20, 20 60, 60 60, 30.1 a))' ),
45- " Expected a number but found 'a' at byte 46"
50+ " non_numeric_coordinates; odd_number_of_coordinates"
51+ )
52+
53+ # Unbalanced parentheses - missing closing
54+ expect_error(
55+ check_wkt(' POLYGON((30.1 10.1, 10 20, 20 60, 60 60, 30.1 10.1)' ),
56+ " unbalanced_parentheses"
57+ )
58+
59+ # Unbalanced parentheses - extra closing
60+ expect_error(
61+ check_wkt(' POLYGON((30.1 10.1, 10 20, 20 60, 60 60, 30.1 10.1)))' ),
62+ " unbalanced_parentheses"
63+ )
64+
65+ # Odd number of coordinates
66+ expect_error(
67+ check_wkt(' LINESTRING(10 20, 30 40, 50)' ),
68+ " odd_number_of_coordinates"
69+ )
70+
71+ # Empty coordinate list
72+ expect_error(
73+ check_wkt(' POLYGON(())' ),
74+ " empty_coordinate_list"
75+ )
76+
77+ # Double comma
78+ expect_error(
79+ check_wkt(' LINESTRING(10 20,, 30 40)' ),
80+ " double_comma"
81+ )
82+
83+ # Dangling comma
84+ expect_error(
85+ check_wkt(' POLYGON((30.1 10.1, 10 20, 20 60,))' ),
86+ " dangling_comma"
87+ )
88+
89+ # Invalid geometry type
90+ expect_error(
91+ check_wkt(' INVALIDTYPE((30.1 10.1))' ),
92+ " WKT must be one of the types"
4693 )
4794
95+ # Multiple issues - non-numeric and unbalanced
96+ expect_error(
97+ check_wkt(' POLYGON((30.1 10.1, abc def, 20 60)' ),
98+ " unbalanced_parentheses; non_numeric_coordinates"
99+ )
100+
101+ # Point with multiple coordinates (should be single coordinate pair)
102+ expect_error(
103+ check_wkt(' POINT(30.1 10.1, 20 40, )' ),
104+ " dangling_comma"
105+ )
106+
107+ # Coordinates with letters mixed in
108+ expect_error(
109+ check_wkt(' POLYGON((30.1 10.1, 10x 20, 20 60, 60 60, 30.1 10.1))' ),
110+ " non_numeric_coordinates"
111+ )
112+
48113})
49114
0 commit comments