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

zz_zerowidth_test.gno

1.29 Kb · 42 lines
 1package devtools
 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 TestZeroWidthNoteIsRefused(cur realm, t *testing.T) {
25	// Reset, not reset: the author board is what ExampleRender would see.
26	Reset(cross(cur))
27	for _, s := range zwBlank {
28		if revive(func() { Add(cross(cur), s) }) == nil {
29			t.Errorf("Add accepted note %q, which is stored escaped as blank", s)
30		}
31	}
32	for _, s := range zwOK {
33		if r := revive(func() { Add(cross(cur), s) }); r != nil {
34			t.Errorf("Add refused note %q: %v", s, r)
35		}
36	}
37	if notes.Size() != len(zwOK) {
38		t.Errorf("%d note(s), want %d", notes.Size(), len(zwOK))
39	}
40	// Not deferred: a crossing call cannot be.
41	Reset(cross(cur))
42}