mirror of
https://github.com/hanzoai/graph.git
synced 2026-10-30 18:35:37 +00:00
Derived from Dgraph (github.com/dgraph-io/dgraph) at commit 64804bd2, Apache-2.0. See NOTICE. WHAT THIS IS. The graph engine as a Go library: posting lists, the DQL parser, the type and tokenizer system, the index and schema layers, and the wire types. 39,170 lines of the upstream's 166,337. THE STORE is github.com/luxfi/zapdb, a Badger fork that kept the package name, the subpackages (options, pb, y) and the API — Open, OpenManaged, DB, Options — so the 74 import sites are aliased rather than rewritten. THE CODEC is ZAP. zapdb serializes with ZAP, not protobuf: its pb package builds the ZAP types by default and the protobuf ones only under `-tags grpc`, a path that does not compile (table/builder.go calls pb.Marshal, which that tag removes). One call site in posting needed converting; every other type here is Hanzo's own protobuf and is untouched. NO TRANSPORT. An embedded engine dials nothing, so nothing here imports google.golang.org/grpc. Removed: 20 transport functions in x, the generated service stubs for Raft, Zero and Worker (1,657 lines), and the JWT helper — identity belongs to IAM. The core called none of them. NOT KEPT: worker, conn, raftwal, the cluster commands, the GraphQL layer and the test harnesses. `query`, the DQL execution engine, went with them because it depends on worker; parsing DQL is available here, executing it is not. The history of the upstream project lives at github.com/dgraph-io/dgraph. This repository begins at the derivation because three quarters of that history describes code this fork does not carry.
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
/*
|
|
* SPDX-FileCopyrightText: © 2017-2026 Istari Digital, Inc.
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
package types
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestParse(t *testing.T) {
|
|
array := []string{
|
|
`{'type':'Point','coordinates':[1,2]}`,
|
|
`{'type':'MultiLineString','coordinates':[[[1,2,3],[4,5,6],[7,8,9],[1,2,3]]]}`,
|
|
}
|
|
for _, v := range array {
|
|
src := Val{StringID, []byte(v)}
|
|
|
|
if g, err := Convert(src, GeoID); err != nil {
|
|
t.Errorf("Error parsing %s: %v", v, err)
|
|
} else {
|
|
// Marshal it back to text
|
|
got := ValueForType(StringID)
|
|
if err := Marshal(g, &got); err != nil || got.Value.(string) != v {
|
|
t.Errorf("Marshal error expected %s, got %s. error %v", v, got.Value.(string), err)
|
|
}
|
|
|
|
wkb := ValueForType(BinaryID)
|
|
// Marshal and unmarshal to WKB
|
|
if err := Marshal(g, &wkb); err != nil {
|
|
t.Errorf("Error marshaling to WKB: %v", err)
|
|
}
|
|
|
|
src := Val{GeoID, wkb.Value.([]byte)}
|
|
if bg, err := Convert(src, GeoID); err != nil {
|
|
t.Errorf("Error unmarshaling WKB: %v", err)
|
|
} else if !reflect.DeepEqual(g, bg) {
|
|
t.Errorf("Expected %#v, got %#v", g, bg)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestParseGeoJsonErrors(t *testing.T) {
|
|
array := []string{
|
|
`{"type":"Curve","coordinates":[1,2]}`,
|
|
`{"type":"Feature","geometry":{"type":"Point","coordinates":[125.6,10.1]},"properties":{"name":"Dinagat Islands"}}`,
|
|
`{}`,
|
|
`thisisntjson`,
|
|
}
|
|
for _, v := range array {
|
|
src := Val{StringID, []byte(v)}
|
|
if _, err := Convert(src, GeoID); err == nil {
|
|
t.Errorf("Expected error parsing %s: %v", v, err)
|
|
}
|
|
}
|
|
}
|