Changed: DB Params

This commit is contained in:
2025-03-20 12:35:13 +01:00
parent 8640a12439
commit b71b3d12ca
822 changed files with 134218 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
<ul>
<li>raw</li>
<li>OK</li>
<li>OK2</li>
</ul>

View File

@@ -0,0 +1,57 @@
package teststringerrs
import (
"bytes"
"context"
_ "embed"
"errors"
"testing"
"github.com/a-h/templ"
"github.com/a-h/templ/generator/htmldiff"
)
//go:embed expected.html
var expected string
func Test(t *testing.T) {
t.Run("can render without error", func(t *testing.T) {
component := TestComponent(nil)
_, err := htmldiff.Diff(component, expected)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
})
t.Run("string expressions can return errors", func(t *testing.T) {
errSomethingBad := errors.New("bad error")
err := TestComponent(errSomethingBad).Render(context.Background(), &bytes.Buffer{})
if err == nil {
t.Fatalf("expected error, but got nil")
}
t.Run("the errors are templ errors", func(t *testing.T) {
var templateErr templ.Error
if !errors.As(err, &templateErr) {
t.Fatalf("expected error to be templ.Error, but got %T", err)
}
if templateErr.FileName != `generator/test-string-errors/template.templ` {
t.Errorf("expected error in `generator/test-string-errors/template.templ`, but got %v", templateErr.FileName)
}
if templateErr.Line != 18 {
t.Errorf("expected error on line 18, but got %v", templateErr.Line)
}
if templateErr.Col != 26 {
t.Errorf("expected error on column 26, but got %v", templateErr.Col)
}
})
t.Run("the underlying error can be unwrapped", func(t *testing.T) {
if !errors.Is(err, errSomethingBad) {
t.Errorf("expected error: %v, but got %v", errSomethingBad, err)
}
})
})
}

View File

@@ -0,0 +1,20 @@
package teststringerrs
func funcWithNoError() (s string) {
return "OK"
}
func funcWithError(in error) (s string, err error) {
if in != nil {
return "", in
}
return "OK2", nil
}
templ TestComponent(err error) {
<ul>
<li>{ "raw" }</li>
<li>{ funcWithNoError() }</li>
<li>{ funcWithError(err) }</li>
</ul>
}

View File

@@ -0,0 +1,90 @@
// Code generated by templ - DO NOT EDIT.
// templ: version: v0.3.833
package teststringerrs
//lint:file-ignore SA4006 This context is only used if a nested component is present.
import "github.com/a-h/templ"
import templruntime "github.com/a-h/templ/runtime"
func funcWithNoError() (s string) {
return "OK"
}
func funcWithError(in error) (s string, err error) {
if in != nil {
return "", in
}
return "OK2", nil
}
func TestComponent(err error) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer {
defer func() {
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
if templ_7745c5c3_Var1 == nil {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<ul><li>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var2 string
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs("raw")
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templ/generator/test-string-errors/template.templ`, Line: 16, Col: 13}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "</li><li>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(funcWithNoError())
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templ/generator/test-string-errors/template.templ`, Line: 17, Col: 25}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "</li><li>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(funcWithError(err))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templ/generator/test-string-errors/template.templ`, Line: 18, Col: 26}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "</li></ul>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
}
var _ = templruntime.GeneratedTemplate