示例#1
0
文件: parser_test.go 项目: kego/ke
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

}
示例#2
0
文件: parser_test.go 项目: kego/ke
func TestImportSystem(t *testing.T) {

	cb := tests.New().TempGopath(true)
	defer cb.Cleanup()

	pathA, dirA := cb.TempPackage("a", map[string]string{
		"package.json": `{
			"type": "system:package",
			"aliases": {
				"s": "kego.io/system"
			}
		}`,
	})
	cb.Path(pathA).Dir(dirA).Cmd().Sempty().Jsystem()
	_, err := Parse(cb.Ctx(), pathA)
	assert.IsError(t, err, "EWMLNJDXKC")

	pathB, dirB := cb.TempPackage("b", map[string]string{
		"package.json": `{
			"type": "system:package",
			"aliases": {
				"system": "a.b/c"
			}
		}`,
	})
	cb.Path(pathB).Dir(dirB)
	_, err = Parse(cb.Ctx(), pathB)
	assert.IsError(t, err, "EWMLNJDXKC")

}
示例#3
0
文件: node_ext_test.go 项目: kego/ke
func TestNode_DeleteArrayChild2(t *testing.T) {
	_, n := data.Setup(t)
	err := n.DeleteArrayChild(0)
	assert.IsError(t, err, "NFVEWWCSMV")
	err = n.Map["mjs"].DeleteArrayChild(0)
	assert.IsError(t, err, "NFVEWWCSMV")
}
示例#4
0
文件: parser_test.go 项目: kego/ke
func TestRuleId(t *testing.T) {

	cb := tests.New().TempGopath(true)
	defer cb.Cleanup()

	pathA, dirA := cb.TempPackage("a", map[string]string{
		"a.json": `{
			"type": "system:type",
			"id": "a",
			"rule": {
				"type": "system:type",
				"id": "foo"
			}
		}`,
	})
	cb.Path(pathA).Dir(dirA).Cmd().Sempty().Jsystem()
	_, err := Parse(cb.Ctx(), pathA)
	assert.IsError(t, err, "VFUNPHUFHD")
	assert.HasError(t, err, "JKARKEDTIW")

	cb.TempFile("a.json", `{
			"type": "system:type",
			"id": "a",
			"rule": {
				"type": "system:type"
			}
		}`)
	_, err = Parse(cb.Ctx(), pathA)
	assert.IsError(t, err, "VFUNPHUFHD")
	assert.HasError(t, err, "LMALEMKFDI")
}
示例#5
0
文件: node_ext_test.go 项目: kego/ke
func TestNode_ReorderArrayChild2(t *testing.T) {
	_, n := data.Setup(t)
	err := n.ReorderArrayChild(0, 1)
	assert.IsError(t, err, "MHEXGBUQOL")
	err = n.Map["mjs"].ReorderArrayChild(0, 1)
	assert.IsError(t, err, "MHEXGBUQOL")
}
示例#6
0
文件: node_ext_test.go 项目: kego/ke
func TestNode_DeleteObjectChild2(t *testing.T) {
	cb, n := data.Setup(t)
	err := n.Map["mjs"].DeleteObjectChild(cb.Ctx(), "a")
	assert.IsError(t, err, "BMUSITINTC")
	err = n.Map["ajs"].DeleteObjectChild(cb.Ctx(), "a")
	assert.IsError(t, err, "BMUSITINTC")
}
示例#7
0
文件: node_ext_test.go 项目: kego/ke
func TestNode_DeleteMapChild2(t *testing.T) {
	_, n := data.Setup(t)
	err := n.DeleteMapChild("js")
	assert.IsError(t, err, "ACRGPCPPFK")
	err = n.Map["ajs"].DeleteMapChild("a")
	assert.IsError(t, err, "ACRGPCPPFK")
}
示例#8
0
文件: validate_test.go 项目: kego/ke
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)

}
示例#9
0
文件: node_ext_test.go 项目: kego/ke
func TestNode_InitialiseArrayChild2(t *testing.T) {
	cb, n := data.Setup(t)
	c := node.NewNode()
	require.NoError(t, c.InitialiseArrayItem(cb.Ctx(), n.Map["ajs"], 5))
	err := c.AddToArray(cb.Ctx(), n.Map["ajs"], 5, true)
	assert.IsError(t, err, "GHJIDXABLL")

	// kludge the Val to be empty
	n.Map["ajs"].Val.Set(reflect.ValueOf([]string{}))
	require.NoError(t, c.InitialiseArrayItem(cb.Ctx(), n.Map["ajs"], 1))
	err = c.AddToArray(cb.Ctx(), n.Map["ajs"], 1, true)
	assert.IsError(t, err, "YFKMXFUPHY")

}
示例#10
0
文件: builder_test.go 项目: kego/ke
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

}
示例#11
0
文件: validate_test.go 项目: kego/ke
func TestFieldExtraRulesObject(t *testing.T) {
	cb := tests.New().TempGopath(true).CopyToTemp("kego.io/process/validate/tests")
	defer cb.Cleanup()

	path, dir := cb.TempPackage("a", map[string]string{
		"a.yml": `
			type: system:package
			id: a
			aliases:
				tests: kego.io/process/validate/tests
		`,
		"b.yml": `
			type: tests:f
			id: b
			a:
				type: tests:a
				b: foo
		`,
	})

	cb.Path(path).Dir(dir).Alias("tests", "kego.io/process/validate/tests").Jauto().Sauto(parser.Parse)

	errors, err := ValidatePackage(cb.Ctx())
	require.NoError(t, err)
	assert.IsError(t, errors[0], "HLKQWDCMRN")
}
示例#12
0
文件: validate_test.go 项目: kego/ke
func TestRuleHasExtraRules(t *testing.T) {
	cb := tests.New().TempGopath(true).CopyToTemp("kego.io/process/validate/tests")
	defer cb.Cleanup()

	path, dir := cb.TempPackage("a", map[string]string{
		"a.yml": `
			type: system:package
			id: a
			aliases:
				tests: kego.io/process/validate/tests
		`,
		"b.yml": `
			type: tests:f
			id: b
			d: foo
		`,
	})

	cb.Path(path).Dir(dir).Alias("tests", "kego.io/process/validate/tests").Jauto().Sauto(parser.Parse)

	errors, err := ValidatePackage(cb.Ctx())
	require.NoError(t, err)
	assert.IsError(t, errors[0], "HLKQWDCMRN")
	assert.Equal(t, "MinLength: length of \"foo\" must not be less than 7", errors[0].Description)
}
示例#13
0
文件: validate_test.go 项目: kego/ke
func TestValidate_error1(t *testing.T) {

	cb := tests.New().TempGopath(true)
	defer cb.Cleanup()

	path, dir := cb.TempPackage("b", map[string]string{
		"b.json": `{
			"description": "b",
			"type": "system:type",
			"id": "b",
			"fields": {
				"b": {
					"type": "system:@string",
					"min-length": 10,
					"max-length": 5
				}
			}
		}`,
	})

	cb.Path(path).Dir(dir).Jsystem().Sauto(parser.Parse)

	errors, err := ValidatePackage(cb.Ctx())
	// @string is invalid because minLength > maxLength
	require.NoError(t, err)
	assert.IsError(t, errors[0], "KULDIJUYFB")

}
示例#14
0
文件: validate_test.go 项目: kego/ke
func TestTestRulesApplyToObjects(t *testing.T) {
	cb := tests.New().TempGopath(true).CopyToTemp("kego.io/process/validate/tests")
	defer cb.Cleanup()

	path, dir := cb.TempPackage("a", map[string]string{
		"a.yml": `
			type: system:package
			id: a
			aliases:
				tests: kego.io/process/validate/tests
		`,
		"b.yml": `
			type: tests:a
			id: b
			b: foobar
			rules:
				-   selector: ".b"
					type: "system:@string"
					max-length: 5
		`,
	})

	cb.Path(path).Dir(dir).Alias("tests", "kego.io/process/validate/tests").Jauto().Sauto(parser.Parse)

	errors, err := ValidatePackage(cb.Ctx())
	require.NoError(t, err)
	assert.IsError(t, errors[0], "HLKQWDCMRN")

}
示例#15
0
文件: parser_test.go 项目: kego/ke
func TestCircularImport(t *testing.T) {

	cb := tests.New().TempGopath(true)
	defer cb.Cleanup()

	pathA, dirA := cb.TempPackage("a", map[string]string{})
	pathB, dirB := cb.TempPackage("b", map[string]string{})
	ioutil.WriteFile(filepath.Join(dirA, "package.json"), []byte(`
			{
				"type": "system:package",
				"aliases": {
					"b": "`+pathB+`"
				}
			}
		`), 0777)
	ioutil.WriteFile(filepath.Join(dirB, "package.json"), []byte(`
			{
				"type": "system:package",
				"aliases": {
					"a": "`+pathA+`"
				}
			}
		`), 0777)

	cb.Path(pathA).Dir(dirA).Cmd().Sempty().Jsystem()

	_, err := Parse(cb.Ctx(), pathA)
	assert.IsError(t, err, "NOVMGYKHHI")
	assert.HasError(t, err, "SCSCFJPPHD")

}
示例#16
0
文件: parser_test.go 项目: kego/ke
func TestNoTypeError(t *testing.T) {

	cb := tests.New().TempGopath(true)
	defer cb.Cleanup()

	pathA, dirA := cb.TempPackage("a", map[string]string{
		"a.json": `{
			"id": "a"
		}`,
	})
	cb.Path(pathA).Dir(dirA).Cmd().Sempty().Jsystem()
	_, err := Parse(cb.Ctx(), pathA)
	assert.IsError(t, err, "GJRHNGGWFD")
	assert.HasError(t, err, "MSNIGTIDIO")

	err = scanForTypesAndExports(cb.Ctx(), cb.Env(), nil, &PackageHasher{})
	assert.IsError(t, err, "NUKWIHYFMQ")

}
示例#17
0
文件: node_test.go 项目: kego/ke
func TestNode_extractFields(t *testing.T) {
	cb := tests.Context("a.b/c").Sempty()

	ty := &system.Type{}
	f := map[string]*system.Field{}
	err := extractFields(cb.Ctx(), f, ty)
	assert.IsError(t, err, "YRFWOTIGFT")

	cb.Ssystem(parser.Parse)

	ty = &system.Type{Embed: []*system.Reference{system.NewReference("a.b/c", "d")}}
	err = extractFields(cb.Ctx(), f, ty)
	assert.IsError(t, err, "SLIRILCARQ")

	f = map[string]*system.Field{"a": nil}
	ty = &system.Type{Fields: map[string]system.RuleInterface{"a": nil}}
	err = extractFields(cb.Ctx(), f, ty)
	assert.IsError(t, err, "BARXPFXQNB")
}
示例#18
0
文件: reference_test.go 项目: kego/ke
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")

}
示例#19
0
文件: node_test.go 项目: kego/ke
func TestNode_SetValueZero3(t *testing.T) {

	n := NewNode()
	err := n.setZero(context.Background(), false, true)
	assert.IsError(t, err, "NYQULBBBHO")

	n = NewNode()
	err = n.setZero(context.Background(), true, true)
	assert.IsError(t, err, "XRYLQWRNPH")

	n = NewNode()
	err = n.setZero(context.Background(), true, false)
	assert.IsError(t, err, "ABXFQOYCBA")

	n = NewNode()
	n.Type = &system.Type{Native: system.NewString("map")}
	err = n.setZero(context.Background(), false, false)
	assert.IsError(t, err, "VGKTIRMDTJ")

}
示例#20
0
文件: array_test.go 项目: kego/ke
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())
}
示例#21
0
文件: selectors_test.go 项目: kego/ke
func TestGetNodes(t *testing.T) {
	p := getParser(t)

	out, err := p.GetNodes(":root")
	require.NoError(t, err)
	assert.Equal(t, 1, len(out))

	// The lexer extracts a S_WORD token, which has no selector
	out, err = p.GetNodes("\"foo\"")
	assert.IsError(t, err, "QFXXVGGHSS")
	assert.HasError(t, err, "REPJTLCAMQ")

	// The lexer extracts a S_FLOAT token, which has no selector
	out, err = p.GetNodes("1.1")
	assert.IsError(t, err, "QFXXVGGHSS")
	assert.HasError(t, err, "REPJTLCAMQ")

	_, err = p.GetNodes(".a * * .b")
	assert.IsError(t, err, "QFXXVGGHSS")
	assert.HasError(t, err, "KLEORWJHSP")

}
示例#22
0
文件: rule_test.go 项目: kego/ke
func TestRuleWrapperItemsRule1(t *testing.T) {
	cb := tests.Context("a.b/c").Jempty()
	fooType := &Type{Object: &Object{Id: NewReference("a.b/c", "foo")}}
	fooRule := &fooRuleStruct{Rule: &Rule{}}
	foo := RuleWrapper{
		Ctx:       cb.Ctx(),
		Interface: fooRule,
		Struct:    fooRule.Rule,
		Parent:    fooType,
	}

	// String isn't a collection
	fooType.Native = NewString("string")
	_, err := foo.ItemsRule()
	assert.IsError(t, err, "VPAGXSTQHM")

	// FooRule isn't a collection rule
	fooType.Native = NewString("map")
	_, err = foo.ItemsRule()
	assert.IsError(t, err, "TNRVQVJIFH")

	barType := &Type{Object: &Object{Id: NewReference("a.b/c", "bar")}, Native: NewString("map")}
	barRule := &barRuleStruct{
		Object: &Object{},
		Rule:   &Rule{},
	}
	bar := RuleWrapper{
		Ctx:       cb.Ctx(),
		Interface: barRule,
		Struct:    barRule.Rule,
		Parent:    barType,
	}
	// barRule has nil Items
	_, err = bar.ItemsRule()
	assert.IsError(t, err, "SUJLYBXPYS")

}
示例#23
0
文件: generate_test.go 项目: kego/ke
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)

}
示例#24
0
文件: map_test.go 项目: kego/ke
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())

}
示例#25
0
文件: parser_test.go 项目: kego/ke
func TestNoIdError(t *testing.T) {

	cb := tests.New().TempGopath(true)
	defer cb.Cleanup()

	pathA, dirA := cb.TempPackage("a", map[string]string{
		"a.json": `{
			"type": "system:type"
		}`,
	})
	cb.Path(pathA).Dir(dirA).Cmd().Sempty().Jsystem()
	_, err := Parse(cb.Ctx(), pathA)
	assert.IsError(t, err, "VFUNPHUFHD")
	assert.HasError(t, err, "DLLMKTDYFW")

}
示例#26
0
文件: reference_test.go 项目: kego/ke
func TestReferenceValue(t *testing.T) {

	r := NewReference("a.b/c", "d")
	assert.Equal(t, "a.b/c:d", r.Value())
	assert.Equal(t, "a.b/c:d", r.String())
	assert.Equal(t, "a.b/c:d", r.NativeString())

	r = NewReference("", "")
	assert.Equal(t, "", r.Value())
	assert.Equal(t, "", r.String())
	assert.Equal(t, "", r.NativeString())

	v, err := r.ValueContext(context.Background())
	require.NoError(t, err)
	assert.Equal(t, "", v)

	cb := tests.Context("a.b/c")
	v, err = r.ValueContext(cb.Ctx())
	require.NoError(t, err)
	assert.Equal(t, "", v)

	r = NewReference("a.b/c", "d")
	v, err = r.ValueContext(cb.Ctx())
	require.NoError(t, err)
	assert.Equal(t, "d", v)

	r = NewReference("kego.io/json", "a")
	v, err = r.ValueContext(cb.Ctx())
	require.NoError(t, err)
	assert.Equal(t, "json:a", v)

	r = NewReference("kego.io/system", "a")
	v, err = r.ValueContext(cb.Ctx())
	require.NoError(t, err)
	assert.Equal(t, "system:a", v)

	cb.Alias("g", "d.e/f")
	r = NewReference("d.e/f", "h")
	v, err = r.ValueContext(cb.Ctx())
	require.NoError(t, err)
	assert.Equal(t, "g:h", v)

	r = NewReference("i.j/k", "l")
	v, err = r.ValueContext(cb.Ctx())
	assert.IsError(t, err, "WGCDQQCFAD")

}
示例#27
0
文件: parser_test.go 项目: kego/ke
func TestGoGet(t *testing.T) {
	cb := tests.New().TempGopath(true).Cmd()
	defer cb.Cleanup()
	pathA, _ := cb.TempPackage("a", map[string]string{
		"a.json": `{
			"type": "system:type",
			"id": "a"
		}`,
	})
	err := GoGet(cb.Ctx(), pathA)
	require.NoError(t, err)

	cb.CmdUpdate(true)
	err = GoGet(cb.Ctx(), pathA)
	assert.IsError(t, err, "NIKCKQAKUI")

}
示例#28
0
func TestInitialise(t *testing.T) {

	cb := tests.New().TempGopath(true)
	defer cb.Cleanup()

	pathA, dirA := cb.TempPackage("a", map[string]string{
		"a.json": `{"type": "system:type", "id": "a"}`,
		"a.go":   "package a",
	})
	pathB, dirB := cb.TempPackage("b", map[string]string{
		"b.json": `{"type": "system:type", "id": "b"}`,
		"b.go":   "package b",
	})

	cb.OsWd(dirA)

	ctx, _, err := Initialise(cb.Ctx(), nil)
	require.NoError(t, err)
	env := envctx.FromContext(ctx)
	assert.Equal(t, dirA, env.Dir)
	assert.Equal(t, pathA, env.Path)

	cb.OsWd("/")

	ctx, _, err = Initialise(ctx, &Options{
		Path: pathB,
	})
	env = envctx.FromContext(ctx)
	require.NoError(t, err)
	assert.Equal(t, dirB, env.Dir)
	assert.Equal(t, pathB, env.Path)

	_, _, err = Initialise(ctx, &Options{
		Path: "",
	})
	assert.IsError(t, err, "ADNJKTLAWY")
	assert.HasErrorExternal(t, err, "CXOETFPTGM")
}
示例#29
0
文件: ke_test.go 项目: kego/ke
func TestKego(t *testing.T) {

	ctx := ke.NewContext(context.Background(), "kego.io/system", nil)

	_, err := ke.Open(ctx, "")
	assert.IsError(t, err, "CXIULJCEBE")

	systemDir, err := packages.GetDirFromPackage(ctx, "kego.io/system")
	require.NoError(t, err)

	i, err := ke.Open(ctx, filepath.Join(systemDir, "type.json"))
	require.NoError(t, err)
	_, ok := i.(*system.Type)
	assert.True(t, ok)

	b, err := ioutil.ReadFile(filepath.Join(systemDir, "type.json"))
	require.NoError(t, err)

	var i1 interface{}
	err = ke.Unmarshal(ctx, b, &i1)
	require.NoError(t, err)
	_, ok = i1.(*system.Type)
	assert.True(t, ok)

	r := &system.Reference{}
	err = ke.Unmarshal(ctx, []byte(`"type"`), r)
	require.NoError(t, err)
	assert.Equal(t, *system.NewReference("kego.io/system", "type"), *r)

	b3, err := ke.Marshal(ctx, system.NewReference("kego.io/system", "type"))
	require.NoError(t, err)
	assert.Equal(t, "{\"type\":\"reference\",\"value\":\"type\"}", string(b3))

	b4, err := ke.MarshalIndent(ctx, &system.Package{Recursive: true}, "", " ")
	require.NoError(t, err)
	assert.Equal(t, "{\n \"recursive\": true\n}", string(b4))

}
示例#30
0
文件: int_test.go 项目: kego/ke
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")

}