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.37 Kb · 39 lines
 1package luhndemo
 2
 3// ExampleRender pins the realm's root Render output as a testable example.
 4func ExampleRender() {
 5	print(Render(""))
 6	// Output:
 7	// # Luhn Checksum
 8	//
 9	// The mod-10 check behind card numbers and IMEIs, demoing the [`p/moul/x/daily/luhn`](/p/moul/x/daily/luhn/v0) library.
10	//
11	// Append a number to the path to check it — spaces and hyphens are ignored.
12	//
13	// ## Samples
14	//
15	// | number | valid? | note |
16	// |---|---|---|
17	// | `79927398713` | ✅ valid | the textbook example |
18	// | `79927398710` | ❌ invalid | same number, wrong check digit |
19	// | `4539148803436467` | ✅ valid | a test card number |
20	// | `4539148803436647` | ❌ invalid | same card, two digits swapped |
21	//
22	// > Luhn is a **typo check, not a security check**: it catches every single-digit error and nearly every swap of adjacent digits, but anyone can compute a valid number. Never authorize anything with it.
23}
24
25// ExampleRender_invalid pins the repair path: a wrong check digit is reported
26// along with the digit it should have been.
27func ExampleRender_invalid() {
28	print(Render("/79927398710"))
29	// Output:
30	// # Luhn Checksum
31	//
32	// The mod-10 check behind card numbers and IMEIs, demoing the [`p/moul/x/daily/luhn`](/p/moul/x/daily/luhn/v0) library.
33	//
34	// ## `79927398710`
35	//
36	// **Not valid.**
37	//
38	// Keeping the leading digits, the check digit should be **3** — i.e. `79927398713`.
39}