Пример #1
0
func NewSong() Song {
	return Song{
		_Title:  "",
		_Artist: "",
		_Album:  "",
		_Year:   "",
		_Mp3:    types.NewEmptyBlob(),

		ref: &ref.Ref{},
	}
}
Пример #2
0
func TestStructWithUnionFieldListPart(t *testing.T) {
	assert := assert.New(t)

	st := gen.NewStructWithUnionField().SetF(gen.SetOfUint8Def{2: true, 4: true}.New())
	f, ok := st.F()
	assert.True(ok)
	assert.True(f.Has(2))
	assert.False(f.Has(1))

	st2 := st.SetF(f)
	assert.True(st.Equals(st2))

	st3 := st.SetD(types.NewEmptyBlob())
	assert.False(st.Equals(st3))
	_, ok = st3.F()
	assert.False(ok)
}
Пример #3
0
func TestReadValueTypeRefPanics_BUG1121(t *testing.T) {
	assert := assert.New(t)
	cs := chunks.NewTestStore()
	ds := NewDataStore(cs)

	b := types.NewEmptyBlob()
	assert.NotEqual(ref.Ref{}, ds.WriteValue(b))

	datasetID := "ds1"
	aCommit := NewCommit().SetValue(types.NewRef(b.Ref()))
	ds2, err := ds.Commit(datasetID, aCommit)
	assert.NoError(err)

	_, ok := ds2.MaybeHead(datasetID)
	assert.True(ok)
	// Fix BUG 1121 and then uncomment this line and delete the one after
	// assert.NotPanics(func() { ds2.WriteValue(types.NewRefOfBlob(b.Ref())) })
	assert.Panics(func() { ds2.WriteValue(types.NewRefOfBlob(b.Ref())) })
}
Пример #4
0
func NewStructPrimitives() StructPrimitives {
	return StructPrimitives{
		_uint64:  uint64(0),
		_uint32:  uint32(0),
		_uint16:  uint16(0),
		_uint8:   uint8(0),
		_int64:   int64(0),
		_int32:   int32(0),
		_int16:   int16(0),
		_int8:    int8(0),
		_float64: float64(0),
		_float32: float32(0),
		_bool:    false,
		_string:  "",
		_blob:    types.NewEmptyBlob(),
		_value:   types.Bool(false),

		ref: &ref.Ref{},
	}
}
Пример #5
0
func TestAccessors(t *testing.T) {
	assert := assert.New(t)

	def := gen.StructPrimitivesDef{
		Uint64:  uint64(1),
		Uint32:  uint32(2),
		Uint16:  uint16(3),
		Uint8:   uint8(4),
		Int64:   int64(5),
		Int32:   int32(6),
		Int16:   int16(7),
		Int8:    int8(8),
		Float64: float64(9),
		Float32: float32(10),
		Bool:    bool(false),
		String:  string("hi"),
		Blob:    types.NewEmptyBlob(),
		Value:   types.Bool(false),
	}

	st := def.New()

	assert.Equal(uint64(1), st.Uint64())
	st.SetUint64(uint64(11))
	assert.Equal(uint64(1), st.Uint64())
	st = st.SetUint64(uint64(11))
	assert.Equal(uint64(11), st.Uint64())

	assert.Equal(uint32(2), st.Uint32())
	st.SetUint32(uint32(22))
	assert.Equal(uint32(2), st.Uint32())
	st = st.SetUint32(uint32(22))
	assert.Equal(uint32(22), st.Uint32())

	assert.Equal(uint16(3), st.Uint16())
	st.SetUint16(uint16(33))
	assert.Equal(uint16(3), st.Uint16())
	st = st.SetUint16(uint16(33))
	assert.Equal(uint16(33), st.Uint16())

	assert.Equal(uint8(4), st.Uint8())
	st.SetUint8(uint8(44))
	assert.Equal(uint8(4), st.Uint8())
	st = st.SetUint8(uint8(44))
	assert.Equal(uint8(44), st.Uint8())

	assert.Equal(int64(5), st.Int64())
	st.SetInt64(int64(55))
	assert.Equal(int64(5), st.Int64())
	st = st.SetInt64(int64(55))
	assert.Equal(int64(55), st.Int64())

	assert.Equal(int32(6), st.Int32())
	st.SetInt32(int32(66))
	assert.Equal(int32(6), st.Int32())
	st = st.SetInt32(int32(66))
	assert.Equal(int32(66), st.Int32())

	assert.Equal(int16(7), st.Int16())
	st.SetInt16(int16(77))
	assert.Equal(int16(7), st.Int16())
	st = st.SetInt16(int16(77))
	assert.Equal(int16(77), st.Int16())

	assert.Equal(int8(8), st.Int8())
	st.SetInt8(int8(88))
	assert.Equal(int8(8), st.Int8())
	st = st.SetInt8(int8(88))
	assert.Equal(int8(88), st.Int8())

	assert.Equal(float64(9), st.Float64())
	st.SetFloat64(float64(99))
	assert.Equal(float64(9), st.Float64())
	st = st.SetFloat64(float64(99))
	assert.Equal(float64(99), st.Float64())

	assert.Equal(float32(10), st.Float32())
	st.SetFloat32(float32(1010))
	assert.Equal(float32(10), st.Float32())
	st = st.SetFloat32(float32(1010))
	assert.Equal(float32(1010), st.Float32())

	assert.Equal(false, st.Bool())
	st.SetBool(true)
	assert.Equal(false, st.Bool())
	st = st.SetBool(true)
	assert.Equal(true, st.Bool())

	assert.Equal("hi", st.String())
	st.SetString("bye")
	assert.Equal("hi", st.String())
	st = st.SetString("bye")
	assert.Equal("bye", st.String())

	assert.True(st.Blob().Equals(types.NewEmptyBlob()))
	b := types.NewBlob(strings.NewReader("hello"))
	st.SetBlob(b)
	assert.True(st.Blob().Equals(types.NewEmptyBlob()))
	st = st.SetBlob(b)
	assert.True(st.Blob().Equals(b))

	assert.True(st.Value().Equals(types.Bool(false)))
	st.SetValue(types.NewString("x"))
	assert.True(st.Value().Equals(types.Bool(false)))
	st = st.SetValue(types.NewString("x"))
	assert.True(st.Value().Equals(types.NewString("x")))
}