本文整理汇总了Golang中github.com/davelondon/ktest/assert.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Equal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例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)
}
示例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())
}
示例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)
}
示例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)
}
示例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)
}),
)
}
示例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))
}
示例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
}
示例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)
}
示例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)
}
示例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)
}
示例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())
}
示例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)
}
示例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())
}
示例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])
}