diff --git a/store/memory_store.go b/store/memory_store.go index a401cc5435..c769a21304 100644 --- a/store/memory_store.go +++ b/store/memory_store.go @@ -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 diff --git a/types/blob.go b/types/blob.go index c3994a2d00..abd5467194 100644 --- a/types/blob.go +++ b/types/blob.go @@ -4,6 +4,7 @@ import "io" type Blob interface { Value + // TODO: Rename just Len() ByteLen() uint64 Read() io.Reader } diff --git a/types/flat_map_test.go b/types/flat_map_test.go index a8cac149e7..f4b0ce40c3 100644 --- a/types/flat_map_test.go +++ b/types/flat_map_test.go @@ -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) { diff --git a/types/flat_string.go b/types/flat_string.go index 32bbe35d9d..c01986ec2a 100644 --- a/types/flat_string.go +++ b/types/flat_string.go @@ -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 + } } diff --git a/types/flat_string_test.go b/types/flat_string_test.go index 9c643a0104..afe92e0a69 100644 --- a/types/flat_string_test.go +++ b/types/flat_string_test.go @@ -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") diff --git a/types/string.go b/types/string.go index 3fd81a5cd6..a591c6567f 100644 --- a/types/string.go +++ b/types/string.go @@ -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} }