当前位置: 首页>>代码示例>>Golang>>正文


Golang assert.False函数代码示例

本文整理汇总了Golang中github.com/davelondon/ktest/assert.False函数的典型用法代码示例。如果您正苦于以下问题:Golang False函数的具体用法?Golang False怎么用?Golang False使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了False函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestComparePackageHash

func TestComparePackageHash(t *testing.T) {
	cb := tests.New().TempGopath(true)
	path, _ := cb.TempPackage("a", map[string]string{
		"a.yaml": "type: system:package",
	})
	cb.Path(path).Jempty().Spkg(path)

	// "a.b/c" not found in scache.
	changes, err := comparePackageHash(cb.Ctx(), "a.b/c")
	assert.IsError(t, err, "NHXWLPHCHL")
	assert.False(t, changes)

	// path not found in jcache
	changes, err = comparePackageHash(cb.Ctx(), path)
	require.NoError(t, err)
	assert.True(t, changes)

	cb.Jsystem().Jpkg(path, 999).Sauto(parser.Parse)

	// hash changed
	changes, err = comparePackageHash(cb.Ctx(), path)
	require.NoError(t, err)
	assert.True(t, changes)

	scache := sysctx.FromContext(cb.Ctx())
	pi, _ := scache.Get(path)
	cb.Jpkg(path, pi.Hash)

	// hash correct
	changes, err = comparePackageHash(cb.Ctx(), path)
	require.NoError(t, err)
	assert.False(t, changes)

	pi.Aliases["c"] = "a.b/c"

	changes, err = comparePackageHash(cb.Ctx(), path)
	assert.IsError(t, err, "DGJTLHQOCQ")
	assert.False(t, changes)

	pi1 := scache.Set("a.b/c")

	changes, err = comparePackageHash(cb.Ctx(), path)
	require.NoError(t, err)
	assert.True(t, changes)

	cb.Jpkg("a.b/c", 1)
	pi1.Hash = 2

	changes, err = comparePackageHash(cb.Ctx(), path)
	require.NoError(t, err)
	assert.True(t, changes)

	pi1.Hash = 1

	changes, err = comparePackageHash(cb.Ctx(), path)
	require.NoError(t, err)
	assert.False(t, changes)

}
开发者ID:kego,项目名称:ke,代码行数:59,代码来源:validate_test.go

示例2: TestIsNull

func TestIsNull(t *testing.T) {
	assert.True(t, isNull(exprElement{typ: system.J_NULL, value: nil}))
	assert.True(t, isNull(exprElement{typ: system.J_MAP, value: nil}))
	assert.True(t, isNull(exprElement{typ: system.J_MAP, value: &node.Node{Null: true}}))
	assert.True(t, isNull(exprElement{typ: system.J_MAP, value: &node.Node{Missing: true}}))
	assert.False(t, isNull(exprElement{typ: system.J_MAP, value: &node.Node{}}))
	assert.False(t, isNull(exprElement{typ: system.J_MAP, value: 1}))
}
开发者ID:kego,项目名称:ke,代码行数:8,代码来源:utilities_test.go

示例3: TestGetBool

func TestGetBool(t *testing.T) {
	assert.False(t, getBool(nil))
	assert.False(t, getBool(&node.Node{ValueBool: false}))
	assert.True(t, getBool(&node.Node{ValueBool: true}))
	assert.True(t, getBool(system.NewBool(true)))
	assert.False(t, getBool(system.NewBool(false)))
	assert.True(t, getBool(true))
	assert.False(t, getBool(false))
	assert.False(t, getBool("a"))
}
开发者ID:kego,项目名称:ke,代码行数:10,代码来源:utilities_test.go

示例4: TestArrayRule_Enforce

func TestArrayRule_Enforce(t *testing.T) {
	r := ArrayRule{MaxItems: NewInt(2)}
	fail, messages, err := r.Enforce(envctx.Empty, []int{1, 2})
	require.NoError(t, err)
	assert.Equal(t, 0, len(messages))
	assert.False(t, fail)

	fail, messages, err = r.Enforce(envctx.Empty, []int{1, 2, 3})
	require.NoError(t, err)
	assert.Equal(t, "MaxItems: length 3 should not be greater than 2", messages[0])
	assert.True(t, fail)

	r = ArrayRule{MinItems: NewInt(2)}
	fail, messages, err = r.Enforce(envctx.Empty, []int{1, 2})
	require.NoError(t, err)
	assert.Equal(t, 0, len(messages))
	assert.False(t, fail)

	fail, messages, err = r.Enforce(envctx.Empty, []int{1})
	require.NoError(t, err)
	assert.Equal(t, "MinItems: length 1 should not be less than 2", messages[0])
	assert.True(t, fail)

	r = ArrayRule{UniqueItems: true}
	fail, messages, err = r.Enforce(envctx.Empty, []int{1, 2, 3, 4})
	require.NoError(t, err)
	assert.Equal(t, 0, len(messages))
	assert.False(t, fail)

	fail, messages, err = r.Enforce(envctx.Empty, []int{1, 2, 3, 3})
	require.NoError(t, err)
	assert.Equal(t, "UniqueItems: array contains duplicate item 3", messages[0])
	assert.True(t, fail)

	fail, messages, err = r.Enforce(envctx.Empty, []string{"foo", "bar", "foo"})
	require.NoError(t, err)
	assert.Equal(t, "UniqueItems: array contains duplicate item foo", messages[0])
	assert.True(t, fail)

	r = ArrayRule{}
	fail, messages, err = r.Enforce(envctx.Empty, []int{1, 2})
	require.NoError(t, err)
	assert.Equal(t, 0, len(messages))
	assert.False(t, fail)

	r = ArrayRule{MaxItems: NewInt(2)}
	fail, messages, err = r.Enforce(envctx.Empty, map[string]int{"foo": 1, "bar": 2})
	assert.IsError(t, err, "OWTAUVVFBL")

	s := &StringRule{}
	var cr CollectionRule = &ArrayRule{Items: s}
	assert.Equal(t, s, cr.GetItemsRule())
}
开发者ID:kego,项目名称:ke,代码行数:53,代码来源:array_test.go

示例5: TestExprElementIsTruthy

func TestExprElementIsTruthy(t *testing.T) {
	assert.False(t, exprElementIsTruthy(exprElement{typ: system.J_STRING, value: ""}))
	assert.True(t, exprElementIsTruthy(exprElement{typ: system.J_STRING, value: "a"}))
	assert.False(t, exprElementIsTruthy(exprElement{typ: system.J_NUMBER, value: 0.0}))
	assert.True(t, exprElementIsTruthy(exprElement{typ: system.J_NUMBER, value: 0.1}))
	assert.True(t, exprElementIsTruthy(exprElement{typ: system.J_OBJECT}))
	assert.True(t, exprElementIsTruthy(exprElement{typ: system.J_MAP}))
	assert.True(t, exprElementIsTruthy(exprElement{typ: system.J_ARRAY}))
	assert.False(t, exprElementIsTruthy(exprElement{typ: system.J_BOOL, value: false}))
	assert.True(t, exprElementIsTruthy(exprElement{typ: system.J_BOOL, value: true}))
	assert.False(t, exprElementIsTruthy(exprElement{typ: system.J_NULL}))
	assert.False(t, exprElementIsTruthy(exprElement{typ: system.J_OPERATOR}))

}
开发者ID:kego,项目名称:ke,代码行数:14,代码来源:utilities_test.go

示例6: TestReferenceRule_Enforce

func TestReferenceRule_Enforce(t *testing.T) {

	r := ReferenceRule{Rule: &Rule{Optional: false}, PatternNot: NewString(`[`)}
	fail, messages, err := r.Enforce(envctx.Empty, NewReference("", ""))
	require.NoError(t, err)
	assert.Equal(t, "PatternNot: regex does not compile: [", messages[0])
	assert.True(t, fail)

	r = ReferenceRule{Rule: &Rule{Optional: false}, Pattern: NewString(`[`)}
	fail, messages, err = r.Enforce(envctx.Empty, NewReference("", ""))
	require.NoError(t, err)
	assert.Equal(t, "Pattern: regex does not compile: [", messages[0])
	assert.True(t, fail)

	fail, messages, err = r.Enforce(envctx.Empty, "")
	require.IsError(t, err, "BYDVGGETWW")

	r = ReferenceRule{Rule: &Rule{Optional: false}, Pattern: NewString(`^foo\d`)}
	fail, messages, err = r.Enforce(envctx.Empty, nil)
	require.NoError(t, err)
	assert.Equal(t, "Pattern: value must exist", messages[0])
	assert.True(t, fail)

	fail, messages, err = r.Enforce(envctx.Empty, NewReference("", "a"))
	require.NoError(t, err)
	assert.Equal(t, "Pattern: value \"a\" must match ^foo\\d", messages[0])
	assert.True(t, fail)

	fail, messages, err = r.Enforce(envctx.Empty, NewReference("", "foo1"))
	require.NoError(t, err)
	assert.Equal(t, 0, len(messages))
	assert.False(t, fail)

	r = ReferenceRule{Rule: &Rule{Optional: false}, PatternNot: NewString(`^foo\d`)}
	fail, messages, err = r.Enforce(envctx.Empty, nil)
	require.NoError(t, err)
	assert.Equal(t, "PatternNot: value must exist", messages[0])
	assert.True(t, fail)

	fail, messages, err = r.Enforce(envctx.Empty, NewReference("", "foo1"))
	require.NoError(t, err)
	assert.Equal(t, "PatternNot: value \"foo1\" must not match ^foo\\d", messages[0])
	assert.True(t, fail)

	fail, messages, err = r.Enforce(envctx.Empty, NewReference("", "a"))
	require.NoError(t, err)
	assert.Equal(t, 0, len(messages))
	assert.False(t, fail)

}
开发者ID:kego,项目名称:ke,代码行数:50,代码来源:reference_test.go

示例7: TestRuleWrapper_Kind

func TestRuleWrapper_Kind(t *testing.T) {
	cb := tests.Context("a.b/c").Jempty()
	at := &Type{
		Object: &Object{Id: NewReference("a.b/c", "foo")},
		Native: NewString("object"),
	}
	ar := &fooRuleStruct{Rule: &Rule{}}
	aw := RuleWrapper{
		Ctx:       cb.Ctx(),
		Interface: ar,
		Struct:    ar.Rule,
		Parent:    at,
	}
	kind, alias := aw.Kind(cb.Ctx())
	assert.False(t, alias)
	assert.Equal(t, KindStruct, kind)

	aw.Struct.Interface = true
	kind, alias = aw.Kind(cb.Ctx())
	assert.False(t, alias)
	assert.Equal(t, KindInterface, kind)

	cr := &MapRule{Rule: &Rule{}, Items: &StringRule{Rule: &Rule{}}}
	aw.Interface = cr
	aw.Struct = cr.Rule
	aw.Parent.CustomKind = NewString(string(KindMap))
	kind, alias = aw.Kind(cb.Ctx())
	assert.False(t, alias)
	assert.Equal(t, KindMap, kind)

	arr := &ArrayRule{Rule: &Rule{}, Items: &StringRule{Rule: &Rule{}}}
	aw.Interface = arr
	aw.Struct = arr.Rule
	aw.Parent.CustomKind = NewString(string(KindArray))
	kind, alias = aw.Kind(cb.Ctx())
	assert.False(t, alias)
	assert.Equal(t, KindArray, kind)

	// DummyRule always implements CollectionRule, but we don't want to return
	// KindMap/KindArray unless GetItemsRule returns something.
	dr := &DummyRule{Rule: &Rule{}}
	aw.Interface = dr
	aw.Struct = dr.Rule
	aw.Parent.CustomKind = nil
	kind, alias = aw.Kind(cb.Ctx())
	assert.False(t, alias)
	assert.Equal(t, KindStruct, kind)
}
开发者ID:kego,项目名称:ke,代码行数:48,代码来源:rule_test.go

示例8: TestMapRule_Enforce

func TestMapRule_Enforce(t *testing.T) {

	r := MapRule{Keys: &IntRule{Rule: &Rule{}}}
	fail, messages, err := r.Enforce(envctx.Empty, map[string]int{"foo": 1})
	require.IsError(t, err, "WDKAXPCRJB")

	r = MapRule{Keys: &StringRule{Rule: &Rule{}, MaxLength: NewInt(1)}}
	fail, messages, err = r.Enforce(envctx.Empty, map[string]int{"foo": 1})
	require.NoError(t, err)
	assert.Equal(t, 1, len(messages))
	assert.True(t, fail)
	assert.Equal(t, "MaxLength: length of \"foo\" must not be greater than 1", messages[0])

	r = MapRule{MaxItems: NewInt(2)}
	fail, messages, err = r.Enforce(envctx.Empty, map[string]int{"foo": 1, "bar": 2})
	require.NoError(t, err)
	assert.Equal(t, 0, len(messages))
	assert.False(t, fail)

	fail, messages, err = r.Enforce(envctx.Empty, map[string]int{"foo": 1, "bar": 2, "baz": 3})
	require.NoError(t, err)
	assert.Equal(t, "MaxItems: length 3 should not be greater than 2", messages[0])
	assert.True(t, fail)

	r = MapRule{MinItems: NewInt(2)}
	fail, messages, err = r.Enforce(envctx.Empty, map[string]int{"foo": 1, "bar": 2})
	require.NoError(t, err)
	assert.Equal(t, 0, len(messages))
	assert.False(t, fail)

	fail, messages, err = r.Enforce(envctx.Empty, map[string]int{"foo": 1})
	require.NoError(t, err)
	assert.Equal(t, "MinItems: length 1 should not be less than 2", messages[0])
	assert.True(t, fail)

	_, _, err = r.Enforce(envctx.Empty, "a")
	assert.IsError(t, err, "NFWPLTOJLP")

	r = MapRule{}
	fail, messages, err = r.Enforce(envctx.Empty, map[string]int{"foo": 1})
	require.NoError(t, err)
	assert.False(t, fail)
	assert.Equal(t, 0, len(messages))

	var cr CollectionRule = &MapRule{Items: &StringRule{Equal: NewString("a")}}
	assert.Equal(t, "a", cr.GetItemsRule().(*StringRule).Equal.Value())

}
开发者ID:kego,项目名称:ke,代码行数:48,代码来源:map_test.go

示例9: TestNewBool

func TestNewBool(t *testing.T) {
	b := NewBool(true)
	assert.True(t, b.Value())

	b1 := NewBool(false)
	assert.False(t, b1.Value())
}
开发者ID:kego,项目名称:ke,代码行数:7,代码来源:bool_test.go

示例10: 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

示例11: 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

示例12: TestKegoProduction

func TestKegoProduction(t *testing.T) {
	p := getParser(t)
	f := p.kegoProduction(nil)
	b, err := f(&node.Node{Null: true})
	assert.False(t, b)
	require.NoError(t, err)

}
开发者ID:kego,项目名称:ke,代码行数:8,代码来源:selectors_test.go

示例13: TestStringRule_Validate

func TestStringRule_Validate(t *testing.T) {
	r := &StringRule{}
	fail, messages, err := r.Validate(envctx.Empty)
	require.NoError(t, err)
	assert.False(t, fail)
	assert.Equal(t, 0, len(messages))

	r = &StringRule{PatternNot: NewString("[")}
	fail, messages, err = r.Validate(envctx.Empty)
	require.NoError(t, err)
	assert.True(t, fail)
	assert.Equal(t, "PatternNot: regex does not compile: [", messages[0])

	r = &StringRule{Pattern: NewString("[")}
	fail, messages, err = r.Validate(envctx.Empty)
	require.NoError(t, err)
	assert.True(t, fail)
	assert.Equal(t, "Pattern: regex does not compile: [", messages[0])

	r = &StringRule{MaxLength: NewInt(10)}
	fail, messages, err = r.Validate(envctx.Empty)
	require.NoError(t, err)
	assert.False(t, fail)
	assert.Equal(t, 0, len(messages))

	r = &StringRule{MaxLength: NewInt(10), MinLength: NewInt(5)}
	fail, messages, err = r.Validate(envctx.Empty)
	require.NoError(t, err)
	assert.False(t, fail)
	assert.Equal(t, 0, len(messages))

	r = &StringRule{MaxLength: NewInt(5), MinLength: NewInt(5)}
	fail, messages, err = r.Validate(envctx.Empty)
	require.NoError(t, err)
	assert.False(t, fail)
	assert.Equal(t, 0, len(messages))

	r = &StringRule{MaxLength: NewInt(4), MinLength: NewInt(5)}
	fail, messages, err = r.Validate(envctx.Empty)
	require.NoError(t, err)
	assert.True(t, fail)
	assert.Equal(t, "MaxLength 4 must not be less than MinLength 5", messages[0])
}
开发者ID:kego,项目名称:ke,代码行数:43,代码来源:string_test.go

示例14: TestReferenceGetType

func TestReferenceGetType(t *testing.T) {

	ty := &Type{
		Object: &Object{Id: NewReference("a.b/c", "d"), Type: NewReference("kego.io/system", "type")},
	}

	ctx := tests.Context("a.b/c").Stype("d", ty).Ctx()

	r := NewReference("a.b/c", "d")
	typ, ok := r.GetType(ctx)
	assert.True(t, ok)
	assert.Equal(t, "a.b/c:d", typ.Id.Value())

	r = NewReference("a.b/c", "e")
	_, ok = r.GetType(ctx)
	assert.False(t, ok)

	r = &Reference{}
	_, ok = r.GetType(ctx)
	assert.False(t, ok)
}
开发者ID:kego,项目名称:ke,代码行数:21,代码来源:reference_test.go

示例15: TestGetInfo

func TestGetInfo(t *testing.T) {
	cb := tests.Context("a.b/c").Wg().Sempty().Jsystem().TempGopath(false)
	defer cb.Cleanup()
	_, dirA := cb.TempPackage("a", map[string]string{
		"generated.go": "",
	})
	info, found, err := getInfo(cb.Ctx(), dirA)
	require.NoError(t, err)
	assert.Nil(t, info)
	assert.False(t, found)

}
开发者ID:kego,项目名称:ke,代码行数:12,代码来源:generate_test.go


注:本文中的github.com/davelondon/ktest/assert.False函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。