Skip to content

Commit

Permalink
fix(Test): various check errors in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
crhntr committed Feb 19, 2025
1 parent 1f245b0 commit 7a19f2b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 34 deletions.
2 changes: 1 addition & 1 deletion cmd/muxt/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Test_example(t *testing.T) {
})
}

func TestGenerate(t *testing.T) {
func Test(t *testing.T) {
e := script.NewEngine()
e.Quiet = true
e.Cmds = scripttest.DefaultCmds()
Expand Down
4 changes: 2 additions & 2 deletions cmd/muxt/testdata/blog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ var _ blog.RoutesReceiver = new(App)

{{define "article-page"}}
{{if .Request.Header.Get "HX-Request" }}
{{template "page-body" .}}
{{template "article-content" .}}
{{else}}
<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -478,7 +478,7 @@ var _ blog.RoutesReceiver = new(App)

{{define "article-page"}}
{{if .Request.Header.Get "HX-Request" }}
{{template "page-body" .}}
{{template "article-content" .}}
{{else}}
<!DOCTYPE html>
<html lang="en">
Expand Down
24 changes: 12 additions & 12 deletions cmd/muxt/testdata/form_basic_fields.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ var templatesDir embed.FS
var templates = template.Must(template.ParseFS(templatesDir, "template.gohtml"))
-- template.gohtml --
{{- define "GET / F(form)" -}}
FieldInt={{.FieldInt}}
FieldInt64={{.FieldInt64}}
FieldInt32={{.FieldInt32}}
FieldInt16={{.FieldInt16}}
FieldInt8={{.FieldInt8}}
FieldUint={{.FieldUint}}
FieldUint64={{.FieldUint64}}
FieldUint32={{.FieldUint32}}
FieldUint16={{.FieldUint16}}
FieldUint8={{.FieldUint8}}
FieldBool={{.FieldBool}}
FieldTime={{.FieldTime}}
FieldInt={{.Result.FieldInt}}
FieldInt64={{.Result.FieldInt64}}
FieldInt32={{.Result.FieldInt32}}
FieldInt16={{.Result.FieldInt16}}
FieldInt8={{.Result.FieldInt8}}
FieldUint={{.Result.FieldUint}}
FieldUint64={{.Result.FieldUint64}}
FieldUint32={{.Result.FieldUint32}}
FieldUint16={{.Result.FieldUint16}}
FieldUint8={{.Result.FieldUint8}}
FieldBool={{.Result.FieldBool}}
FieldTime={{.Result.FieldTime}}
{{- end -}}
-- in.go --
package main
Expand Down
5 changes: 4 additions & 1 deletion cmd/muxt/testdata/path_param.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
muxt generate
muxt check

! muxt check
stderr 'checking endpoint GET /fruits/\{name\}/tree ToUpper\(name\)'
stderr 'ERROR type check failed: template.gohtml:2:20: Name not found on any'

exec go test -cover

Expand Down
17 changes: 8 additions & 9 deletions cmd/muxt/testdata/result_import_result_type.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func Test(t *testing.T) {
}
body, _ := io.ReadAll(res.Body)

if !strings.Contains(string(body), `<textarea name="Title" value=""></textarea>`) {
if !strings.Contains(string(body), `<input name="Title">`) {
t.Error(string(body))
}
})
Expand All @@ -67,7 +67,7 @@ func Test(t *testing.T) {
t.Fail()
}
body, _ := io.ReadAll(res.Body)
if !strings.Contains(string(body), `<textarea name="Title" value="HELLO"></textarea>`) {
if !strings.Contains(string(body), `<input name="Title" value="HELLO">`) {
t.Error(string(body))
}
})
Expand Down Expand Up @@ -112,15 +112,14 @@ var (
templates = template.Must(template.ParseFS(templateFiles, "*"))
)
-- internal/hypertext/form.gohtml --
<form method="POST" action="/article">
<textarea name="Title" value="{{if .}}{{.Title}}{{end}}"></textarea>
</form>
<details><summary>data</summary><pre>{{printf "%#v" .}}</pre></details>

{{- define "POST /article CreatArticle(ctx, form)" -}}
{{- template "form.gohtml" .Result -}}
<form method="POST" action="/article">
<input name="Title" value="{{if .}}{{.Result.Title}}{{end}}">
</form>
{{- end -}}

{{- define "GET /article/new" -}}
{{- template "form.gohtml" -}}
<form method="POST" action="/article">
<input name="Title">
</form>
{{- end -}}
17 changes: 8 additions & 9 deletions cmd/muxt/testdata/result_named_result_type.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func Test(t *testing.T) {
}
body, _ := io.ReadAll(res.Body)

if !strings.Contains(string(body), `<textarea name="Title" value=""></textarea>`) {
if !strings.Contains(string(body), `<input name="Title">`) {
t.Error(string(body))
}
})
Expand All @@ -67,7 +67,7 @@ func Test(t *testing.T) {
t.Fail()
}
body, _ := io.ReadAll(res.Body)
if !strings.Contains(string(body), `<textarea name="Title" value="HELLO"></textarea>`) {
if !strings.Contains(string(body), `<input name="Title" value="HELLO">`) {
t.Error(string(body))
}
})
Expand Down Expand Up @@ -104,15 +104,14 @@ var (
templates = template.Must(template.ParseFS(templateFiles, "*"))
)
-- internal/hypertext/form.gohtml --
<form method="POST" action="/article">
<textarea name="Title" value="{{if .}}{{.Title}}{{end}}"></textarea>
</form>
<details><summary>data</summary><pre>{{printf "%#v" .}}</pre></details>

{{- define "POST /article CreatArticle(ctx, form)" -}}
{{- template "form.gohtml" .Result -}}
<form method="POST" action="/article">
<input name="Title" value="{{.Result.Title}}">
</form>
{{- end -}}

{{- define "GET /article/new" -}}
{{- template "form.gohtml" -}}
<form method="POST" action="/article">
<input name="Title">
</form>
{{- end -}}

0 comments on commit 7a19f2b

Please sign in to comment.