Initial commit of Descrybe v2 without local scratch artifacts.
Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package email
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestConfirmUnderstoodPhrase(t *testing.T) {
|
||||
if ConfirmUnderstoodPhrase != "I understand" {
|
||||
t.Fatalf("unexpected phrase %q", ConfirmUnderstoodPhrase)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDomainOfEmail(t *testing.T) {
|
||||
if got := domainOfEmail("Alice@Example.COM"); got != "example.com" {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInjectUnsubscribeFooter(t *testing.T) {
|
||||
html, text := injectUnsubscribeFooter("<p>Hi</p>", "Hi", "https://app/unsubscribe?token=x")
|
||||
if !containsFold(html, "unsubscribe") || !containsFold(text, "unsubscribe") {
|
||||
t.Fatalf("expected unsubscribe footer")
|
||||
}
|
||||
}
|
||||
|
||||
func containsFold(s, sub string) bool {
|
||||
return len(s) >= len(sub) && (s == sub || len(sub) == 0 ||
|
||||
(len(s) > 0 && (stringIndexFold(s, sub) >= 0)))
|
||||
}
|
||||
|
||||
func stringIndexFold(s, sub string) int {
|
||||
ls, lsub := len(s), len(sub)
|
||||
for i := 0; i+lsub <= ls; i++ {
|
||||
ok := true
|
||||
for j := 0; j < lsub; j++ {
|
||||
a, b := s[i+j], sub[j]
|
||||
if a >= 'A' && a <= 'Z' {
|
||||
a += 'a' - 'A'
|
||||
}
|
||||
if b >= 'A' && b <= 'Z' {
|
||||
b += 'a' - 'A'
|
||||
}
|
||||
if a != b {
|
||||
ok = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if ok {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func TestListUnsubscribeHeaders(t *testing.T) {
|
||||
h := listUnsubscribeHeaders("https://api/u?t=1", "")
|
||||
if h["List-Unsubscribe"] == "" || h["List-Unsubscribe-Post"] == "" {
|
||||
t.Fatal("missing headers")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user