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.
73 lines
1.5 KiB
Go
73 lines
1.5 KiB
Go
/*
|
|
* SPDX-FileCopyrightText: © 2017-2026 Istari Digital, Inc.
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
package types
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestTypeForValue(t *testing.T) {
|
|
tests := []struct {
|
|
in string
|
|
out TypeID
|
|
}{
|
|
{`true`, BoolID},
|
|
{`TRUE`, BoolID},
|
|
{`True`, BoolID},
|
|
{`t`, DefaultID},
|
|
{`false`, BoolID},
|
|
{`FALSE`, BoolID},
|
|
{`False`, BoolID},
|
|
{`f`, DefaultID},
|
|
{`2018`, IntID},
|
|
{`2018-10`, DateTimeID},
|
|
{`2018-10-03`, DateTimeID},
|
|
{`2018-10-03T20:47:53Z`, DateTimeID},
|
|
{`123`, IntID},
|
|
{`-123`, IntID},
|
|
{`+123`, IntID},
|
|
{`0001`, IntID},
|
|
{`+0`, IntID},
|
|
{`-0`, IntID},
|
|
{`1World`, DefaultID},
|
|
{`3.14159`, FloatID},
|
|
{`-273.15`, FloatID},
|
|
{`2.99792e8`, FloatID},
|
|
{`9.1095E-28`, FloatID},
|
|
{`-.0`, FloatID},
|
|
{`+.0`, FloatID},
|
|
{`.1`, FloatID},
|
|
{`1.`, FloatID},
|
|
{`1-800-4GOLANG`, DefaultID},
|
|
{`+1800-446-5264`, DefaultID},
|
|
{`212.555.9876`, DefaultID},
|
|
{`testing`, DefaultID},
|
|
}
|
|
for _, tc := range tests {
|
|
out, _ := TypeForValue([]byte(tc.in))
|
|
require.Equal(t, tc.out, out, "%s != %s", tc.in, tc.out.Enum())
|
|
}
|
|
}
|
|
|
|
func TestFloatArrayTranslation(t *testing.T) {
|
|
testCases := [][]float32{
|
|
{},
|
|
{0.1},
|
|
{0},
|
|
{0.65433, 1.855, 3.1415926539},
|
|
}
|
|
for _, tc := range testCases {
|
|
asBytes := FloatArrayAsBytes(tc)
|
|
asFloat32 := BytesAsFloatArray(asBytes)
|
|
require.Equal(t, len(tc), len(asFloat32))
|
|
for i := range tc {
|
|
require.Equal(t, tc[i], asFloat32[i])
|
|
}
|
|
}
|
|
}
|