From c12ae447fced31c806ae788d7d53d6c24f5a05ff Mon Sep 17 00:00:00 2001 From: George Xie Date: Sun, 11 Dec 2022 02:16:37 +0800 Subject: [PATCH] doc: show ExampleB3 in readme (#9) --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 14098d2..9cf75a6 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,22 @@ Functions like `True(bool)` and friends. To assert a condition or panic. `B1`, `B2`... are generic assertions that pass their first inputs unmodified with compile time type info preserved. They return a function to specify what assertions are made on each field. +``` go +func ExampleB3() { + // lets say we have an io.RuneReader + readRune := func() (r rune, size int, err error) { + return 'a', 1, nil + } + + // that must return 1 byte runes and never err out + char, _, _ := must.B3(readRune())(must.Any, 1, nil) + fmt.Println(string(char)) + + // output: + // a +} +``` + Assertions have optional debug arguments, to provide additional information when violated. Usually, just pass in the line comment as string.