Ejemplo n.º 1
0
func TestAlmjsi(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	// Note: map alias types in interfaces are always marshalled to explicit
	// object notation.
	Run(t, ctx, `{
			"type": "multi",
			"almjsi": {"type": "almjs", "value": {"a": "b", "c": "d"}}
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			assert.Len(t, v.(*data.Multi).Almjsi.GetAlmjs(ctx), 2)
			assert.Equal(t, "b", v.(*data.Multi).Almjsi.GetAlmjs(ctx)["a"])
			assert.Equal(t, "d", v.(*data.Multi).Almjsi.GetAlmjs(ctx)["c"])
		}),
	)
}
Ejemplo n.º 2
0
func TestAlajsi(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	// Note: array alias types in an interface can be expressed without
	// explicit type notation.
	Run(t, ctx, `{
			"type": "multi",
			"alajsi": ["a", "b"]
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			assert.Len(t, v.(*data.Multi).Alajsi.GetAlajs(ctx), 2)
			assert.Equal(t, "a", v.(*data.Multi).Alajsi.GetAlajs(ctx)[0])
			assert.Equal(t, "b", v.(*data.Multi).Alajsi.GetAlajs(ctx)[1])
		}),
	)
}
Ejemplo n.º 3
0
func TestAlajsiExplicit(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	// Note: array alias types in an interface can be expressed without
	// explicit type notation. Explicit type notation is permitted, but it
	// will marshal back to the bare form.
	Run(t, ctx, `{
			"type": "multi",
			"alajsi": {"type":"alajs", "value": ["a", "b"]}
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			assert.Len(t, v.(*data.Multi).Alajsi.GetAlajs(ctx), 2)
			assert.Equal(t, "a", v.(*data.Multi).Alajsi.GetAlajs(ctx)[0])
			assert.Equal(t, "b", v.(*data.Multi).Alajsi.GetAlajs(ctx)[1])
		}),
		MarshalledString(`{
			"type": "multi",
			"alajsi": ["a", "b"]
		}`),
	)
}