MCPcopy
hub / github.com/cayleygraph/cayley / TestLoadTypedQuads

Function TestLoadTypedQuads

graph/graphtest/graphtest.go:775–843  ·  view source on GitHub ↗
(t testing.TB, gen testutil.DatabaseFunc, conf *Config)

Source from the content-addressed store, hash-verified

773}
774
775func TestLoadTypedQuads(t testing.TB, gen testutil.DatabaseFunc, conf *Config) {
776 qs, opts, closer := gen(t)
777 defer closer()
778
779 w := testutil.MakeWriter(t, qs, opts)
780
781 values := []quad.Value{
782 quad.BNode("A"), quad.IRI("name"), quad.String("B"), quad.IRI("graph"),
783 quad.IRI("B"), quad.Raw("<type>"),
784 quad.TypedString{Value: "10", Type: "int"},
785 quad.LangString{Value: "value", Lang: "en"},
786 quad.Int(-123456789),
787 quad.Float(-12345e-6),
788 quad.Bool(true),
789 quad.Time(time.Now()),
790 }
791
792 err := w.AddQuadSet([]quad.Quad{
793 {values[0], values[1], values[2], values[3]},
794 {values[4], values[5], values[6], nil},
795 {values[4], values[5], values[7], nil},
796 {values[0], values[1], values[8], nil},
797 {values[0], values[1], values[9], nil},
798 {values[0], values[1], values[10], nil},
799 {values[0], values[1], values[11], nil},
800 })
801 require.NoError(t, err)
802 for _, pq := range values {
803 got := qs.NameOf(qs.ValueOf(pq))
804 if !conf.UnTyped {
805 if pt, ok := pq.(quad.Time); ok {
806 var trim int64
807 if conf.TimeInMcs {
808 trim = 1000
809 } else if conf.TimeInMs {
810 trim = 1000000
811 }
812 if trim > 0 {
813 tm := time.Time(pt)
814 seconds := tm.Unix()
815 nanos := int64(tm.Sub(time.Unix(seconds, 0)))
816 if conf.TimeRound {
817 nanos = (nanos/trim + ((nanos/(trim/10))%10)/5) * trim
818 } else {
819 nanos = (nanos / trim) * trim
820 }
821 pq = quad.Time(time.Unix(seconds, nanos).UTC())
822 }
823 }
824 if eq, ok := pq.(quad.Equaler); ok {
825 assert.True(t, eq.Equal(got), "Failed to roundtrip %q (%T), got %q (%T)", pq, pq, got, got)
826 } else {
827 assert.Equal(t, pq, got, "Failed to roundtrip %q (%T)", pq, pq)
828 }
829 // check if we can get received value again (hash roundtrip)
830 got2 := qs.NameOf(qs.ValueOf(got))
831 assert.Equal(t, got, got2, "Failed to use returned value to get it again")
832 } else {

Callers

nothing calls this directly

Calls 6

MakeWriterFunction · 0.92
StringMethod · 0.65
AddQuadSetMethod · 0.65
NameOfMethod · 0.65
ValueOfMethod · 0.65
StatsMethod · 0.65

Tested by

no test coverage detected