Beispiel #1
0
func TestResolver(t *testing.T) {
	rx := dispatch.NewResolver("/:id")
	params, _, state := rx.Test("12")

	if !state {
		tests.Failed(t, "Should have matched giving path")
	}
	tests.Passed(t, "Should have matched giving path")

	val, ok := params["id"]
	if !ok {
		tests.Failed(t, "Should have retrieve parameter :id => %s", val)
	}
	tests.Passed(t, "Should have retrieve parameter :id => %s", val)

	rx.ResolvedPassed(func(px dispatch.Path) {
		tests.Passed(t, "Should have notified with Path %#v", px)
	})

	rx.ResolvedFailed(func(px dispatch.Path) {
		tests.Failed(t, "Should have notified with Path %#v", px)
	})

	rx.Resolve(dispatch.UseLocation("/12"))
}
Beispiel #2
0
func TestResolverLevels(t *testing.T) {
	home := dispatch.NewResolver("/home/*")
	rx := dispatch.NewResolver("/:id")

	home.Register(rx)

	rx.ResolvedPassed(func(px dispatch.Path) {
		tests.Passed(t, "Should have notified with Path %#v", px)
	})

	rx.ResolvedFailed(func(px dispatch.Path) {
		tests.Failed(t, "Should have notified with Path %#v", px)
	})

	home.Resolve(dispatch.UseLocation("home/12"))
}
Beispiel #3
0
// newResource creates a new ResourceDefinition instance and adds the
// new resource into the root ResourceDefinition list.
func newResource(root *Resources, dsl DSL) *ResourceDefinition {
	var rs ResourceDefinition
	rs.Dsl = dsl
	rs.Order = Any
	rs.Root = root
	rs.uuid = gu.NewKey()
	rs.Manager = gu.NewRouteManager()
	rs.Resolver = dispatch.NewResolver("*")

	rsp := &rs
	root.Resources = append(root.Resources, rsp)

	dispatch.Subscribe(func(rv *ResourceViewUpdate) {

		if rv.Resource != rsp.uuid {
			return
		}

		if !rsp.active {
			return
		}

		rs.Root.renderer.RenderUpdate(rv.View, rv.Target, true)
	})

	return rsp
}
Beispiel #4
0
func TestResolverFailed(t *testing.T) {
	rx := dispatch.NewResolver("/:id")
	rx.ResolvedPassed(func(px dispatch.Path) {
		tests.Failed(t, "Should have notified with failed Path %#v", px)
	})

	rx.ResolvedFailed(func(px dispatch.Path) {
		tests.Passed(t, "Should have notified with failed Path %#v", px)
	})

	rx.Resolve(dispatch.UseLocation("/home/12"))
}
Beispiel #5
0
// Routing returns a new instance of a Routing struct.
func newRouting(path string, morpher trees.SwitchMorpher) *routing {
	var rs routing
	rs.m = morpher
	rs.Resolver = dispatch.NewResolver(path)

	rs.Resolver.ResolvedPassed(func(p dispatch.Path) {
		morpher.Off(p)
	}).ResolvedFailed(func(p dispatch.Path) {
		morpher.On(p)
	})

	morpher.On(nil)

	return &rs
}
Beispiel #6
0
// UseRoute sets the giving route for the currently used resource of the giving resource root.
func UseRoute(path string) {
	getResources().MustCurrentResource().Resolver = dispatch.NewResolver(path)
}