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.57 Kb · 47 lines
 1package qvote
 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 TestZeroWidthQuestionAndOptionAreRefused(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() { CreatePoll(cross(cur), s, "x,y") }) == nil {
32			t.Errorf("CreatePoll accepted question %q, which the render strips to blank", s)
33		}
34		// With the blank option dropped, one option is left and the poll is refused.
35		if revive(func() { CreatePoll(cross(cur), "q", "x,"+s) }) == nil {
36			t.Errorf("CreatePoll kept option %q, which the render strips to blank", s)
37		}
38	}
39	for _, s := range zwOK {
40		if r := revive(func() { CreatePoll(cross(cur), s, "x,"+s) }); r != nil {
41			t.Errorf("CreatePoll refused question and option %q: %v", s, r)
42		}
43	}
44	if nextID != len(zwOK) {
45		t.Errorf("%d poll(s) created, want %d", nextID, len(zwOK))
46	}
47}