-
Notifications
You must be signed in to change notification settings - Fork 7
/
mux_test.go
44 lines (32 loc) · 1 KB
/
mux_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// SPDX-FileCopyrightText: 2014-2024 caixw
//
// SPDX-License-Identifier: MIT
package mux
import (
"testing"
"github.com/issue9/assert/v4"
"github.com/issue9/mux/v9/internal/tree"
)
func TestMethods(t *testing.T) {
a := assert.New(t, false)
a.Equal(Methods(), tree.Methods).
Equal(AnyMethods(), tree.AnyMethods).
Contains(Methods(), AnyMethods())
}
func TestCheckSyntax(t *testing.T) {
a := assert.New(t, false)
a.NotError(CheckSyntax("/{path"))
a.NotError(CheckSyntax("/path}"))
a.Error(CheckSyntax(""))
}
func TestURL(t *testing.T) {
a := assert.New(t, false)
url, err := URL("/posts/{id:}", map[string]string{"id": "100"})
a.NotError(err).Equal(url, "/posts/100")
url, err = URL("/posts/{id:}", nil)
a.NotError(err).Equal(url, "/posts/{id:}")
url, err = URL("/posts/{id:}", map[string]string{"other-": "id"})
a.Error(err).Empty(url)
url, err = URL("/posts/{id:\\\\d+}/author/{page}/", map[string]string{"id": "100", "page": "200"})
a.NotError(err).Equal(url, "/posts/100/author/200/")
}