本文整理汇总了Golang中github.com/davelondon/ktest/assert.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Equal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
示例2: 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
示例3: TestNumberInterfaces
func TestNumberInterfaces(t *testing.T) {
var nn NativeNumber = NewNumber(99.9)
assert.Equal(t, 99.9, nn.NativeNumber())
var dr DefaultRule = &NumberRule{Default: NewNumber(22.2)}
assert.Equal(t, 22.2, dr.GetDefault().(*Number).Value())
}
开发者ID:kego,项目名称:ke,代码行数:7,代码来源:number_test.go
示例4: TestNode_DeleteObjectChild
func TestNode_DeleteObjectChild(t *testing.T) {
cb, n := data.Setup(t)
test := func(t *testing.T, n *node.Node, m *data.Multi) {
require.NoError(t, n.DeleteObjectChild(cb.Ctx(), "js"))
assert.True(t, n.Map["js"].Missing)
assert.Equal(t, "", m.Js)
require.NoError(t, n.DeleteObjectChild(cb.Ctx(), "ss"))
assert.Nil(t, m.Ss)
require.NoError(t, n.DeleteObjectChild(cb.Ctx(), "sr"))
assert.Nil(t, m.Sr)
require.NoError(t, n.DeleteObjectChild(cb.Ctx(), "jn"))
assert.Equal(t, 0.0, m.Jn)
require.NoError(t, n.DeleteObjectChild(cb.Ctx(), "sn"))
assert.Nil(t, m.Sn)
require.NoError(t, n.DeleteObjectChild(cb.Ctx(), "jb"))
assert.Equal(t, false, m.Jb)
require.NoError(t, n.DeleteObjectChild(cb.Ctx(), "sb"))
assert.Nil(t, m.Sb)
require.NoError(t, n.DeleteObjectChild(cb.Ctx(), "i"))
assert.Nil(t, m.I)
require.NoError(t, n.DeleteObjectChild(cb.Ctx(), "ajs"))
assert.Nil(t, m.Ajs)
require.NoError(t, n.DeleteObjectChild(cb.Ctx(), "mjs"))
assert.Nil(t, m.Mjs)
}
data.Run(t, n, n.Value.(*data.Multi), test)
}
开发者ID:kego,项目名称:ke,代码行数:29,代码来源:node_ext_test.go
示例5: TestNode_InitialiseMapChild
func TestNode_InitialiseMapChild(t *testing.T) {
cb, n := data.Setup(t)
test := func(t *testing.T, n *node.Node, m *data.Multi) {
c := node.NewNode()
require.NoError(t, c.InitialiseMapItem(cb.Ctx(), n.Map["mjs"], "c"))
require.NoError(t, c.AddToMap(cb.Ctx(), n.Map["mjs"], "c", true))
assert.Equal(t, 3, len(n.Map["mjs"].Map))
assert.True(t, n.Map["mjs"].Map["c"].Null)
assert.False(t, n.Map["mjs"].Map["c"].Missing)
assert.Equal(t, c, n.Map["mjs"].Map["c"])
assert.Equal(t, "", m.Mjs["c"])
c1 := node.NewNode()
require.NoError(t, c1.InitialiseMapItem(cb.Ctx(), n.Map["mss"], "c"))
require.NoError(t, c1.AddToMap(cb.Ctx(), n.Map["mss"], "c", true))
assert.Equal(t, 3, len(n.Map["mss"].Map))
assert.Nil(t, m.Mss["c"])
c2 := node.NewNode()
require.NoError(t, c2.InitialiseMapItem(cb.Ctx(), n.Map["mm"], "c"))
require.NoError(t, c2.AddToMap(cb.Ctx(), n.Map["mm"], "c", true))
assert.Equal(t, 3, len(m.Mm))
assert.Nil(t, m.Mm["c"])
}
data.Run(t, n, n.Value.(*data.Multi), test)
}
开发者ID:kego,项目名称:ke,代码行数:28,代码来源:node_ext_test.go
示例6: TestMalms
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)
}),
)
}
开发者ID:kego,项目名称:ke,代码行数:26,代码来源:marshal_map_ext_test.go
示例7: TestReference_Label
func TestReference_Label(t *testing.T) {
var r *Reference
assert.Equal(t, "", r.Label(nil))
r = NewReference("a", "b")
assert.Equal(t, "b", r.Label(nil))
}
开发者ID:kego,项目名称:ke,代码行数:7,代码来源:reference_test.go
示例8: TestBuilder
func TestBuilder(t *testing.T) {
g := New("a.b/c")
b, err := g.Build()
require.NoError(t, err)
assert.Equal(t, "package c\n", string(b))
g.buffer.Reset()
g.Imports.Anonymous("e.f/g")
b, err = g.Build()
require.NoError(t, err)
assert.Equal(t, "package c\n\nimport (\n\t_ \"e.f/g\"\n)\n", string(b))
g.buffer.Reset()
alias := g.Imports.Add("h.i/j")
assert.Equal(t, "j", alias)
b, err = g.Build()
require.NoError(t, err)
assert.Equal(t, "package c\n\nimport (\n\t_ \"e.f/g\"\n\t\"h.i/j\"\n)\n", string(b))
g.buffer.Reset()
g.SetPackageComment("comment")
g.SetIntroComment("intro")
g.Print("var ")
g.Println("foo string")
g.Printf("var bar int\n%s", "var baz bool")
g.Println("")
g.Println("func foo() {")
g.PrintFunctionCall("k.l/m", "n", "o", "p")
g.Println("")
g.PrintMethodCall("a", "b", "c", "d")
g.Println("}")
b, err = g.Build()
require.NoError(t, err)
assert.Contains(t, string(b), `// comment
package c
// intro
import (
_ "e.f/g"
"h.i/j"
"k.l/m"
)
var foo string
var bar int
var baz bool
func foo() {
m.n(o, p)
a.b(c, d)
}
`)
g.Print("dfskjsdf")
_, err = g.Build()
assert.IsError(t, err, "CRBYOUOHPG") // Error formatting source
}
开发者ID:kego,项目名称:ke,代码行数:60,代码来源:builder_test.go
示例9: TestGetOptions
func TestGetOptions(t *testing.T) {
getTrue := func() *bool {
val := true
return &val
}
a := "a"
b := 2
f := Flags{
Edit: getTrue(),
Update: getTrue(),
Log: getTrue(),
Validate: getTrue(),
Debug: getTrue(),
Path: &a,
Port: &b,
}
d := f.getOptions()
assert.True(t, d.Edit)
assert.True(t, d.Update)
assert.True(t, d.Log)
assert.True(t, d.Validate)
assert.True(t, d.Debug)
assert.Equal(t, 2, d.Port)
assert.Equal(t, "a", d.Path)
}
开发者ID:kego,项目名称:ke,代码行数:27,代码来源:initialise_test.go
示例10: TestScanDirToFiles
func TestScanDirToFiles(t *testing.T) {
cb := tests.New().TempGopath(false)
defer cb.Cleanup()
_, dir := cb.TempPackage("a", map[string]string{
"b.json": "c",
})
// make a dir so we hit the IsRegular block
require.NoError(t, os.Mkdir(filepath.Join(dir, "d"), 0777))
// put another file in it
require.NoError(t, ioutil.WriteFile(filepath.Join(dir, "d", "e.json"), []byte("f"), 0777))
ch := ScanDirToFiles(cb.Ctx(), dir, false)
out := []File{}
for f := range ch {
require.NoError(t, f.Err)
out = append(out, f)
}
assert.Equal(t, 1, len(out))
assert.Equal(t, filepath.Join(dir, "b.json"), out[0].File)
ch = ScanDirToFiles(cb.Ctx(), dir, true)
out = []File{}
for f := range ch {
require.NoError(t, f.Err)
out = append(out, f)
}
assert.Equal(t, 2, len(out))
assert.Equal(t, filepath.Join(dir, "b.json"), out[0].File)
assert.Equal(t, filepath.Join(dir, "d", "e.json"), out[1].File)
}
开发者ID:kego,项目名称:ke,代码行数:32,代码来源:scanner_test.go
示例11: 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
示例12: 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
示例13: TestGetIndex
func TestGetIndex(t *testing.T) {
p := getUtilParser(t)
r := p.root
i := p.getIndex(r)
assert.Equal(t, -1, i)
s := p.getSiblings(r)
assert.Equal(t, 0, s)
}
开发者ID:kego,项目名称:ke,代码行数:8,代码来源:utilities_test.go
示例14: TestPackedArray
func TestPackedArray(t *testing.T) {
n1 := &Node{ValueString: "n1"}
n2 := &Node{ValueString: "n2"}
p := &packed{n: &Node{Array: []*Node{n1, n2}}}
a := p.Array()
assert.Equal(t, 2, len(a))
assert.Equal(t, "n1", a[0].String())
assert.Equal(t, "n2", a[1].String())
}
开发者ID:kego,项目名称:ke,代码行数:9,代码来源:packed_test.go
示例15: TestSortableReferences
func TestSortableReferences(t *testing.T) {
ra := []*Reference{NewReference("e.f/g", "h"), NewReference("a.b/c", "d")}
sr := SortableReferences(ra)
sort.Sort(sr)
ra = []*Reference(sr)
assert.Equal(t, 2, len(ra))
assert.Equal(t, *NewReference("a.b/c", "d"), *ra[0])
assert.Equal(t, *NewReference("e.f/g", "h"), *ra[1])
}
开发者ID:kego,项目名称:ke,代码行数:9,代码来源:reference_test.go
示例16: TestPackedType
func TestPackedType(t *testing.T) {
var p *packed
assert.Equal(t, system.J_NULL, p.Type())
p = &packed{n: nil}
assert.Equal(t, system.J_NULL, p.Type())
p = &packed{n: &Node{JsonType: system.J_OBJECT}}
assert.Equal(t, system.J_MAP, p.Type())
p = &packed{n: &Node{JsonType: system.J_STRING}}
assert.Equal(t, system.J_STRING, p.Type())
}
开发者ID:kego,项目名称:ke,代码行数:10,代码来源:packed_test.go
示例17: TestGetInt32
func TestGetInt32(t *testing.T) {
i := getInt32(2.0)
assert.Equal(t, int32(2), i)
i = getInt32(2)
assert.Equal(t, int32(2), i)
i = getInt32("a")
assert.Equal(t, int32(-1), i)
}
开发者ID:kego,项目名称:ke,代码行数:10,代码来源:utilities_test.go
示例18: TestPackedMap
func TestPackedMap(t *testing.T) {
n1 := &Node{ValueString: "n1"}
n2 := &Node{ValueString: "n2", Missing: true}
n3 := &Node{ValueString: "n3"}
p := &packed{n: &Node{Map: map[string]*Node{"n1": n1, "n2": n2, "n3": n3}}}
m := p.Map()
assert.Equal(t, 2, len(m))
assert.Equal(t, "n1", m["n1"].String())
assert.Equal(t, "n3", m["n3"].String())
}
开发者ID:kego,项目名称:ke,代码行数:10,代码来源:packed_test.go
示例19: TestBuild
func TestBuild(t *testing.T) {
type a struct {
As string
}
type b struct {
Ba *a
}
foo := &b{&a{"c"}}
p := []Pointer{}
i := builder.Imports{}
n := Build(foo, &p, "", i.Add)
assert.Equal(t, "ptr1", n.Name)
assert.Equal(t, `&literal.a{As:"c"}`, p[0].Source)
assert.Equal(t, `&literal.b{Ba:ptr0}`, p[1].Source)
p = []Pointer{}
i = builder.Imports{"a.b/c": builder.Import{Path: "a.b/c", Name: "c", Alias: "a"}}
n = Build(foo, &p, "kego.io/process/generate/literal", i.Add)
assert.Equal(t, "ptr1", n.Name)
assert.Equal(t, `&a{As:"c"}`, p[0].Source)
assert.Equal(t, `&b{Ba:ptr0}`, p[1].Source)
p = []Pointer{}
i = builder.Imports{
"foo.com/literal": builder.Import{Path: "foo.com/literal", Name: "literal", Alias: "literal"},
"kego.io/process/generate/literal": builder.Import{Path: "kego.io/process/generate/literal", Name: "literal", Alias: "f"}}
n = Build(foo, &p, "kego.io/system", i.Add)
assert.Equal(t, "ptr1", n.Name)
assert.Equal(t, `&f.a{As:"c"}`, p[0].Source)
assert.Equal(t, `&f.b{Ba:ptr0}`, p[1].Source)
}
开发者ID:kego,项目名称:ke,代码行数:34,代码来源:build_test.go
示例20: TestStringString
func TestStringString(t *testing.T) {
var s *String
str := s.String()
assert.Equal(t, "", str)
s = NewString(`foo "bar"`)
str = s.String()
assert.Equal(t, `foo "bar"`, str)
}
开发者ID:kego,项目名称:ke,代码行数:11,代码来源:string_test.go
注:本文中的github.com/davelondon/ktest/assert.Equal函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论