Exemple #1
0
func TestEnumIsValue(t *testing.T) {
	ds := datas.NewDataStore(chunks.NewMemoryStore())
	var v types.Value = gen.NewEnumStruct()
	ref := ds.WriteValue(v).TargetRef()
	v2 := ds.ReadValue(ref)
	assert.True(t, v.Equals(v2))
}
Exemple #2
0
func TestValue(t *testing.T) {
	assert := assert.New(t)

	def := gen.StructDef{"hi", true}
	var st types.Value
	st = def.New()
	st2 := st.(gen.Struct)
	assert.True(st.Equals(st2))
}
Exemple #3
0
func TestEnumValue(t *testing.T) {
	assert := assert.New(t)

	def := gen.EnumStructDef{gen.Switch}
	var st types.Value
	st = def.New()
	st2 := st.(gen.EnumStruct)
	assert.True(st.Equals(st2))
}
Exemple #4
0
func TestValueMapValue(t *testing.T) {
	assert := assert.New(t)

	def := gen.MapOfStringToValueDef{"s": types.NewString("s"), "i": types.Int32(42)}
	var m types.Value
	m = def.New()
	m2 := m.(gen.MapOfStringToValue)
	assert.True(m.Equals(m2))
}
Exemple #5
0
func TestReadWriteCache(t *testing.T) {
	assert := assert.New(t)
	cs := chunks.NewTestStore()
	ds := NewDataStore(cs)

	var v types.Value = types.Bool(true)
	assert.NotEqual(ref.Ref{}, ds.WriteValue(v))
	assert.Equal(1, cs.Writes)
	r := ds.WriteValue(v).TargetRef()
	assert.Equal(1, cs.Writes)

	v = ds.ReadValue(r)
	assert.True(v.Equals(types.Bool(true)))
}
func TestStructIsValue(t *testing.T) {
	assert := assert.New(t)
	ds := datas.NewDataStore(chunks.NewMemoryStore())
	var v types.Value = gen.StructWithListDef{
		L: gen.ListOfUint8Def{0, 1, 2},
		B: true,
		S: "world",
		I: 42,
	}.New()

	ref := ds.WriteValue(v).TargetRef()
	v2 := ds.ReadValue(ref)
	assert.True(v.Equals(v2))

	s2 := v2.(gen.StructWithList)
	assert.True(s2.L().Equals(gen.NewListOfUint8().Append(0, 1, 2)))
	assert.True(s2.B())
	assert.Equal("world", s2.S())
	assert.Equal(int64(42), s2.I())
}