implement fmt.Stringer interface on Tuple
This commit is contained in:
parent
cdeed25f63
commit
16f3a2480b
|
@ -66,6 +66,12 @@ type TupleElement interface{}
|
|||
// packing T (modulo type normalization to []byte, uint64, and int64).
|
||||
type Tuple []TupleElement
|
||||
|
||||
// String implements the fmt.Stringer interface and return the tuple
|
||||
// as a human readable byte string provided by fdb.Printable.
|
||||
func (t Tuple) String() string {
|
||||
return fdb.Printable(t.Pack())
|
||||
}
|
||||
|
||||
// UUID wraps a basic byte array as a UUID. We do not provide any special
|
||||
// methods for accessing or generating the UUID, but as Go does not provide
|
||||
// a built-in UUID type, this simple wrapper allows for other libraries
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"encoding/gob"
|
||||
"flag"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"testing"
|
||||
|
@ -118,3 +119,12 @@ func BenchmarkTuplePacking(b *testing.B) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTupleString(t *testing.T) {
|
||||
printed := fmt.Sprint(Tuple{[]byte("hello"), "world", 42, 0x99})
|
||||
expected := "\\x01hello\\x00\\x02world\\x00\\x15*\\x15\\x99"
|
||||
|
||||
if printed != expected {
|
||||
t.Fatalf("printed tuple result differs, expected %v, got %v", expected, printed)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue