Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

zz_zerowidth_test.gno

1.66 Kb · 54 lines
 1package polls
 2
 3import (
 4	"testing"
 5)
 6
 7// zwBlank holds one input per rune range chain/markdown.StripBidiAndZeroWidth
 8// removes (U+200B..U+200F, U+202A..U+202E, U+2066..U+2069, U+FEFF), plus a mix
 9// with real spaces. strings.TrimSpace keeps every one of them and the render
10// strips them all, so each must be refused.
11var zwBlank = []string{
12	"\u200b\u200b\u200b", // ZWSP
13	"\u200d",             // ZWJ
14	"\u200e",             // LRM
15	"\u202e",             // RLO
16	"\u2066\u2069",       // LRI PDI
17	"\ufeff",             // BOM
18	" \u200b \u200b ",    // mixed with real spaces
19}
20
21// zwOK must stay accepted: the stripper removes the marks and leaves text.
22var zwOK = []string{"a", "a\u200bb", "  padded  "}
23
24func TestZeroWidthQuestionIsRefused(cur realm, t *testing.T) {
25	resetState()
26	defer resetState()
27	testing.SetRealm(testing.NewUserRealm(alice))
28	for _, s := range zwBlank {
29		if revive(func() { CreatePoll(cross(cur), s, "x,y") }) == nil {
30			t.Errorf("CreatePoll accepted question %q, which the render strips to blank", s)
31		}
32	}
33	for _, s := range zwOK {
34		if r := revive(func() { CreatePoll(cross(cur), s, "x,y") }); r != nil {
35			t.Errorf("CreatePoll refused question %q: %v", s, r)
36		}
37	}
38	if PollCount() != len(zwOK) {
39		t.Errorf("PollCount = %d, want %d", PollCount(), len(zwOK))
40	}
41}
42
43func TestZeroWidthOptionIsDropped(t *testing.T) {
44	for _, s := range zwBlank {
45		if got := parseOptions("x," + s); len(got) != 1 {
46			t.Errorf("parseOptions kept option %q, which the render strips to blank: %q", s, got)
47		}
48	}
49	for _, s := range zwOK {
50		if got := parseOptions("x," + s); len(got) != 2 {
51			t.Errorf("parseOptions dropped option %q, which renders as text: %q", s, got)
52		}
53	}
54}