<commit_before>package router

import (
	"fmt"
	"math"
	"math/rand"
	"net/http"
	"net/http/httptest"
	"testing"

	"golang.scot/liberty/middleware"
)

/*func TestExactMatch(t *testing.T) {
	router := &HTTPRouter{}
	mux := http.NewServeMux()
	sg := &ServerGroup{servers: []*server{{s: &http.Server{Handler: mux}, handler: mux}}}
	if err := router.put("http://www.example.com", sg); err != nil {
		t.Errorf("insertion error: foo")
	}
	if match := router.Getc("http://www.example.com"); match == nil {
		t.Errorf("bad search: foo")
	}
}
*/

func newServerGroup() http.Handler {
	mux := http.NewServeMux()
	return mux
	//return &balancer.ServerGroup{servers: []*server{{s: &http.Server{Handler: mux}, handler: mux}}}
}

func httpWriterRequest(urlPath string) (http.ResponseWriter, *http.Request) {
	w := httptest.NewRecorder()
	req, _ := http.NewRequest("GET", urlPath, nil)
	return w, req
}

func newRouter() *HTTPRouter {
	router := NewHTTPRouter()
	router.Use(
		[]middleware.Chainable{&middleware.HelloWorld{}},
	)

	return router
}

func TestRouteMatch(t *testing.T) {
	router := newRouter()
	mux := http.NewServeMux()

	ctx := ctxPool.Get().(*Context)
	ctx.Reset()

	if err := router.Handle("/test/example/path", mux); err != nil {
		t.Error(err)
	}
	match := router.match("/test/example/path", ctx)
	if match == nil {
		t.Errorf("bad search:")
	}

	if fmt.Sprintf("%p", mux) != fmt.Sprintf("%p", match) {
		t.Errorf("address mismatch: - h: %#v,  match: %#v", mux, match)
	}

	ctxPool.Put(ctx)
}

func TestMatchLastVar(t *testing.T) {

	router := NewHTTPRouter()<commit_msg>test for deeper path placeholders<commit_after>package router

import (
	"fmt"
	"math"
	"math/rand"
	"net/http"
	"net/http/httptest"
	"testing"

	"golang.scot/liberty/middleware"
)

/*func TestExactMatch(t *testing.T) {
	router := &HTTPRouter{}
	mux := http.NewServeMux()
	sg := &ServerGroup{servers: []*server{{s: &http.Server{Handler: mux}, handler: mux}}}
	if err := router.put("http://www.example.com", sg); err != nil {
		t.Errorf("insertion error: foo")
	}
	if match := router.Getc("http://www.example.com"); match == nil {
		t.Errorf("bad search: foo")
	}
}
*/

func newServerGroup() http.Handler {
	mux := http.NewServeMux()
	return mux
	//return &balancer.ServerGroup{servers: []*server{{s: &http.Server{Handler: mux}, handler: mux}}}
}

func httpWriterRequest(urlPath string) (http.ResponseWriter, *http.Request) {
	w := httptest.NewRecorder()
	req, _ := http.NewRequest("GET", urlPath, nil)
	return w, req
}

func newRouter() *HTTPRouter {
	router := NewHTTPRouter()
	router.Use(
		[]middleware.Chainable{&middleware.HelloWorld{}},
	)

	return router
}

func TestRouteMatch(t *testing.T) {
	router := newRouter()
	mux := http.NewServeMux()

	ctx := ctxPool.Get().(*Context)
	ctx.Reset()

	if err := router.Handle("/test/example/path", mux); err != nil {
		t.Error(err)
	}
	match := router.match("/test/example/path", ctx)
	if match == nil {
		t.Errorf("bad search:")
	}

	if fmt.Sprintf("%p", mux) != fmt.Sprintf("%p", match) {
		t.Errorf("address mismatch: - h: %#v,  match: %#v", mux, match)
	}

	ctxPool.Put(ctx)
}

func TestBenchMatchFail01(t *testing.T) {
	testPath := "/test/test/test/test/test"
	fiveColon := "/:a/:b/:c/:d/:e"

	router := newRouter()
	mux := http.NewServeMux()

	ctx := ctxPool.Get().(*Context)
	ctx.Reset()

	if err := router.Handle(fiveColon, mux); err != nil {
		t.Error(err)
	}
	match := router.match(testPath, ctx)
	if match == nil {
		t.Errorf("bad search:")
	}

	if fmt.Sprintf("%p", mux) != fmt.Sprintf("%p", match) {
		t.Errorf("address mismatch: - h: %#v,  match: %#v", mux, match)
	}

	ctxPool.Put(ctx)

}

func TestMatchLastVar(t *testing.T) {

	router := NewHTTPRouter()
{'fraction_non_alphanumeric': 0.19794205253181696, 'fraction_numerical': 0.0005415651232060655, 'mean_word_length': 4.284692417739628, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '309429', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1439, 'n_words': 290}