mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-29 03:08:47 -06:00
Factor Blob back out into a method of String, rather than embedded. Embedding makes branching on nom type hard.
This commit is contained in:
@@ -3,7 +3,6 @@ package store
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha1"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
||||
@@ -45,7 +44,6 @@ func (w *memoryChunkWriter) Ref() (ref.Ref, error) {
|
||||
if w.ms.data == nil {
|
||||
w.ms.data = map[ref.Ref][]byte{}
|
||||
}
|
||||
fmt.Println(string(w.buf.Bytes()))
|
||||
w.ms.data[r] = w.buf.Bytes()
|
||||
w.Close()
|
||||
return r, nil
|
||||
|
||||
@@ -4,6 +4,7 @@ import "io"
|
||||
|
||||
type Blob interface {
|
||||
Value
|
||||
// TODO: Rename just Len()
|
||||
ByteLen() uint64
|
||||
Read() io.Reader
|
||||
}
|
||||
|
||||
@@ -85,7 +85,8 @@ func TestFlatMapIter(t *testing.T) {
|
||||
stop = true
|
||||
m.Iter(cb)
|
||||
assert.Equal(1, len(got))
|
||||
assert.True(Int32(0).Equals(got["a"]))
|
||||
// Iteration order not guaranteed, but it has to be one of these.
|
||||
assert.True(Int32(0).Equals(got["a"]) || Int32(1).Equals(got["b"]))
|
||||
}
|
||||
|
||||
func TestFlatMapEquals(t *testing.T) {
|
||||
|
||||
@@ -1,9 +1,22 @@
|
||||
package types
|
||||
|
||||
// Stupid inefficient temporary implementation of the String interface.
|
||||
type flatString struct {
|
||||
flatBlob
|
||||
s string
|
||||
}
|
||||
|
||||
func (fs flatString) Blob() Blob {
|
||||
return NewBlob([]byte(fs.s))
|
||||
}
|
||||
|
||||
func (fs flatString) String() string {
|
||||
return string(fs.data)
|
||||
return fs.s
|
||||
}
|
||||
|
||||
func (fs flatString) Equals(other Value) bool {
|
||||
if other, ok := other.(String); ok {
|
||||
return fs.String() == other.String()
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,21 +12,6 @@ func TestNewStringIsFlatString(t *testing.T) {
|
||||
assert.IsType(s, flatString{})
|
||||
}
|
||||
|
||||
func TestStringFromBytes(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
s := StringFromBytes([]byte("foo"))
|
||||
assert.IsType(s, flatString{})
|
||||
assert.Equal("foo", s.String())
|
||||
}
|
||||
|
||||
func TestFlatStringLen(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
s1 := NewString("foo")
|
||||
s2 := NewString("⌘")
|
||||
assert.Equal(uint64(3), uint64(s1.ByteLen()))
|
||||
assert.Equal(uint64(3), uint64(s2.ByteLen()))
|
||||
}
|
||||
|
||||
func TestFlatStringEquals(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
s1 := NewString("foo")
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
package types
|
||||
|
||||
type String interface {
|
||||
Blob
|
||||
Value
|
||||
|
||||
Blob() Blob
|
||||
|
||||
// Slurps the entire string into memory. You obviously don't want to do this if the string might be large.
|
||||
String() string
|
||||
}
|
||||
|
||||
func NewString(s string) String {
|
||||
return flatString{flatBlob{[]byte(s)}}
|
||||
}
|
||||
|
||||
func StringFromBytes(b []byte) String {
|
||||
return flatString{flatBlob{b}}
|
||||
return flatString{s}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user