|
3 | 3 |
|
4 | 4 | import test from 'tape'; |
5 | 5 | import {findDefaultColorField, createNewDataEntry} from '@kepler.gl/utils'; |
| 6 | +import {isHexWkb, isWkt} from '@kepler.gl/common-utils'; |
6 | 7 |
|
7 | 8 | import {processCsvData} from '@kepler.gl/processors'; |
8 | 9 |
|
@@ -88,4 +89,42 @@ test('datasetUtils.isHexWkb', t => { |
88 | 89 |
|
89 | 90 | const validEWktNDR = '0020000001000013ff0000000000400000000000000040'; |
90 | 91 | t.ok(isHexWkb(validEWktNDR), 'A valid hex ewkb in NDR should be valid'); |
| 92 | + t.end(); |
| 93 | +}); |
| 94 | + |
| 95 | +test('datasetUtils.isWkt', t => { |
| 96 | + // non-strings |
| 97 | + t.notOk(isWkt(null), 'null is not a valid WKT'); |
| 98 | + t.notOk(isWkt(undefined), 'undefined is not a valid WKT'); |
| 99 | + t.notOk(isWkt(123), 'number is not a valid WKT'); |
| 100 | + t.notOk(isWkt({}), 'object is not a valid WKT'); |
| 101 | + |
| 102 | + // regular strings / known non-WKT identifiers |
| 103 | + t.notOk(isWkt(''), 'empty string is not a valid WKT'); |
| 104 | + t.notOk(isWkt('hello world'), 'regular string is not a valid WKT'); |
| 105 | + t.notOk(isWkt('06075'), 'FIPS code should not be a valid WKT'); |
| 106 | + t.notOk(isWkt('8a2a1072b59ffff'), 'H3 code should not be a valid WKT'); |
| 107 | + |
| 108 | + // edge cases (missing coordinates / parentheses) |
| 109 | + t.notOk(isWkt('POINT'), 'POINT without coordinates should not be a valid WKT'); |
| 110 | + t.notOk(isWkt('POINT 1 2'), 'POINT without parentheses should not be a valid WKT'); |
| 111 | + t.notOk(isWkt('SRID=4326;POINT'), 'SRID prefix without geometry should not be a valid WKT'); |
| 112 | + t.notOk(isWkt('POINT (1 2'), 'missing closing parenthesis should not be a valid WKT'); |
| 113 | + t.notOk(isWkt('POINT ( )'), 'empty coordinates should not be a valid WKT'); |
| 114 | + |
| 115 | + // valid WKT examples (heuristic) |
| 116 | + t.ok(isWkt('POINT (1 2)'), 'POINT should be recognized as WKT'); |
| 117 | + t.ok(isWkt('POINT(1 2)'), 'POINT without space before parentheses should be recognized as WKT'); |
| 118 | + t.ok(isWkt('LINESTRING (0 0, 1 1)'), 'LINESTRING should be recognized as WKT'); |
| 119 | + t.ok(isWkt('POLYGON ((0 0, 1 0, 1 1, 0 0))'), 'POLYGON should be recognized as WKT'); |
| 120 | + t.ok( |
| 121 | + isWkt('SRID=4326;POINT(1 2)'), |
| 122 | + 'WKT with SRID prefix should be recognized as WKT' |
| 123 | + ); |
| 124 | + t.ok(isWkt('POINT Z (1 2 3)'), 'WKT with Z dimension should be recognized as WKT'); |
| 125 | + |
| 126 | + // not WKT but contains parentheses |
| 127 | + t.notOk(isWkt('HELLO (1 2)'), 'non-WKT string with parentheses should not be valid WKT'); |
| 128 | + |
| 129 | + t.end(); |
91 | 130 | }); |
0 commit comments