Files
via/signal_test.go
ryan cb13839157
All checks were successful
CI / Build and Test (push) Successful in 34s
fix: nil-close bug, stale docs, dead code, and tracked binaries (#7)
2026-02-20 20:00:44 +00:00

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())
})
}
}