mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-21 05:07:33 +00:00
[Go] Implements a SharedStrings function (#5733)
* Adds the sharedstring implementation for go * Reimplemented testcase according to request
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
7cdfc8475e
commit
a593a11e59
@@ -28,6 +28,7 @@ import (
|
||||
"reflect"
|
||||
"sort"
|
||||
"testing"
|
||||
"testing/quick"
|
||||
|
||||
flatbuffers "github.com/google/flatbuffers/go"
|
||||
)
|
||||
@@ -77,7 +78,8 @@ func TestAll(t *testing.T) {
|
||||
CheckByteStringIsNestedError(t.Fatalf)
|
||||
CheckStructIsNotInlineError(t.Fatalf)
|
||||
CheckFinishedBytesError(t.Fatalf)
|
||||
|
||||
CheckSharedStrings(t.Fatalf)
|
||||
|
||||
// Verify that GetRootAs works for non-root tables
|
||||
CheckGetRootAsForNonRootTable(t.Fatalf)
|
||||
CheckTableAccessors(t.Fatalf)
|
||||
@@ -1375,6 +1377,29 @@ func CheckStringIsNestedError(fail func(string, ...interface{})) {
|
||||
b.CreateString("foo")
|
||||
}
|
||||
|
||||
func CheckSharedStrings(fail func(string, ...interface{})) {
|
||||
f := func(strings []string) bool {
|
||||
b := flatbuffers.NewBuilder(0)
|
||||
for _, s1 := range strings {
|
||||
for _, s2 := range strings {
|
||||
off1 := b.CreateSharedString(s1)
|
||||
off2 := b.CreateSharedString(s2)
|
||||
|
||||
if (s1 == s2) && (off1 != off2) {
|
||||
return false
|
||||
}
|
||||
if (s1 != s2) && (off1 == off2) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
if err := quick.Check(f, nil); err != nil {
|
||||
fail("expected same offset")
|
||||
}
|
||||
}
|
||||
|
||||
// CheckByteStringIsNestedError verifies that a bytestring can not be created
|
||||
// inside another object.
|
||||
func CheckByteStringIsNestedError(fail func(string, ...interface{})) {
|
||||
|
||||
Reference in New Issue
Block a user