コード例 #1
0
ファイル: type_ext_test.go プロジェクト: kego/ke
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())

}
コード例 #2
0
ファイル: initialise_test.go プロジェクト: kego/ke
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)

}
コード例 #3
0
ファイル: node_ext_test.go プロジェクト: kego/ke
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)

}
コード例 #4
0
ファイル: parser_test.go プロジェクト: kego/ke
func TestParse1(t *testing.T) {

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

	path, dir := cb.TempPackage("a", map[string]string{
		"a.json": `{
			"description": "a",
			"type": "system:type",
			"id": "b",
			"fields": {
				"c": {
					"type": "system:@string"
				}
			}
		}`,
	})

	cb.Path(path).Dir(dir).Cmd().Sempty().Jsystem()

	_, err := Parse(cb.Ctx(), path)
	require.NoError(t, err)

	scache := sysctx.FromContext(cb.Ctx())
	i, ok := scache.GetType(path, "b")
	assert.True(t, ok)
	ty, ok := i.(*system.Type)
	assert.True(t, ok)
	assert.Equal(t, "a", ty.Description)

}
コード例 #5
0
ファイル: bool_test.go プロジェクト: kego/ke
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)

}
コード例 #6
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)

}
コード例 #7
0
ファイル: utilities_test.go プロジェクト: kego/ke
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}))
}
コード例 #8
0
ファイル: utilities_test.go プロジェクト: kego/ke
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"))
}
コード例 #9
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())
}
コード例 #10
0
ファイル: logger_test.go プロジェクト: kego/ke
func TestLogger(t *testing.T) {
	_, o, e := Logger(false)
	_, ok := o.(*bytes.Buffer)
	assert.True(t, ok)
	_, ok = e.(*bytes.Buffer)
	assert.True(t, ok)

	_, o, e = Logger(true)
	_, ok = o.(*multiWriter)
	assert.True(t, ok)
	_, ok = e.(*multiWriter)
	assert.True(t, ok)
}
コード例 #11
0
ファイル: rule_ext_test.go プロジェクト: kego/ke
func checkReflectType(ctx context.Context, t *testing.T, path string, name string, field string, output string) {
	scache := sysctx.FromContext(ctx)
	p, ok := scache.Get(path)
	assert.True(t, ok)
	typ, ok := p.Types.Get(name)
	assert.True(t, ok)
	ty, ok := typ.Type.(*system.Type)
	assert.True(t, ok)
	r, ok := ty.Fields[field]
	assert.True(t, ok)
	rh := system.WrapRule(ctx, r)
	rt, err := rh.GetReflectType()
	require.NoError(t, err)
	assert.Equal(t, output, rt.String())
}
コード例 #12
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())

}
コード例 #13
0
func TestLoopDetectorInner(t *testing.T) {
	s1 := &mockStore1{}
	s2 := &mockStore2{}
	s3 := &mockStore3{}
	s4 := &mockStore4{}
	s5 := &mockStore5{}
	s6 := &mockStore6{}
	d := newLoopDetector()

	found, store := d.request(s1, s2)
	assert.False(t, found)
	assert.Nil(t, store)
	found, store = d.request(s2, s3)
	assert.False(t, found)
	assert.Nil(t, store)
	found, store = d.request(s3, s1)
	assert.True(t, found)
	assert.Equal(t, s1, store)
	found, store = d.request(s4, s5)
	assert.False(t, found)
	assert.Nil(t, store)
	found, store = d.request(s6, s4)
	assert.False(t, found)
	assert.Nil(t, store)
}
コード例 #14
0
ファイル: node_ext_test.go プロジェクト: kego/ke
func TestNode_SetValueZero3(t *testing.T) {
	cb, n := data.Empty(t)
	f, ok := system.GetTypeFromCache(cb.Ctx(), "kego.io/tests/data", "face")
	assert.True(t, ok)
	err := n.SetValueZero(cb.Ctx(), true, f)
	assert.HasError(t, err, "VHOSYBMDQL")
}
コード例 #15
0
ファイル: bool_test.go プロジェクト: kego/ke
func TestNewBool(t *testing.T) {
	b := NewBool(true)
	assert.True(t, b.Value())

	b1 := NewBool(false)
	assert.False(t, b1.Value())
}
コード例 #16
0
ファイル: node_ext_test.go プロジェクト: kego/ke
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)

}
コード例 #17
0
ファイル: node_ext_test.go プロジェクト: kego/ke
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)
}
コード例 #18
0
ファイル: reference_test.go プロジェクト: kego/ke
func TestGetDefault(t *testing.T) {
	rr := &ReferenceRule{Default: NewReference("a.b/c", "d")}
	d := rr.GetDefault()
	dr, ok := d.(*Reference)
	assert.True(t, ok)
	assert.Equal(t, *NewReference("a.b/c", "d"), *dr)
}
コード例 #19
0
ファイル: string_test.go プロジェクト: kego/ke
func TestStringGetDefault(t *testing.T) {
	r := StringRule{Default: NewString("a")}
	i := r.GetDefault()
	s, ok := i.(*String)
	assert.True(t, ok)
	assert.Equal(t, "a", s.Value())
}
コード例 #20
0
ファイル: compiler_test.go プロジェクト: kego/ke
func TestServer_Data(t *testing.T) {
	source := []byte(`
	package main
	import "fmt"
	func main(){
		fmt.Println("foo")
	}`)
	c, err := Compile(context.Background(), source, false)
	require.NoError(t, err)
	assert.True(t, len(c) > 100000) // should be ~700K

	m, err := Compile(context.Background(), source, true)
	require.NoError(t, err)
	assert.True(t, len(m) > 10000) // should be ~35K

}
コード例 #21
0
ファイル: bool_test.go プロジェクト: kego/ke
func TestBoolInterfaces(t *testing.T) {
	var nb NativeBool = NewBool(true)
	assert.True(t, nb.NativeBool())

	d := NewBool(true)
	var dr DefaultRule = &BoolRule{Default: d}
	assert.Equal(t, d, dr.GetDefault())
}
コード例 #22
0
ファイル: reference_test.go プロジェクト: kego/ke
func TestReferenceRule_Validate(t *testing.T) {
	r := &ReferenceRule{}
	fail, messages, err := r.Validate(envctx.Empty)
	require.NoError(t, err)
	assert.False(t, fail)
	assert.Equal(t, 0, len(messages))

	r = &ReferenceRule{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 = &ReferenceRule{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])
}
コード例 #23
0
ファイル: string_test.go プロジェクト: kego/ke
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])
}
コード例 #24
0
ファイル: object_test.go プロジェクト: kego/ke
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())

}
コード例 #25
0
ファイル: node_ext_test.go プロジェクト: kego/ke
func TestNode_InitialiseRoot(t *testing.T) {
	n := newNonEmptyNode()
	n.InitialiseRoot()
	assert.Nil(t, n.Parent)
	assert.Equal(t, 0, len(n.Array))
	assert.Equal(t, 0, len(n.Map))
	assert.Equal(t, "", n.Key)
	assert.Equal(t, -1, n.Index)
	assert.Nil(t, n.Origin)
	assert.Equal(t, "", n.ValueString)
	assert.Equal(t, 0.0, n.ValueNumber)
	assert.Equal(t, false, n.ValueBool)
	assert.Nil(t, n.Value)
	assert.Equal(t, reflect.Value{}, n.Val)
	assert.True(t, n.Null)
	assert.True(t, n.Missing)
	assert.Nil(t, n.Rule)
	assert.Nil(t, n.Type)
	assert.Equal(t, system.J_NULL, n.JsonType)
}
コード例 #26
0
ファイル: client_test.go プロジェクト: kego/ke
func TestRegisterTypes(t *testing.T) {
	cb := tests.New().Sempty().Jauto()

	imports := map[string]shared.ImportInfo{
		"a": {
			Path: "b",
			Types: map[string]shared.TypeInfo{
				"c": {Bytes: []byte(`{"type": "system:type", "id": "d"}`)},
			},
		},
		"g": {
			Path: "h",
			Types: map[string]shared.TypeInfo{
				"i": {Bytes: []byte(`{"type": "system:type", "id": "j"}`)},
			},
		},
	}
	pi, err := registerTypes(cb.Ctx(), "b", imports)
	require.NoError(t, err)

	ti, ok := pi.Types.Get("d")
	assert.True(t, ok)
	assert.Equal(t, "b:d", ti.Type.(*system.Type).Id.String())

	sc := sysctx.FromContext(cb.Ctx())

	pi, ok = sc.Get("b")
	assert.True(t, ok)

	ti, ok = pi.Types.Get("d")
	assert.True(t, ok)
	assert.Equal(t, "b:d", ti.Type.(*system.Type).Id.String())

	pi, ok = sc.Get("h")
	assert.True(t, ok)

	ti, ok = pi.Types.Get("j")
	assert.True(t, ok)
	assert.Equal(t, "h:j", ti.Type.(*system.Type).Id.String())

}
コード例 #27
0
ファイル: selectors_test.go プロジェクト: kego/ke
func TestUniversalProduction(t *testing.T) {
	p := getParser(t)

	f := p.universalProduction("a")
	out, err := f(&node.Node{})
	require.NoError(t, err)
	assert.False(t, out)

	f = p.universalProduction("*")
	out, err = f(&node.Node{})
	require.NoError(t, err)
	assert.True(t, out)
}
コード例 #28
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))

}
コード例 #29
0
func TestNewLoopDetector(t *testing.T) {
	s1 := &mockStore1{}
	s2 := &mockStore2{}
	d := newLoopDetector()

	found, store := d.request(s1, s2)
	assert.False(t, found)
	assert.Nil(t, store)

	found, store = d.request(s2, s1)
	assert.True(t, found)
	assert.Equal(t, s1, store)

	d.finished(s1)
	found, store = d.request(s2, s1)
	assert.False(t, found)
	assert.Nil(t, store)
}
コード例 #30
0
ファイル: scan_test.go プロジェクト: kego/ke
func getErrData(t *testing.T, args []ast.Expr, arg int, file string, pos token.Position) *errDef {
	require.True(t, len(args) > arg, "Not enough args (%s:%d)", file, pos.Line)
	b, ok := args[arg].(*ast.BasicLit)
	if !ok {
		return nil
	}
	require.Equal(t, b.Kind, token.STRING, "kind should be token.STRING (%s:%d)", file, pos.Line)
	id, err := strconv.Unquote(b.Value)
	require.NoError(t, err, "Error unquoting arg (%s:%d)", file, pos.Line)
	assert.True(t, ksrc.IsId(id), "Invalid kerr ID %s (%s:%d)", id, file, pos.Line)
	def, ok := all[id]
	if ok {
		return def
	}
	def = &errDef{}
	def.id = id
	all[id] = def
	return def
}