tracing url parsing
This commit is contained in:
parent
fbb8bcd2c8
commit
c79518125b
11
url_test.go
11
url_test.go
@ -57,13 +57,17 @@ func printURLTree(t *testing.T, a Node) {
|
|||||||
notation.Lprintw(t, a)
|
notation.Lprintw(t, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
func urlParser() func(string) (Node, error) {
|
func urlParser(trace bool) func(string) (Node, error) {
|
||||||
b, err := os.ReadFile("doc/example/url.treerack")
|
b, err := os.ReadFile("doc/example/url.treerack")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
p := new(Syntax)
|
p := new(Syntax)
|
||||||
|
if trace {
|
||||||
|
p.MaxTraceLength = 180
|
||||||
|
}
|
||||||
|
|
||||||
if err = p.ReadSyntax(bytes.NewBuffer(b)); err != nil {
|
if err = p.ReadSyntax(bytes.NewBuffer(b)); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -1524,12 +1528,13 @@ func TestURL(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var d time.Duration
|
var d time.Duration
|
||||||
p := urlParser()
|
p := urlParser(test.bench <= 0)
|
||||||
for i := 0; i < n && !t.Failed(); i++ {
|
for i := 0; i < n && !t.Failed(); i++ {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
a, err := p(test.input)
|
a, err := p(test.input)
|
||||||
d += time.Since(start)
|
d += time.Since(start)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Trace(t.Output(), err)
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1581,7 +1586,7 @@ func TestURLErrors(t *testing.T) {
|
|||||||
input: "http://foo.bar/foo%xbar",
|
input: "http://foo.bar/foo%xbar",
|
||||||
}} {
|
}} {
|
||||||
t.Run(test.title, func(t *testing.T) {
|
t.Run(test.title, func(t *testing.T) {
|
||||||
p := urlParser()
|
p := urlParser(false)
|
||||||
if a, err := p(test.input); err == nil {
|
if a, err := p(test.input); err == nil {
|
||||||
printURLTree(t, a)
|
printURLTree(t, a)
|
||||||
t.Fatal("failed to fail", test.input)
|
t.Fatal("failed to fail", test.input)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user