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

2.95 Kb · 92 lines
 1package ns
 2
 3import "gno.land/p/nt/avl/v0"
 4
 5// resetForExample rebuilds the whole realm state. Realm globals persist for
 6// the entire test binary and examples run after every Test, so without this an
 7// example would pin whatever the last test happened to leave behind.
 8func resetForExample() {
 9	services = avl.NewTree()
10	spaces = avl.NewTree()
11	seedDemo()
12}
13
14// ExampleRender pins the realm's front page.
15func ExampleRender() {
16	resetForExample()
17	print(Render(""))
18	// Output:
19	// # plan9: namespaces for gno
20	//
21	// A Plan 9 namespace server. Every account owns a private mount table over [9P-shaped](https://9p.io/sys/doc/9.html) file trees: realms post trees into `/srv`, you `bind` them where you want them, and a name means what *you* bound it to.
22	//
23	// ## /srv
24	//
25	// _No service is posted yet._
26	//
27	// ## The demo namespace
28	//
29	// ```
30	// mount #s /srv
31	// bind -ac /usr/glenda/bin /bin
32	// cd /usr/glenda
33	// ```
34	//
35	// `/bin` is a union: the system `/bin` first, then `/usr/glenda/bin`, with `-c` so new files land in the second. Listing it shows both members because a Plan 9 union is a concatenation, so shadowing stays visible.
36	//
37	// - [ns](:ns) · [ls /](:ls) · [ls /bin](:ls/bin) · [cat /tmp/greeting](:cat/tmp/greeting) · [walk /bin/rc](:walk/bin/rc)
38	// - any read-only command: [`rc?c=ls -l /srv`](:rc?c=ls%20-l%20/srv)
39	//
40	// ## Your own namespace
41	//
42	// ```
43	// gnokey maketx call -pkgpath gno.land/r/moul/x/plan9/ns/v0 \
44	//   -func Exec -args 'bind -ac /srv/dev /dev; echo hi > /tmp/f'
45	// ```
46	//
47	// Then browse it with `?u=<your address>`. `Reset` throws it away.
48	//
49	// ## Namespaces
50	//
51	// - [`demo`](:ns?u=demo)
52	//
53	// Design and analysis: [moul/gno-contracts#136](https://github.com/moul/gno-contracts/issues/136).
54	//
55	// _Not affiliated with Plan 9. Plan 9 from Bell Labs is the work of the Computing Science Research Center at Bell Labs; the name and the marks are theirs, and the copyright is held by the [Plan 9 Foundation](https://p9f.org). This realm borrows the vocabulary and none of the code: it is an homage, asking what that ecosystem's spirit looks like on a chain._
56}
57
58// ExampleRender_ls pins a union directory listing.
59func ExampleRender_ls() {
60	resetForExample()
61	print(Render("ls/bin"))
62	// Output:
63	// # ls /bin
64	//
65	// namespace: `demo`
66	//
67	// ```
68	// -rw-r--r-- demo         demo          10 ls
69	// -rw-r--r-- demo         demo          10 rc
70	// ```
71	//
72	// [namespace](:ns?u=demo) · [root](:ls?u=demo) · [home](:)
73}
74
75// ExampleRender_walk pins a resolution trace, which is where a bind becomes
76// visible: the union column widens exactly at the bound name.
77func ExampleRender_walk() {
78	resetForExample()
79	print(Render("walk/bin/rc"))
80	// Output:
81	// # walk /bin/rc
82	//
83	// namespace: `demo`
84	//
85	// ```
86	// /                        (1 5 d) drwxr-xr-x union=1
87	// /bin                     (a 1 d) drwxr-xr-x union=2
88	// /bin/rc                  (9 1 f) -rw-r--r-- union=1
89	// ```
90	//
91	// [namespace](:ns?u=demo) · [root](:ls?u=demo) · [home](:)
92}