github.com/dgraph-io/dgraph@v1.2.8/types/s2_test.go (about) 1 /* 2 * Copyright 2017-2018 Dgraph Labs, Inc. and Contributors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package types 18 19 import ( 20 "testing" 21 22 "github.com/stretchr/testify/require" 23 geom "github.com/twpayne/go-geom" 24 "github.com/twpayne/go-geom/encoding/geojson" 25 ) 26 27 func TestConvertToGeoJson_Point(t *testing.T) { 28 s := `[1.0, 2.0] ` 29 b, err := convertToGeom(s) 30 require.NoError(t, err) 31 require.Equal(t, geom.Coord{1, 2}, b.(*geom.Point).Coords()) 32 } 33 34 func TestConvertToGeoJson_Poly(t *testing.T) { 35 s := `[[[1.123, 2.543], [-3.23, 4.123], [4.43, -6.123], [1.123, 2.543]]]` 36 b, err := convertToGeom(s) 37 require.NoError(t, err) 38 require.Equal(t, 39 [][]geom.Coord{{{1.123, 2.543}, {-3.23, 4.123}, {4.43, -6.123}, {1.123, 2.543}}}, 40 b.(*geom.Polygon).Coords()) 41 _, err = geojson.Marshal(b) 42 require.NoError(t, err) 43 } 44 45 func TestConvertToGeoJson_PolyError1(t *testing.T) { 46 s := `[[1.76, -2.234], [3.543, 4.534], [4.54, 6.213]]` 47 _, err := convertToGeom(s) 48 require.Error(t, err) 49 } 50 51 func TestConvertToGeoJson_PolyError2(t *testing.T) { 52 s := `[[1.253, 2.2343], [-4.563, 6.1231], []]` 53 _, err := convertToGeom(s) 54 require.Error(t, err) 55 }