Skip to content
quarry Artifact [749a5241fc]
Login

Artifact [749a5241fc]

Artifact 749a5241fc7a299c2aa25dd232af2b4ff9a26360bcfe82ced4bd69f0bd7e3063:


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