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.

example_test.gno

2.10 Kb · 66 lines
 1package kitindexdemo
 2
 3import (
 4	"testing"
 5
 6	"gno.land/p/nt/uassert/v0"
 7)
 8
 9// seed builds a fixed board without crossing anything, so an example can set up
10// its own state.
11//
12// An Example has no realm token, so it cannot call Post, and the state the
13// tests happen to leave is not a contract. Writing the globals directly is the
14// escape hatch AGENTS.md names: same package, no crossing, fully deterministic.
15func seed() {
16	reset()
17	add := func(who address, tag, body string, height int64) {
18		id := notes.Add(&note{Author: who, Tag: tag, Body: body, Height: height})
19		if err := byTag.Add(tag, id); err != nil {
20			panic(err)
21		}
22		if err := byAuthor.Add(who.String(), id); err != nil {
23			panic(err)
24		}
25	}
26	add(alice, "gno", "the index is two containers and one function", 123)
27	add(bob, "gno", "and the function is where the correctness is", 124)
28	add(alice, "storage", "you are charged for objects, not for data", 125)
29}
30
31// The root page carries TWO consecutive blank lines, which an // Output: block
32// can never pin: gno collapses them, exactly as Go does. So the root is
33// asserted with uassert.Equal and a backtick literal, which preserves them,
34// and only the pages without that shape get an Example.
35//
36// This is the order of preference AGENTS.md names, and the root page is the
37// case that forces the second rung.
38func TestRenderRoot(t *testing.T) {
39	seed()
40	want := `# Notes by tag
41
423 note(s) under 2 tag(s), by 2 author(s).
43
44
45| tag | notes |
46| --- | --- |
47| [gno](/r/nym-moultest123/x/kitindexdemo/v0:tag/gno) | 2 |
48| [storage](/r/nym-moultest123/x/kitindexdemo/v0:tag/storage) | 1 |
49
50[Post a note](/r/nym-moultest123/x/kitindexdemo/v0$help&func=Post&body=&tag=)
51
52`
53	uassert.Equal(t, want, Render(""))
54}
55
56// ExampleRender_tag pins one tag's page, which is the lookup the library is for.
57func ExampleRender_tag() {
58	seed()
59	print(Render("tag/gno"))
60	// Output:
61	// # #gno
62	// | # | author | tag | note | height |
63	// | --- | --- | --- | --- | --- |
64	// | 1 | `g1v9kxjc…40gh` | `gno` | the index is two containers and one function | 123 |
65	// | 2 | `g1vfhkyh…vdhu` | `gno` | and the function is where the correctness is | 124 |
66}