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.13 Kb · 34 lines
 1package rledemo
 2
 3// ExampleRender pins the realm's root Render output as a testable example.
 4func ExampleRender() {
 5	print(Render(""))
 6	// Output:
 7	// # Run-Length Encoding
 8	//
 9	// `<count><char>` pairs, demoing the [`p/moul/x/daily/rle`](/p/moul/x/daily/rle/v0) library.
10	//
11	// | input | encoded | size | round-trips |
12	// |---|---|---|---|
13	// | `aaaaaaaaaabbbbbbbbbb` | `10a10b` | 30% | ✅ |
14	// | `aaabbc` | `3a2b1c` | 100% | ✅ |
15	// | `abcdef` | `1a1b1c1d1e1f` | 200% | ✅ |
16	//
17	// > Over 100% means the encoding made the data **bigger**. RLE only wins on runny input, and `abcdef` is the honest counter-example.
18	//
19	// > Append text to the path to encode it — digits are rejected, since they would be ambiguous with a run count.
20}
21
22// ExampleRender_rejectsDigits pins the refusal path: digits cannot be encoded
23// because they are indistinguishable from a run count on the way back.
24func ExampleRender_rejectsDigits() {
25	print(Render("/ab3c"))
26	// Output:
27	// # Run-Length Encoding
28	//
29	// `<count><char>` pairs, demoing the [`p/moul/x/daily/rle`](/p/moul/x/daily/rle/v0) library.
30	//
31	// ## `ab3c`
32	//
33	// _rle: input must not contain digits_
34}