package web
import (
"os"
"path/filepath"
"regexp"
"testing"
)
// Datastar v1 names the element el, not $el; an expression that reads
// $el throws on click and does nothing (#388: the agent token's Copy).
func TestNoDollarElInDatastarExpressions(t *testing.T) {
files, _ := filepath.Glob("*.go")
re := regexp.MustCompile(`\$el\b`)
for _, f := range files {
if filepath.Ext(f) != ".go" || regexp.MustCompile(`_test\.go$`).MatchString(f) {
continue
}
b, err := os.ReadFile(f)
if err != nil {
t.Fatal(err)
}
if re.Match(b) {
t.Errorf("FAIL: %s reads $el in a Datastar expression; use el or evt.currentTarget", f)
}
}
t.Log("ok: no $el")
}