func TestNode_Unpack5(t *testing.T) { cb := tests.Context("kego.io/tests/data").Jauto().Sauto(parser.Parse) s := `{ "type": "multi", "sri": {"type":"system:string", "value": "b"}, "nri": {"type":"system:number", "value": 2}, "bri": {"type":"system:bool", "value": true}, "aljbi": {"type":"aljb", "value": true}, "aljni": {"type":"aljn", "value": 3.0}, "aljsi": {"type":"aljs", "value": "aljs2"} }` n := node.NewNode() err := n.Unpack(cb.Ctx(), system.MustPackString(s), false) require.NoError(t, err) assert.Equal(t, "b", n.Value.(*data.Multi).Sri.GetString(cb.Ctx()).Value()) assert.Equal(t, 2.0, n.Value.(*data.Multi).Nri.GetNumber(cb.Ctx()).Value()) assert.Equal(t, true, n.Value.(*data.Multi).Bri.GetBool(cb.Ctx()).Value()) assert.Equal(t, data.Aljb(true), *n.Value.(*data.Multi).Aljbi.GetAljb(cb.Ctx())) assert.Equal(t, data.Aljn(3.0), *n.Value.(*data.Multi).Aljni.GetAljn(cb.Ctx())) assert.Equal(t, data.Aljs("aljs2"), *n.Value.(*data.Multi).Aljsi.GetAljs(cb.Ctx())) }
func TestNode_extractType(t *testing.T) { r := &system.RuleWrapper{ Struct: &system.Rule{Interface: true}, Parent: &system.Type{Interface: true}, } _, err := extractType(context.Background(), system.Pack(nil), r) assert.IsError(t, err, "TDXTPGVFAK") ty, err := extractType(context.Background(), nil, nil) require.NoError(t, err) assert.Nil(t, ty) r = &system.RuleWrapper{ Parent: &system.Type{Interface: true}, } _, err = extractType(context.Background(), system.Pack(""), r) assert.IsError(t, err, "DLSQRFLINL") r = &system.RuleWrapper{ Struct: &system.Rule{Interface: true}, } ty, err = extractType(context.Background(), nil, r) require.NoError(t, err) assert.Nil(t, ty) r = &system.RuleWrapper{ Struct: &system.Rule{Interface: true}, } _, err = extractType(context.Background(), system.MustPackString(`[""]`), r) assert.IsError(t, err, "SNYLGBJYTM") _, err = extractType(context.Background(), system.MustPackString(`{}`), nil) assert.IsError(t, err, "HBJVDKAKBJ") r = &system.RuleWrapper{ Parent: &system.Type{Interface: true}, } _, err = extractType(context.Background(), system.MustPackString(`{}`), r) assert.IsError(t, err, "HBJVDKAKBJ") cb := tests.Context("a.b/c").Sempty() _, err = extractType(cb.Ctx(), system.MustPackString(`{"type": "a"}`), nil) assert.IsError(t, err, "IJFMJJWVCA") }
func TestNode_Unpack3(t *testing.T) { cb := tests.Context("kego.io/tests/data").Jauto().Sauto(parser.Parse) s := `{ "type": "multi", "a": "b" }` n := node.NewNode() err := n.Unpack(cb.Ctx(), system.MustPackString(s), false) assert.HasError(t, err, "SRANLETJRS") }
func Empty(t *testing.T) (*tests.ContextBuilder, *node.Node) { cb := tests.Context("kego.io/tests/data").Jauto().Sauto(parser.Parse) s := `{ "type": "multi", "m": { "type": "multi" }, "am": [ { "type": "multi" }, { "type": "multi" } ], "mm": { "a": { "type": "multi" }, "b": { "type": "multi" } } }` n := node.NewNode() require.NoError(t, n.Unpack(cb.Ctx(), system.MustPackString(s), false)) return cb, n }
func TestNode_Unpack(t *testing.T) { cb := tests.Context("kego.io/tests/data").Jauto().Sauto(parser.Parse) s := `{ "type": "multi", "js": "a" }` n := node.NewNode() require.NoError(t, n.Unpack(cb.Ctx(), system.MustPackString(s), false)) m, ok := n.Value.(*data.Multi) require.True(t, ok) assert.Equal(t, "a", m.Js) }
func Setup(t *testing.T) (*tests.ContextBuilder, *node.Node) { simple := false if !simple { cb := tests.Context("kego.io/tests/data").Jauto().Sauto(parser.Parse) m := `"type": "multi", "js": "js1", "ss": "ss1", "sr": "sr1", "jn": 1.1, "sn": 1.2, "jb": true, "sb": false, "alajs": ["alajs0", "alajs1", "alajs2"], "alas": [{"type": "simple", "js": "alas0"}, {"type": "simple", "js": "alas1"}], "alass": ["alass0", "alass1", "alass2"], "aljb": true, "aljn": 2.0, "aljs": "aljs", "almjs": {"a": "almjsa", "b": "almjsb"}, "alms": {"a": {"type": "simple", "js": "almsa"}, "b": {"type": "simple", "js": "almsb"}}, "almss": {"a": "almssa", "b": "almssb"}, "alss": "alss", "als": {"type": "als", "js": "als"}, "i": { "type": "facea", "a": "ia" }, "ajs": [ "ajs0", "ajs1", "ajs2", "ajs3" ], "ass": [ "ass0", "ass1", "ass2", "ass3" ], "ajn": [ 2.1, 2.2, 2.3, 2.4 ], "asn": [ 3.1, 3.2, 3.3, 3.4 ], "ajb": [ true, false, false, false ], "asb": [ false, true, false, false ], "mjs": { "a": "mjsa", "b": "mjsb" }, "mss": { "a": "mssa", "b": "mssb" }, "mjn": { "a": 4.1, "b": 4.2 }, "msn": { "a": 5.1, "b": 5.2 }, "mjb": { "a": true, "b": false }, "msb": { "a": false, "b": true }, "anri": [ "anri0", { "type": "facea", "a": "anri1" }, { "type": "multi", "ss": "anri2" } ], "mnri": { "a": "mnria", "b": { "type": "facea", "a": "mnrib" }, "c": { "type": "multi", "ss": "mnric" } } ` mm := m + `, "m": { "type": "multi" }, "am": [ { "type": "multi", "js": "amjs0" }, { "type": "multi", "js": "amjs1" } ], "mm": { "a": { "type": "multi", "js": "mmjsa" }, "b": { "type": "multi", "js": "mmjsb" } }` s := `{ ` + m + `, "m": {` + mm + `}, "am": [ {` + mm + `}, {` + mm + `} ], "mm": { "a": {` + mm + `}, "b": {` + mm + `} } }` n := node.NewNode() require.NoError(t, n.Unpack(cb.Ctx(), system.MustPackString(s), false)) return cb, n } else { cb := tests.Context("kego.io/tests/data").Jauto().Sauto(parser.Parse) m := `"type": "multi", "alms": {"a": {"type": "simple", "js": "almsa"}, "b": {"type": "simple", "js": "almsb"}} ` mm := m + `, "m": { "type": "multi" }, "am": [ { "type": "multi", "js": "amjs0" }, { "type": "multi", "js": "amjs1" } ], "mm": { "a": { "type": "multi", "js": "mmjsa" }, "b": { "type": "multi", "js": "mmjsb" } }` s := `{ ` + m + `, "m": {` + mm + `}, "am": [ {` + mm + `}, {` + mm + `} ], "mm": { "a": {` + mm + `}, "b": {` + mm + `} } }` n := node.NewNode() require.NoError(t, n.Unpack(cb.Ctx(), system.MustPackString(s), false)) return cb, n } }