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.60 Kb · 60 lines
 1package toposortdemo
 2
 3// ExampleRender pins the realm's root Render output as a testable example.
 4func ExampleRender() {
 5	print(Render(""))
 6	// Output:
 7	// # Topological Sort
 8	//
 9	// Ordering a dependency graph so nothing is built before what it needs, demoing the [`p/moul/x/daily/toposort`](/p/moul/x/daily/toposort/v0) library.
10	//
11	// ## The graph
12	//
13	// ```
14	// avl <- strings
15	// markdown <- strings
16	// realm <- storage, ui
17	// storage <- avl
18	// strings
19	// ui <- markdown
20	// ```
21	//
22	// ## Install order
23	//
24	// 1. `strings`
25	// 2. `avl`
26	// 3. `markdown`
27	// 4. `storage`
28	// 5. `ui`
29	// 6. `realm`
30	//
31	// Ties are broken lexicographically, so this ordering is the *only* one the library will ever produce for this graph.
32	//
33	// > See [`/cycle`](/r/moul/x/daily/toposortdemo/v0:cycle) for what happens when the graph is not a DAG.
34}
35
36// ExampleRender_cycle pins the failure mode: a cycle is reported with the nodes
37// still stuck, rather than silently dropping them.
38func ExampleRender_cycle() {
39	print(Render("/cycle"))
40	// Output:
41	// # Topological Sort
42	//
43	// Ordering a dependency graph so nothing is built before what it needs, demoing the [`p/moul/x/daily/toposort`](/p/moul/x/daily/toposort/v0) library.
44	//
45	// ## A graph with a cycle
46	//
47	// ```
48	// auth <- session
49	// server <- auth
50	// session <- auth
51	// ```
52	//
53	// `Sort` returns an error: **toposort: graph has a cycle**
54	//
55	// Ordered before giving up: _nothing_
56	//
57	// Stuck on the cycle: `auth`, `server`, `session`
58	//
59	// > The nodes still stuck are named rather than silently dropped, so a caller can report exactly which dependencies are tangled.
60}