zz_zerowidth_test.gno
1.30 Kb · 43 lines
1package timecapsule
2
3import (
4 "testing"
5
6 "gno.land/p/nt/testutils/v0"
7)
8
9// zwBlank holds one input per rune range chain/markdown.StripBidiAndZeroWidth
10// removes (U+200B..U+200F, U+202A..U+202E, U+2066..U+2069, U+FEFF), plus a mix
11// with real spaces. strings.TrimSpace keeps every one of them and the render
12// strips them all, so each must be refused.
13var zwBlank = []string{
14 "\u200b\u200b\u200b", // ZWSP
15 "\u200d", // ZWJ
16 "\u200e", // LRM
17 "\u202e", // RLO
18 "\u2066\u2069", // LRI PDI
19 "\ufeff", // BOM
20 " \u200b \u200b ", // mixed with real spaces
21}
22
23// zwOK must stay accepted: the stripper removes the marks and leaves text.
24var zwOK = []string{"a", "a\u200bb", " padded "}
25
26func TestZeroWidthMessageIsRefused(cur realm, t *testing.T) {
27 resetState()
28 defer resetState()
29 testing.SetRealm(testing.NewUserRealm(testutils.TestAddress("alice")))
30 for _, s := range zwBlank {
31 if revive(func() { Leave(cross(cur), s, 5) }) == nil {
32 t.Errorf("Leave accepted message %q, which the render strips to blank", s)
33 }
34 }
35 for _, s := range zwOK {
36 if r := revive(func() { Leave(cross(cur), s, 5) }); r != nil {
37 t.Errorf("Leave refused message %q: %v", s, r)
38 }
39 }
40 if capsules.Len() != len(zwOK) {
41 t.Errorf("%d capsule(s), want %d", capsules.Len(), len(zwOK))
42 }
43}