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

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

2.21 Kb · 68 lines
 1package faucet
 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 TestZeroWidthReasonIsRefused(cur realm, t *testing.T) {
25	reset()
26	defer reset()
27	testing.SetRealm(testing.NewUserRealm(carl))
28	for _, s := range zwBlank {
29		if revive(func() { Request(cross(cur), zoe.String(), 1_000_000, s) }) == nil {
30			t.Errorf("Request accepted reason %q, which the render strips to blank", s)
31		}
32	}
33	for _, s := range zwOK {
34		if r := revive(func() { Request(cross(cur), zoe.String(), 1_000_000, s) }); r != nil {
35			t.Errorf("Request refused reason %q: %v", s, r)
36		}
37	}
38	if Requests() != len(zwOK) {
39		t.Errorf("Requests = %d, want %d", Requests(), len(zwOK))
40	}
41}
42
43func TestZeroWidthDenyReasonIsRefused(cur realm, t *testing.T) {
44	reset()
45	defer reset()
46	testing.SetRealm(testing.NewUserRealm(carl))
47	id := Request(cross(cur), zoe.String(), 1_000_000, "to try the chain")
48	testing.SetRealm(testing.NewUserRealm(Owner))
49	for _, s := range zwBlank {
50		if revive(func() { Deny(cross(cur), id, s) }) == nil {
51			t.Errorf("Deny accepted reason %q, which the render strips to blank", s)
52		}
53	}
54	if Status(id) != StatusPending {
55		t.Fatalf("Status = %q after blank denials, want %q", Status(id), StatusPending)
56	}
57	for _, s := range zwOK {
58		testing.SetRealm(testing.NewUserRealm(carl))
59		id := Request(cross(cur), zoe.String(), 1_000_000, "to try the chain")
60		testing.SetRealm(testing.NewUserRealm(Owner))
61		if r := revive(func() { Deny(cross(cur), id, s) }); r != nil {
62			t.Errorf("Deny refused reason %q: %v", s, r)
63		}
64		if Status(id) != StatusDenied {
65			t.Errorf("Status = %q, want %q", Status(id), StatusDenied)
66		}
67	}
68}