-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add custom Delims support #860
Changes from 7 commits
556287f
63b5d1c
7dc96be
041ca04
e2212d4
edd55b5
e8ce83e
23d0ee8
b4e7ec8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Hello {[{.name}]}</h1> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,60 @@ import ( | |
"reflect" | ||
"testing" | ||
|
||
"net/http" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why all these blank lines? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the miss inspection, this was auto import package and format style by the vscode. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove the empty line for import native package. |
||
"fmt" | ||
"io/ioutil" | ||
|
||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func setupHTMLFiles(t *testing.T) func() { | ||
go func() { | ||
router := New() | ||
router.Delims("{[{", "}]}") | ||
router.LoadHTMLFiles("./fixtures/basic/hello.tmpl") | ||
router.GET("/test", func(c *Context) { | ||
c.HTML(http.StatusOK, "hello.tmpl", map[string]string{"name": "world"}) | ||
}) | ||
router.Run(":8888") | ||
}() | ||
t.Log("waiting 1 second for server startup") | ||
time.Sleep(1 * time.Second) | ||
return func() {} | ||
} | ||
|
||
func setupHTMLGlob(t *testing.T) func() { | ||
go func() { | ||
router := New() | ||
router.Delims("{[{", "}]}") | ||
router.LoadHTMLGlob("./fixtures/basic/*") | ||
router.GET("/test", func(c *Context) { | ||
c.HTML(http.StatusOK, "hello.tmpl", map[string]string{"name": "world"}) | ||
}) | ||
router.Run(":8888") | ||
}() | ||
t.Log("waiting 1 second for server startup") | ||
time.Sleep(1 * time.Second) | ||
return func() {} | ||
} | ||
|
||
//TODO | ||
// func (engine *Engine) LoadHTMLGlob(pattern string) { | ||
func TestLoadHTMLGlob(t *testing.T) { | ||
td := setupHTMLGlob(t) | ||
res, err := http.Get("http://127.0.0.1:8888/test") | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
resp, _ := ioutil.ReadAll(res.Body) | ||
assert.Equal(t, "<h1>Hello world</h1>", string(resp[:])) | ||
|
||
td() | ||
} | ||
|
||
// func (engine *Engine) LoadHTMLFiles(files ...string) { | ||
// func (engine *Engine) RunTLS(addr string, cert string, key string) error { | ||
|
||
|
@@ -42,6 +91,18 @@ func TestCreateEngine(t *testing.T) { | |
// SetMode(TestMode) | ||
// } | ||
|
||
func TestLoadHTMLFiles(t *testing.T) { | ||
td := setupHTMLFiles(t) | ||
res, err := http.Get("http://127.0.0.1:8888/test") | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
resp, _ := ioutil.ReadAll(res.Body) | ||
assert.Equal(t, "<h1>Hello world</h1>", string(resp[:])) | ||
td() | ||
} | ||
|
||
func TestLoadHTMLReleaseMode(t *testing.T) { | ||
|
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this comments code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shenshouer Please remove this comments.