summaryrefslogtreecommitdiff
path: root/optional/example_template_test.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-12-01 20:26:12 +0100
committerxengineering <me@xengineering.eu>2024-12-01 20:26:12 +0100
commit4c500acc06bd01b52ceacd3dc458f4eb7070e381 (patch)
tree54f7a6eeb6f3053f6341c3b9c21899739558e113 /optional/example_template_test.go
parent9ccb926124e84f46453b863f9cf3b1bdd93836ac (diff)
downloadoptional-go-4c500acc06bd01b52ceacd3dc458f4eb7070e381.tar
optional-go-4c500acc06bd01b52ceacd3dc458f4eb7070e381.tar.zst
optional-go-4c500acc06bd01b52ceacd3dc458f4eb7070e381.zip
Introduce example_ prefix convention
This allows to distinguish unit test files of the format `<name>_test.go` from full file examples like `example_<name>_test.go`.
Diffstat (limited to 'optional/example_template_test.go')
-rw-r--r--optional/example_template_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/optional/example_template_test.go b/optional/example_template_test.go
new file mode 100644
index 0000000..83b5821
--- /dev/null
+++ b/optional/example_template_test.go
@@ -0,0 +1,34 @@
+package optional_test
+
+import (
+ "html/template"
+ "log"
+ "os"
+
+ "xengineering.eu/optional-go/optional"
+)
+
+func Example_template() {
+ data := struct {
+ Flag optional.Optional[bool]
+ }{
+ Flag: optional.Optional[bool]{
+ Value: false,
+ Exists: false,
+ },
+ }
+
+ tmpl := `Flag is: {{if .Flag.Exists}}{{.Flag.Value}}{{else}}[none]{{end}}`
+
+ t, err := template.New("optional").Parse(tmpl)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ err = t.Execute(os.Stdout, data)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ // Output: Flag is: [none]
+}