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

render_example_test.gno

1.45 Kb · 40 lines
 1package idle
 2
 3import (
 4	"strings"
 5	"testing"
 6
 7	"gno.land/p/nt/testutils/v0"
 8	"gno.land/p/nt/uassert/v0"
 9)
10
11// TestRenderRoutes pins that Render dispatches on the path: empty is the
12// board, anything else is read as an address.
13func TestRenderRoutes(t *testing.T) {
14	reset()
15	alice := testutils.TestAddress("alice")
16	// Anchored at the block clock, not at t0: Render reads now().
17	start(alice, now())
18
19	uassert.True(t, strings.Contains(Render(""), "The Mine"), "empty path is the board")
20	uassert.True(t, strings.Contains(Render(alice.String()), "'s mine"), "an address is a card")
21	uassert.True(t, strings.Contains(Render("  "+alice.String()+"  "), "'s mine"),
22		"a padded address is still a card")
23	uassert.True(t, strings.Contains(Render("g1nobody"), "No mine at"), "a stranger is handled")
24}
25
26// ExampleRender pins the realm's empty board. It resets the tree first because
27// examples run after every Test in the package and would otherwise render
28// whatever they left behind.
29func ExampleRender() {
30	reset()
31	print(Render(""))
32	// Output:
33	// # The Mine
34	//
35	// Ore accrues while you are away. The mine holds 120 periods of production and then spills, so the only thing that costs you anything is not showing up.
36	//
37	// *Nobody is digging yet.*
38	//
39	// [Open a mine](/r/moul/x/games/idle/v0$help&func=Start) | [Claim](/r/moul/x/games/idle/v0$help&func=Claim) | [Upgrade](/r/moul/x/games/idle/v0$help&func=Upgrade) | [Prestige](/r/moul/x/games/idle/v0$help&func=Prestige)
40}