Changed clip errors and json result type

This commit is contained in:
tidwall 2019-02-12 05:33:20 -07:00
parent 62f44ed055
commit fb7259b10b
2 changed files with 17 additions and 11 deletions

View File

@ -1,6 +1,7 @@
// TEST command: spatial tests without walking the tree.
package server
// TEST command: spatial tests without walking the tree.
import (
"bytes"
"fmt"
@ -16,7 +17,7 @@ import (
"github.com/tidwall/tile38/internal/clip"
)
func (s * Server) parseArea(ovs[]string, doClip bool) (vs []string, o geojson.Object, err error) {
func (s *Server) parseArea(ovs []string, doClip bool) (vs []string, o geojson.Object, err error) {
var ok bool
var typ string
vs = ovs[:]
@ -48,7 +49,7 @@ func (s * Server) parseArea(ovs[]string, doClip bool) (vs []string, o geojson.Ob
o = geojson.NewPoint(geometry.Point{X: lon, Y: lat})
case "circle":
if doClip {
err = errInvalidArgument("cannot clip with " + ltyp)
err = fmt.Errorf("invalid clip type '%s'", typ)
return
}
var slat, slon, smeters string
@ -84,7 +85,7 @@ func (s * Server) parseArea(ovs[]string, doClip bool) (vs []string, o geojson.Ob
o = geojson.NewCircle(geometry.Point{X: lon, Y: lat}, meters, defaultCircleSteps)
case "object":
if doClip {
err = errInvalidArgument("cannot clip with " + ltyp)
err = fmt.Errorf("invalid clip type '%s'", typ)
return
}
var obj string
@ -198,7 +199,7 @@ func (s * Server) parseArea(ovs[]string, doClip bool) (vs []string, o geojson.Ob
})
case "get":
if doClip {
err = errInvalidArgument("cannot clip with " + ltyp)
err = fmt.Errorf("invalid clip type '%s'", typ)
return
}
var key, id string
@ -224,7 +225,7 @@ func (s * Server) parseArea(ovs[]string, doClip bool) (vs []string, o geojson.Ob
return
}
func (s *Server) cmdTest (msg *Message) (res resp.Value, err error) {
func (s *Server) cmdTest(msg *Message) (res resp.Value, err error) {
start := time.Now()
vs := msg.Args[1:]
@ -252,7 +253,7 @@ func (s *Server) cmdTest (msg *Message) (res resp.Value, err error) {
case "clip":
vs = nvs
if lTest != "intersects" {
err = errInvalidArgument("cannot clip with" + wtok)
err = errInvalidArgument(wtok)
return
}
doClip = true
@ -282,7 +283,11 @@ func (s *Server) cmdTest (msg *Message) (res resp.Value, err error) {
case JSON:
var buf bytes.Buffer
buf.WriteString(`{"ok":true`)
buf.WriteString(fmt.Sprintf(`,"result":%d`, result))
if result != 0 {
buf.WriteString(`,"result":true`)
} else {
buf.WriteString(`,"result":false`)
}
if clipped != nil {
buf.WriteString(`,"object":` + clipped.JSON())
}

View File

@ -104,9 +104,10 @@ func testcmd_INTERSECTS_CLIP_test(mc *mockServer) error {
return mc.DoBatch([][]interface{}{
{"SET", "mykey", "point1", "POINT", 37.7335, -122.4412}, {"OK"},
{"TEST", "OBJECT", poly9, "INTERSECTS", "CLIP", "OBJECT", "{}"}, {"ERR invalid argument 'cannot clip with object'"},
{"TEST", "OBJECT", poly9, "INTERSECTS", "CLIP", "CIRCLE", "1", "2", "3"}, {"ERR invalid argument 'cannot clip with circle'"},
{"TEST", "OBJECT", poly9, "INTERSECTS", "CLIP", "GET", "mykey", "point1"}, {"ERR invalid argument 'cannot clip with get'"},
{"TEST", "OBJECT", poly9, "INTERSECTS", "CLIP", "OBJECT", "{}"}, {"ERR invalid clip type 'OBJECT'"},
{"TEST", "OBJECT", poly9, "INTERSECTS", "CLIP", "CIRCLE", "1", "2", "3"}, {"ERR invalid clip type 'CIRCLE'"},
{"TEST", "OBJECT", poly9, "INTERSECTS", "CLIP", "GET", "mykey", "point1"}, {"ERR invalid clip type 'GET'"},
{"TEST", "OBJECT", poly9, "WITHIN", "CLIP", "BOUNDS", 10, 10, 20, 20}, {"ERR invalid argument 'CLIP'"},
{"TEST", "OBJECT", poly9, "INTERSECTS", "CLIP", "BOUNDS", 37.732906137107, -122.44126439094543, 37.73421283683962, -122.43980526924135}, {"[1 " + poly9 + "]"},
{"TEST", "OBJECT", poly8, "INTERSECTS", "CLIP", "BOUNDS", 37.733, -122.4408378, 37.7341129, -122.44}, {"[1 " + poly8 + "]"},