當前位置: 首頁>>代碼示例>>Golang>>正文


Golang tests.Context函數代碼示例

本文整理匯總了Golang中kego/io/tests.Context函數的典型用法代碼示例。如果您正苦於以下問題:Golang Context函數的具體用法?Golang Context怎麽用?Golang Context使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Context函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestScan_errors

func TestScan_errors(t *testing.T) {

	cb := tests.Context("").Cmd().Sempty().Jsystem().TempGopath(true)
	defer cb.Cleanup()

	_, err := Parse(cb.Ctx(), "does-not-exist")
	require.IsError(t, err, "SBALWXUPKN") // Error from ScanForEnv
	assert.HasError(t, err, "NIKCKQAKUI") // GoGet: exit status 1: package does-not-exist

	path, _ := cb.TempPackage("a", map[string]string{
		"a.json": `{
			"type": "system:package",
			"recursive": false
		}`,
		"b.json": "foo",
	})

	cb.Path(path)

	_, err = Parse(cb.Ctx(), path)
	assert.IsError(t, err, "VFUNPHUFHD")  // Error from scanForTypes
	assert.HasError(t, err, "HCYGNBDFFA") // Error trying to unmarshal a type

	path, _ = cb.TempPackage("a", map[string]string{
		"a.json": "foo",
	})

	cb.Path(path)

	_, err = Parse(cb.Ctx(), path)
	assert.IsError(t, err, "GJRHNGGWFD")  // Error from ScanForEnv
	assert.HasError(t, err, "MTDCXBYBEJ") // Error trying to scan for packages

}
開發者ID:kego,項目名稱:ke,代碼行數:34,代碼來源:parser_test.go

示例2: TestWrapRule

func TestWrapRule(t *testing.T) {

	type nonObjectStruct struct {
		*Rule
	}
	type ruleStruct struct {
		*Object
		*Rule
	}
	parentType := &Type{
		Object: &Object{Id: NewReference("a.b/c", "a"), Type: NewReference("kego.io/system", "type")},
	}
	ruleType := &Type{
		Object: &Object{Id: NewReference("a.b/c", "@a"), Type: NewReference("kego.io/system", "type")},
	}

	ctx := tests.Context("a.b/c").Stype("a", parentType).Stype("@a", ruleType).Ctx()

	r := &ruleStruct{
		Object: &Object{Type: NewReference("a.b/c", "@a")},
	}
	w := WrapRule(ctx, r)
	assert.Equal(t, "a", w.Parent.Id.Name)

}
開發者ID:kego,項目名稱:ke,代碼行數:25,代碼來源:rule_test.go

示例3: TestNode_Unpack5

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()))

}
開發者ID:kego,項目名稱:ke,代碼行數:26,代碼來源:node_ext_test.go

示例4: TestFoo

func TestFoo(t *testing.T) {
	cb := tests.Context("kego.io/system")
	typ := new(Type)
	in := Pack(map[string]interface{}{"type": "type", "id": "a"})
	err := typ.Unpack(cb.Ctx(), in, false)
	require.NoError(t, err)
	assert.Equal(t, "a", typ.Id.Name)
}
開發者ID:kego,項目名稱:ke,代碼行數:8,代碼來源:bootstrap_test.go

示例5: TestNewReferenceFromString

func TestNewReferenceFromString(t *testing.T) {
	cb := tests.Context("a.b/c")
	r, err := NewReferenceFromString(cb.Ctx(), "d")
	require.NoError(t, err)
	assert.Equal(t, NewReference("a.b/c", "d"), r)

	r, err = NewReferenceFromString(cb.Ctx(), "e:f")
	assert.IsError(t, err, "VXRGOQHWNB")

}
開發者ID:kego,項目名稱:ke,代碼行數:10,代碼來源:reference_test.go

示例6: TestObjectGetType

func TestObjectGetType(t *testing.T) {
	ty := &Type{Object: &Object{Id: NewReference("a.b/c", "foo")}}

	o := &Object{Type: NewReference("a.b/c", "t")}

	gt, ok := o.Type.GetType(tests.Context("a.b/c").Stype("t", ty).Ctx())
	assert.True(t, ok)
	assert.Equal(t, "a.b/c:foo", gt.Id.Value())

}
開發者ID:kego,項目名稱:ke,代碼行數:10,代碼來源:object_test.go

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

示例8: getUtilParser

func getUtilParser(t *testing.T) *Parser {
	cb := tests.Context("a.b/c").Ssystem(parser.Parse)
	data := `{
		"type": "system:type",
		"id": "foo"
	}`
	n, err := node.Unmarshal(cb.Ctx(), []byte(data))
	require.NoError(t, err)
	p, err := CreateParser(cb.Ctx(), n)
	require.NoError(t, err)
	return p
}
開發者ID:kego,項目名稱:ke,代碼行數:12,代碼來源:utilities_test.go

示例9: Test

func Test(t *testing.T) {
	cb := tests.Context("kego.io/tests/data/alias").Jauto().Sauto(parser.Parse)
	s := `{
  "type": "main",
  "id": "data",
  "a": {"a": {"type":"simple", "js": "a0"}, "b": {"type":"simple", "js": "b0"}}
}`
	var m Main
	err := system.Unmarshal(cb.Ctx(), []byte(s), &m)
	require.NoError(t, err)
	require.Equal(t, "a0", m.A["a"].Js)
	require.Equal(t, "b0", m.A["b"].Js)

}
開發者ID:kego,項目名稱:ke,代碼行數:14,代碼來源:alias_test.go

示例10: Empty

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
}
開發者ID:kego,項目名稱:ke,代碼行數:14,代碼來源:helpers.go

示例11: TestNode_Unpack3

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")

}
開發者ID:kego,項目名稱:ke,代碼行數:14,代碼來源:node_ext_test.go

示例12: TestNode_Print

func TestNode_Print(t *testing.T) {

	cb := tests.Context("kego.io/tests/data").Jauto().Sauto(parser.Parse)

	s := `{
	"type": "simple",
	"js": "a"
}`

	n, err := node.Unmarshal(cb.Ctx(), []byte(s))
	require.NoError(t, err)
	require.Equal(t, `{"js":"a","type":"simple"}`, n.Print(cb.Ctx()))

}
開發者ID:kego,項目名稱:ke,代碼行數:14,代碼來源:node_ext_test.go

示例13: TestGenerateAll

func TestGenerateAll(t *testing.T) {

	cb := tests.Context("a.b/c").Wg().Sempty().Jsystem().TempGopath(true)
	defer cb.Cleanup()

	pathA, dirA := cb.TempPackage("a", map[string]string{
		"a.yml": `
id: a
type: system:type
fields:
	a:
		type: system:@string`,
	})

	err := GenerateAll(cb.Ctx(), pathA, map[string]bool{})
	assert.IsError(t, err, "XMVXECGDOX")

	cb.Path(pathA).Sauto(parser.Parse)

	done := map[string]bool{pathA: true}
	err = GenerateAll(cb.Ctx(), pathA, done)
	require.NoError(t, err)
	assert.Equal(t, 1, len(done))

	err = GenerateAll(cb.Ctx(), pathA, map[string]bool{})
	require.NoError(t, err)

	b, err := ioutil.ReadFile(filepath.Join(dirA, "generated.go"))
	require.NoError(t, err)
	assert.Contains(t, string(b), "type A struct")

	pathB, _ := cb.TempPackage("b", map[string]string{
		"pkg.yml": `
type: system:package
aliases: {"a": "` + pathA + `"}`,
		"b.yml": `
id: b
type: system:type
fields:
	a:
		type: system:@string`,
	})

	cb.Path(pathB).Sauto(parser.Parse)
	err = GenerateAll(cb.Ctx(), pathB, map[string]bool{})
	require.NoError(t, err)

}
開發者ID:kego,項目名稱:ke,代碼行數:48,代碼來源:generate_test.go

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

示例15: TestUnmarshal

func TestUnmarshal(t *testing.T) {

	cb := tests.Context("kego.io/tests/data").Jauto().Sauto(parser.Parse)

	s := `{
	"type": "simple",
	"js": "a"
}`

	n, err := node.Unmarshal(cb.Ctx(), []byte(s))
	require.NoError(t, err)
	m, ok := n.Value.(*data.Simple)
	require.True(t, ok)
	assert.Equal(t, "a", m.Js)

}
開發者ID:kego,項目名稱:ke,代碼行數:16,代碼來源:node_ext_test.go


注:本文中的kego/io/tests.Context函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。