本文整理汇总了Golang中github.com/davelondon/ktest/assert.NotNil函数的典型用法代码示例。如果您正苦于以下问题:Golang NotNil函数的具体用法?Golang NotNil怎么用?Golang NotNil使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NotNil函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: testType
func testType(t *testing.T, up unpacker.Interface) {
ctx := initialise()
data := `{
"description": "This is the most basic type.",
"type": "type",
"id": "type",
"fields": {
"native": {
"description": "This is the native json type that represents this type. If omitted, default is object.",
"type": "@string",
"enum": ["string", "number", "bool", "array", "object", "map"],
"default": "object",
"optional": true
},
"interface": {
"description": "Is this type an interface?",
"type": "@bool",
"default": false,
"optional": true
},
"fields": {
"description": "Each field is listed with it's type",
"type": "@map",
"items": {
"type": "@rule"
},
"optional": true
},
"rule": {
"description": "Embedded type that defines restriction rules for this type. By convention, the ID should be this type prefixed with the @ character.",
"type": "@type",
"optional": true
}
},
"rule": {
"description": "Restriction rules for types",
"type": "type",
"embed": ["rule"]
}
}`
var i interface{}
err := up.Process(ctx, []byte(data), &i)
require.NoError(t, err)
f, ok := i.(*system.Type)
assert.True(t, ok, "Type %T not correct", i)
assert.NotNil(t, f)
assert.Equal(t, "This is the most basic type.", f.Description)
assert.NotNil(t, f.Native)
assert.Equal(t, "object", f.Native.Value())
assert.Equal(t, "Is this type an interface?", f.Fields["interface"].(system.ObjectInterface).GetObject(nil).Description)
assert.Equal(t, true, f.Fields["interface"].GetRule(nil).Optional)
r, ok := f.Fields["interface"].(*system.BoolRule)
assert.True(t, ok, "Wrong type %T\n", f.Fields["interface"])
assert.NotNil(t, r.Default)
assert.Equal(t, false, r.Default.Value())
}
开发者ID:kego,项目名称:ke,代码行数:60,代码来源:type_ext_test.go
示例2: TestStringUnmarshalJSON
func TestStringUnmarshalJSON(t *testing.T) {
var s *String
err := s.Unpack(envctx.Empty, Pack(nil), false)
require.NoError(t, err)
assert.Nil(t, s)
s = NewString("")
err = s.Unpack(envctx.Empty, Pack(`foo "bar"`), false)
require.NoError(t, err)
assert.NotNil(t, s)
assert.Equal(t, `foo "bar"`, s.Value())
s = NewString("")
err = s.Unpack(envctx.Empty, Pack(map[string]interface{}{
"type": "system:string",
"value": `foo "bar"`,
}), false)
require.NoError(t, err)
assert.NotNil(t, s)
assert.Equal(t, `foo "bar"`, s.Value())
s = NewString("")
err = s.Unpack(envctx.Empty, Pack(1.0), false)
assert.Error(t, err)
}
开发者ID:kego,项目名称:ke,代码行数:28,代码来源:string_test.go
示例3: TestBoolUnmarshalJSON
func TestBoolUnmarshalJSON(t *testing.T) {
var b *Bool
err := b.Unpack(envctx.Empty, Pack(nil), false)
require.NoError(t, err)
assert.Nil(t, b)
b = NewBool(false)
err = b.Unpack(envctx.Empty, Pack(true), false)
require.NoError(t, err)
assert.NotNil(t, b)
assert.True(t, b.Value())
b = NewBool(false)
err = b.Unpack(envctx.Empty, Pack(map[string]interface{}{
"type": "system:bool",
"value": true,
}), false)
require.NoError(t, err)
assert.NotNil(t, b)
assert.True(t, b.Value())
b = NewBool(true)
err = b.Unpack(envctx.Empty, Pack(false), false)
require.NoError(t, err)
assert.NotNil(t, b)
assert.False(t, b.Value())
b = NewBool(false)
err = b.Unpack(envctx.Empty, Pack("foo"), false)
assert.Error(t, err)
}
开发者ID:kego,项目名称:ke,代码行数:34,代码来源:bool_test.go
示例4: TestNode_SetValueZero2
func TestNode_SetValueZero2(t *testing.T) {
cb, n := data.Empty(t)
test := func(t *testing.T, n *node.Node, m *data.Multi) {
sstring, ok := system.GetTypeFromCache(cb.Ctx(), "kego.io/system", "string")
assert.True(t, ok)
snumber, ok := system.GetTypeFromCache(cb.Ctx(), "kego.io/system", "number")
assert.True(t, ok)
require.NoError(t, n.Map["ss"].SetValueZero(cb.Ctx(), true, sstring))
assert.Nil(t, m.Ss)
require.NoError(t, n.Map["sn"].SetValueZero(cb.Ctx(), false, snumber))
assert.NotNil(t, m.Sn)
require.NoError(t, n.Map["mnri"].SetValueZero(cb.Ctx(), true, nil))
assert.Nil(t, m.Mnri)
require.NoError(t, n.Map["mi"].SetValueZero(cb.Ctx(), false, nil))
assert.NotNil(t, m.Mi)
assert.Equal(t, 0, len(m.Mi))
require.NoError(t, n.Map["anri"].SetValueZero(cb.Ctx(), true, nil))
assert.Nil(t, m.Anri)
require.NoError(t, n.Map["ai"].SetValueZero(cb.Ctx(), false, nil))
assert.NotNil(t, m.Ai)
assert.Equal(t, 0, len(m.Ai))
}
data.Run(t, n, n.Value.(*data.Multi), test)
}
开发者ID:kego,项目名称:ke,代码行数:32,代码来源:node_ext_test.go
示例5: TestNumberUnmarshalJSON
func TestNumberUnmarshalJSON(t *testing.T) {
var n *Number
err := n.Unpack(envctx.Empty, Pack(nil), false)
require.NoError(t, err)
assert.Nil(t, n)
n = NewNumber(0.0)
err = n.Unpack(envctx.Empty, Pack(1.2), false)
require.NoError(t, err)
assert.NotNil(t, n)
assert.Equal(t, 1.2, n.Value())
n = NewNumber(0.0)
err = n.Unpack(envctx.Empty, Pack(map[string]interface{}{
"type": "system:number",
"value": 1.2,
}), false)
require.NoError(t, err)
assert.NotNil(t, n)
assert.Equal(t, 1.2, n.Value())
n = NewNumber(0.0)
err = n.Unpack(envctx.Empty, Pack("foo"), false)
assert.Error(t, err)
}
开发者ID:kego,项目名称:ke,代码行数:28,代码来源:number_test.go
示例6: TestRuleWrapper_ZeroValue
func TestRuleWrapper_ZeroValue(t *testing.T) {
cb := tests.Context("kego.io/system").Jauto().Sauto(parser.Parse)
r := system.WrapRule(cb.Ctx(), &system.MapRule{
Object: &system.Object{Type: system.NewReference("kego.io/system", "@map")},
Rule: &system.Rule{},
Items: &system.StringRule{
Object: &system.Object{Type: system.NewReference("kego.io/system", "@string")},
Rule: &system.Rule{},
},
})
v, err := r.ZeroValue(true)
require.NoError(t, err)
assert.IsType(t, map[string]*system.String{}, v.Interface())
assert.Nil(t, v.Interface())
v, err = r.ZeroValue(false)
require.NoError(t, err)
assert.IsType(t, map[string]*system.String{}, v.Interface())
assert.NotNil(t, v.Interface())
vv := v.Interface().(map[string]*system.String)
vv["a"] = system.NewString("")
r = system.WrapRule(cb.Ctx(), &system.MapRule{
Object: &system.Object{Type: system.NewReference("kego.io/system", "@array")},
Rule: &system.Rule{},
Items: &system.StringRule{
Object: &system.Object{Type: system.NewReference("kego.io/system", "@string")},
Rule: &system.Rule{},
},
})
v, err = r.ZeroValue(true)
require.NoError(t, err)
assert.IsType(t, []*system.String{}, v.Interface())
assert.Nil(t, v.Interface())
v, err = r.ZeroValue(false)
require.NoError(t, err)
assert.IsType(t, []*system.String{}, v.Interface())
assert.NotNil(t, v.Interface())
va := v.Interface().([]*system.String)
va = append(va, system.NewString(""))
}
开发者ID:kego,项目名称:ke,代码行数:44,代码来源:rule_ext_test.go
示例7: TestAls
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)
}),
)
}
开发者ID:kego,项目名称:ke,代码行数:12,代码来源:marshal_ext_test.go
示例8: TestI
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())
}),
)
}
开发者ID:kego,项目名称:ke,代码行数:12,代码来源:marshal_ext_test.go
示例9: TestAljn
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())
}),
)
}
开发者ID:kego,项目名称:ke,代码行数:12,代码来源:marshal_ext_test.go
示例10: TestSri2
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())
}),
)
}
开发者ID:kego,项目名称:ke,代码行数:12,代码来源:marshal_ext_test.go
示例11: TestNri2
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())
}),
)
}
开发者ID:kego,项目名称:ke,代码行数:12,代码来源:marshal_ext_test.go
示例12: TestBri2
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())
}),
)
}
开发者ID:kego,项目名称:ke,代码行数:12,代码来源:marshal_ext_test.go
示例13: TestAljbi
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())
}),
)
}
开发者ID:kego,项目名称:ke,代码行数:13,代码来源:marshal_ext_test.go
示例14: TestIntUnmarshalJSON
func TestIntUnmarshalJSON(t *testing.T) {
var i *Int
err := i.Unpack(envctx.Empty, Pack(nil), false)
require.NoError(t, err)
assert.Nil(t, i)
i = NewInt(0)
err = i.Unpack(envctx.Empty, Pack(2.0), false)
require.NoError(t, err)
assert.NotNil(t, i)
assert.Equal(t, 2, i.Value())
i = NewInt(0)
err = i.Unpack(envctx.Empty, Pack(map[string]interface{}{
"type": "system:int",
"value": 2.0,
}), false)
require.NoError(t, err)
assert.NotNil(t, i)
assert.Equal(t, 2, i.Value())
i = NewInt(0)
err = i.Unpack(envctx.Empty, Pack(-12.0), false)
require.NoError(t, err)
assert.NotNil(t, i)
assert.Equal(t, -12, i.Value())
i = NewInt(0)
err = i.Unpack(envctx.Empty, Pack("foo"), false)
assert.IsError(t, err, "UJUBDGVYGF")
i = NewInt(0)
err = i.Unpack(envctx.Empty, Pack(1.2), false)
assert.HasError(t, err, "KVEOETSIJY")
}
开发者ID:kego,项目名称:ke,代码行数:38,代码来源:int_test.go
示例15: TestAljni2
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())
}),
)
}
开发者ID:kego,项目名称:ke,代码行数:15,代码来源:marshal_ext_test.go
示例16: TestAljbi2
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())
}),
)
}
开发者ID:kego,项目名称:ke,代码行数:15,代码来源:marshal_ext_test.go
示例17: testBool
func testBool(t *testing.T, up unpacker.Interface) {
ctx := initialise()
data := `{
"description": "This is the native json bool data type",
"type": "type",
"id": "bool",
"native": "bool",
"alias": {
"type": "json:@bool"
},
"rule": {
"description": "Restriction rules for bools",
"type": "type",
"embed": ["rule"],
"fields": {
"default": {
"description": "Default value of this is missing or null",
"type": "@bool",
"optional": true
}
}
}
}`
var i interface{}
err := up.Process(ctx, []byte(data), &i)
require.NoError(t, err)
f, ok := i.(*system.Type)
assert.True(t, ok, "Type %T not correct", i)
assert.NotNil(t, f)
assert.Equal(t, "This is the native json bool data type", f.Description)
assert.NotNil(t, f.Native)
assert.Equal(t, "bool", f.Native.Value())
}
开发者ID:kego,项目名称:ke,代码行数:36,代码来源:type_ext_test.go
示例18: TestNewNumber
func TestNewNumber(t *testing.T) {
n := NewNumber(1.2)
assert.NotNil(t, n)
assert.Equal(t, 1.2, n.Value())
}
开发者ID:kego,项目名称:ke,代码行数:5,代码来源:number_test.go
示例19: TestNewString
func TestNewString(t *testing.T) {
s := NewString("a")
assert.NotNil(t, s)
assert.Equal(t, "a", s.Value())
assert.Equal(t, "a", s.NativeString())
}
开发者ID:kego,项目名称:ke,代码行数:6,代码来源:string_test.go
示例20: TestNewInt
func TestNewInt(t *testing.T) {
n := NewInt(2)
assert.NotNil(t, n)
assert.Equal(t, 2, n.Value())
}
开发者ID:kego,项目名称:ke,代码行数:5,代码来源:int_test.go
注:本文中的github.com/davelondon/ktest/assert.NotNil函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论