Esempio n. 1
0
func TestCreateElement(t *testing.T) {
	assert.Equal(t, meta.DirectTypeOf(meta.CreateElement([]Foo{}).Interface()).String(), "meta_test.Foo")
	assert.Equal(t, meta.DirectTypeOf(meta.CreateElement([]*Foo{}).Interface()).String(), "*meta_test.Foo")
	assert.Equal(t, meta.DirectTypeOf(meta.CreateElement(&[]Foo{}).Interface()).String(), "meta_test.Foo")
	assert.Equal(t, meta.DirectTypeOf(meta.CreateElement(&[]*Foo{}).Interface()).String(), "*meta_test.Foo")
	assert.Equal(t, meta.DirectTypeOf(meta.CreateElement(FooPTRSlice{}).Interface()).String(), "*meta_test.Foo")
	assert.Equal(t, meta.DirectTypeOf(meta.CreateElement(&FooPTRSlice{}).Interface()).String(), "*meta_test.Foo")
	assert.Equal(t, meta.DirectTypeOf(meta.CreateElement([]string{}).Interface()).String(), "string")
}
Esempio n. 2
0
func TestSliceOf(t *testing.T) {
	a := meta.SliceOf(123).Interface().([]int)
	assert.Equal(t, len(a), 1)
	assert.Equal(t, a[0], 123)

	b := meta.SliceOf(Foo{}).Interface().([]Foo)
	assert.Equal(t, len(b), 1)
	assert.Equal(t, meta.DirectTypeOf(b[0]).String(), "meta_test.Foo")

	r := &Foo{}
	c := meta.SliceOf(r).Interface().([]*Foo)
	assert.Equal(t, len(c), 1)
	assert.Equal(t, meta.DirectTypeOf(c[0]).String(), "*meta_test.Foo")
	assert.Equal(t, c[0], r)

	var e *Foo
	d := meta.SliceOf(e).Interface().([]*Foo)
	assert.Equal(t, len(d), 1)
	assert.Equal(t, meta.DirectTypeOf(d[0]).String(), "*meta_test.Foo")
	assert.Equal(t, d[0], e)
}