Esempio n. 1
0
func TestMalms(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"malms": {
				"a": {
					"b": {"type":"simple", "js": "c"},
					"d": {"type":"simple", "js": "e"}
				},
				"f": {
					"g": {"type":"simple", "js": "h"},
					"i": {"type":"simple", "js": "j"}
				}
			}
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			require.Len(t, v.(*data.Multi).Malms, 2)
			require.Len(t, v.(*data.Multi).Malms["a"], 2)
			require.Len(t, v.(*data.Multi).Malms["f"], 2)
			assert.Equal(t, "c", v.(*data.Multi).Malms["a"]["b"].Js)
			assert.Equal(t, "e", v.(*data.Multi).Malms["a"]["d"].Js)
			assert.Equal(t, "h", v.(*data.Multi).Malms["f"]["g"].Js)
			assert.Equal(t, "j", v.(*data.Multi).Malms["f"]["i"].Js)
		}),
	)
}
Esempio n. 2
0
func TestRi(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"ri": {"type": "system:@string", "default": "a"}
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			assert.Equal(t, "a", v.(*data.Multi).Ri.(*system.StringRule).Default.Value())
		}),
	)
}
Esempio n. 3
0
func TestSp(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"sp": {"type": "system:package", "recursive": true}
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			assert.Equal(t, true, v.(*data.Multi).Sp.Recursive)
		}),
	)
}
Esempio n. 4
0
func TestNri2(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"nri": {"type": "aljn2", "value": 1.1}
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			assert.NotNil(t, v.(*data.Multi).Nri)
			assert.Equal(t, 1.1, v.(*data.Multi).Nri.GetNumber(ctx).Value())
		}),
	)
}
Esempio n. 5
0
func TestSri2(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"sri": {"type": "aljs2", "value": "a"}
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			assert.NotNil(t, v.(*data.Multi).Sri)
			assert.Equal(t, "a", v.(*data.Multi).Sri.GetString(ctx).Value())
		}),
	)
}
Esempio n. 6
0
func TestI(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"i": {"type": "facea", "a": "b"}
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			assert.NotNil(t, v.(*data.Multi).I)
			assert.Equal(t, "b", v.(*data.Multi).I.Face())
		}),
	)
}
Esempio n. 7
0
func TestBri2(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"bri": {"type": "aljb2", "value": true}
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			assert.NotNil(t, v.(*data.Multi).Bri)
			assert.Equal(t, true, v.(*data.Multi).Bri.GetBool(ctx).Value())
		}),
	)
}
Esempio n. 8
0
func TestAljn(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"aljn": 1.1
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			assert.NotNil(t, v.(*data.Multi).Aljn)
			assert.Equal(t, 1.1, v.(*data.Multi).Aljn.Value())
		}),
	)
}
Esempio n. 9
0
func TestAls(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"als": {"type": "als", "js": "a"}
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			assert.NotNil(t, v.(*data.Multi).Als)
			assert.Equal(t, "a", v.(*data.Multi).Als.Js)
		}),
	)
}
Esempio n. 10
0
func TestSr(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"sr": "a"
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			assert.Equal(t, "kego.io/tests/data", v.(*data.Multi).Sr.Package)
			assert.Equal(t, "a", v.(*data.Multi).Sr.Name)
		}),
	)
}
Esempio n. 11
0
func TestAljbi(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"aljbi": true
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			assert.NotNil(t, v.(*data.Multi).Aljbi.GetAljb(ctx))
			assert.IsType(t, new(data.Aljb), v.(*data.Multi).Aljbi)
			assert.Equal(t, true, v.(*data.Multi).Aljbi.GetAljb(ctx).Value())
		}),
	)
}
Esempio n. 12
0
func TestAjb(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"ajb": [true, false]
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			require.Len(t, v.(*data.Multi).Ajb, 2)
			assert.Equal(t, true, v.(*data.Multi).Ajb[0])
			assert.Equal(t, false, v.(*data.Multi).Ajb[1])
		}),
	)
}
Esempio n. 13
0
func TestAjn(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"ajn": [1.1, 1.2]
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			require.Len(t, v.(*data.Multi).Ajn, 2)
			assert.Equal(t, 1.1, v.(*data.Multi).Ajn[0])
			assert.Equal(t, 1.2, v.(*data.Multi).Ajn[1])
		}),
	)
}
Esempio n. 14
0
func TestAalss(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"aalss": ["a", "b"]
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			require.Len(t, v.(*data.Multi).Aalss, 2)
			assert.Equal(t, "a", v.(*data.Multi).Aalss[0].Value())
			assert.Equal(t, "b", v.(*data.Multi).Aalss[1].Value())
		}),
	)
}
Esempio n. 15
0
func TestMjb(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"mjb": {"a": true, "b": false}
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			require.Len(t, v.(*data.Multi).Mjb, 2)
			assert.Equal(t, true, v.(*data.Multi).Mjb["a"])
			assert.Equal(t, false, v.(*data.Multi).Mjb["b"])
		}),
	)
}
Esempio n. 16
0
func TestMjn(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"mjn": {"a": 1.1, "b": 1.2}
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			require.Len(t, v.(*data.Multi).Mjn, 2)
			assert.Equal(t, 1.1, v.(*data.Multi).Mjn["a"])
			assert.Equal(t, 1.2, v.(*data.Multi).Mjn["b"])
		}),
	)
}
Esempio n. 17
0
func TestAsi(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"asi": [2, 3]
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			require.Len(t, v.(*data.Multi).Asi, 2)
			assert.Equal(t, 2, v.(*data.Multi).Asi[0].Value())
			assert.Equal(t, 3, v.(*data.Multi).Asi[1].Value())
		}),
	)
}
Esempio n. 18
0
func TestMsi(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"msi": {"a": 2, "b": 3}
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			require.Len(t, v.(*data.Multi).Msi, 2)
			assert.Equal(t, 2, v.(*data.Multi).Msi["a"].Value())
			assert.Equal(t, 3, v.(*data.Multi).Msi["b"].Value())
		}),
	)
}
Esempio n. 19
0
func TestMjs(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"mjs": {"a": "b", "c": "d"}
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			require.Len(t, v.(*data.Multi).Mjs, 2)
			assert.Equal(t, "b", v.(*data.Multi).Mjs["a"])
			assert.Equal(t, "d", v.(*data.Multi).Mjs["c"])
		}),
	)
}
Esempio n. 20
0
func TestMsr(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"msr": {"a": "a", "b": "system:b"}
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			require.Len(t, v.(*data.Multi).Msr, 2)
			assert.Equal(t, "kego.io/tests/data:a", v.(*data.Multi).Msr["a"].Value())
			assert.Equal(t, "kego.io/system:b", v.(*data.Multi).Msr["b"].Value())
		}),
	)
}
Esempio n. 21
0
func TestAlmjsiError(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, so this throws an error.
	Run(t, ctx, `{
			"type": "multi",
			"almjsi": {"a": "b", "c": "d"}
		}`,
		UnmarshalError(func(t *testing.T, err error) {
			require.IsError(t, err, "SVXYHJWMOC")
			require.HasError(t, err, "RXEPCCGFKV")
		}),
	)
}
Esempio n. 22
0
func TestAlsError(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	// Type must be als when unpacking into als, even if it's an alias
	// of simple
	Run(t, ctx, `{
			"type": "multi",
			"als": {"type": "simple", "js": "a"}
		}`,
		UnmarshalError(func(t *testing.T, err error) {
			require.IsError(t, err, "SVXYHJWMOC")
			require.HasError(t, err, "BNHVLQPFKC")
		}),
	)
}
Esempio n. 23
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"])
		}),
	)
}
Esempio n. 24
0
func TestAljni2(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	// Aljn2 is another alias number type that implements the Aljn default
	// interface.
	Run(t, ctx, `{
			"type": "multi",
			"aljni": {"type": "aljn2", "value": 1.1}
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			assert.NotNil(t, v.(*data.Multi).Aljni.GetAljn(ctx))
			assert.IsType(t, new(data.Aljn2), v.(*data.Multi).Aljni)
			assert.Equal(t, 1.1, v.(*data.Multi).Aljni.GetAljn(ctx).Value())
		}),
	)
}
Esempio n. 25
0
func TestAljbi2(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	// aljb2 is another alias bool type that implements the aljb default
	// interface.
	Run(t, ctx, `{
			"type": "multi",
			"aljbi": {"type": "aljb2", "value": true}
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			assert.NotNil(t, v.(*data.Multi).Aljbi.GetAljb(ctx))
			assert.IsType(t, new(data.Aljb2), v.(*data.Multi).Aljbi)
			assert.Equal(t, true, v.(*data.Multi).Aljbi.GetAljb(ctx).Value())
		}),
	)
}
Esempio n. 26
0
func TestJbJnJs(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"jb": true,
			"jn": 1.1,
			"js": "a"
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			assert.Equal(t, true, v.(*data.Multi).Jb)
			assert.Equal(t, 1.1, v.(*data.Multi).Jn)
			assert.Equal(t, "a", v.(*data.Multi).Js)
		}),
	)
}
Esempio n. 27
0
func TestSbSnSs(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"sb": true,
			"sn": 1.1,
			"ss": "a"
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			assert.Equal(t, true, v.(*data.Multi).Sb.Value())
			assert.Equal(t, 1.1, v.(*data.Multi).Sn.Value())
			assert.Equal(t, "a", v.(*data.Multi).Ss.Value())
		}),
	)
}
Esempio n. 28
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])
		}),
	)
}
Esempio n. 29
0
func TestAlas(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"alas": [
				{"type":"simple", "js": "a"},
				{"type":"simple", "js": "b"}
			]
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			require.Len(t, v.(*data.Multi).Alas, 2)
			assert.Equal(t, "a", v.(*data.Multi).Alas[0].Js)
			assert.Equal(t, "b", v.(*data.Multi).Alas[1].Js)
		}),
	)
}
Esempio n. 30
0
func TestMsp(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	Run(t, ctx, `{
			"type": "multi",
			"msp": {
				"a": {"type": "system:package", "recursive": true},
				"b": {"type": "system:package"}
			}
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			require.Len(t, v.(*data.Multi).Msp, 2)
			assert.Equal(t, true, v.(*data.Multi).Msp["a"].Recursive)
			assert.Equal(t, false, v.(*data.Multi).Msp["b"].Recursive)
		}),
	)
}