- Fix potential nil file.Close() panic in devModePersist/devModeRemovePersisted
by extracting loadDevModeMap/saveDevModeMap helpers with proper defer
- Remove tracked binaries (pathparams 10.8 MB, shake.db 22 MB) and consolidate
.gitignore with a wildcard pattern covering all 19 examples
- Remove stale reaper reference in README (removed in dc56261), update example
count from 14 to 19, fix OnChange debounce claim in docs
- Fix typos: "percist"→"persist", "percisted"→"persisted", "tmplates"→"templates"
- Remove dead code: commented import in signal_test.go, unnecessary fmt.Sprintf
in computed.go, commented picocss imports and no-op Config calls in examples
- Replace go fmt with gofmt -l check in ci-check.sh to fail on unformatted code
instead of silently reformatting
69 lines
1.5 KiB
Go
69 lines
1.5 KiB
Go
package via
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/ryanhamamura/via/h"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestSignalReturnAsString(t *testing.T) {
|
|
testcases := []struct {
|
|
desc string
|
|
given any
|
|
expected string
|
|
}{
|
|
{"string", "test", "test"},
|
|
{"other string", "another", "another"},
|
|
{"int", 1, "1"},
|
|
{"negative int", -99, "-99"},
|
|
{"float", 1.1, "1.1"},
|
|
{"negative float", -34.345, "-34.345"},
|
|
{"positive bool", true, "true"},
|
|
{"negative bool", false, "false"},
|
|
}
|
|
|
|
for _, testcase := range testcases {
|
|
t.Run(testcase.desc, func(t *testing.T) {
|
|
t.Parallel()
|
|
var sig *Signal
|
|
v := New()
|
|
v.Page("/", func(c *Context) {
|
|
sig = c.Signal(testcase.given)
|
|
c.View(func() h.H { return h.Div() })
|
|
})
|
|
assert.Equal(t, testcase.expected, sig.String())
|
|
})
|
|
|
|
}
|
|
}
|
|
|
|
func TestSignalReturnAsStringComplexTypes(t *testing.T) {
|
|
testcases := []struct {
|
|
desc string
|
|
given any
|
|
expected string
|
|
}{
|
|
{"string slice", []string{"test"}, `["test"]`},
|
|
{"int slice", []int{1, 2}, "[1, 2]"},
|
|
{"struct1", struct{ Val string }{"test"}, `{"Val": "test"}`},
|
|
{"struct2", struct {
|
|
Num int
|
|
IsPositive bool
|
|
}{1, true}, `{"Num": 1, "IsPositive": true}`},
|
|
}
|
|
|
|
for _, testcase := range testcases {
|
|
t.Run(testcase.desc, func(t *testing.T) {
|
|
t.Parallel()
|
|
var sig *Signal
|
|
v := New()
|
|
v.Page("/", func(c *Context) {
|
|
c.View(func() h.H { return nil })
|
|
sig = c.Signal(testcase.given)
|
|
})
|
|
assert.JSONEq(t, testcase.expected, sig.String())
|
|
})
|
|
}
|
|
}
|