From 4c500acc06bd01b52ceacd3dc458f4eb7070e381 Mon Sep 17 00:00:00 2001 From: xengineering Date: Sun, 1 Dec 2024 20:26:12 +0100 Subject: Introduce example_ prefix convention This allows to distinguish unit test files of the format `_test.go` from full file examples like `example__test.go`. --- optional/example_template_test.go | 34 ++++++++++++++++++++++++++++++++++ optional/template_test.go | 34 ---------------------------------- 2 files changed, 34 insertions(+), 34 deletions(-) create mode 100644 optional/example_template_test.go delete mode 100644 optional/template_test.go 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] +} diff --git a/optional/template_test.go b/optional/template_test.go deleted file mode 100644 index 83b5821..0000000 --- a/optional/template_test.go +++ /dev/null @@ -1,34 +0,0 @@ -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] -} -- cgit v1.2.3-70-g09d2