From dc11be84ee476765ffb15ef670ca1f2dea71dc8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0tefan=20Baebler?= Date: Mon, 10 Jun 2024 22:32:16 +0200 Subject: [PATCH] Isolated the go doc examples into a separate file (#25) Trying to get "Share", "Format" and "Run" buttons below examples on https://pkg.go.dev/github.com/stefanb/osmshortlink-go#pkg-functions as per * https://go.dev/blog/examples * https://pkg.go.dev/golang.org/x/example/hello/reverse#String * https://cs.opensource.google/go/x/example/+/master:hello/reverse/example_test.go --- example_test.go | 34 ++++++++++++++++++++++++++++++++++ osmshortlink_test.go | 28 ---------------------------- 2 files changed, 34 insertions(+), 28 deletions(-) create mode 100644 example_test.go diff --git a/example_test.go b/example_test.go new file mode 100644 index 0000000..6630e9e --- /dev/null +++ b/example_test.go @@ -0,0 +1,34 @@ +package osmshortlink_test + +import ( + "fmt" + + "github.com/stefanb/osmshortlink-go" +) + +func ExampleCreate() { + shortLink, err := osmshortlink.Create(46.05141, 14.50604, 17) + if err != nil { + panic(err) + } + fmt.Println(shortLink) + // Output: https://osm.org/go/0Ik3VNr_A-?m +} + +func ExampleEncode() { + shortLink, err := osmshortlink.Encode(46.05141, 14.50604, 17) + if err != nil { + panic(err) + } + fmt.Println(shortLink) + // Output: 0Ik3VNr_A- +} + +func ExampleDecode() { + latitude, longitude, zoom, err := osmshortlink.Decode("0Ik3VNr_A-") + if err != nil { + panic(err) + } + fmt.Println(latitude, longitude, zoom) + // Output: 46.05140447616577 14.506051540374756 17 +} diff --git a/osmshortlink_test.go b/osmshortlink_test.go index 5415be9..43221e5 100644 --- a/osmshortlink_test.go +++ b/osmshortlink_test.go @@ -1,7 +1,6 @@ package osmshortlink import ( - "fmt" "math" "testing" ) @@ -200,30 +199,3 @@ func TestDecodeShortLinkString(t *testing.T) { }) } } - -func ExampleCreate() { - shortLink, err := Create(46.05141, 14.50604, 17) - if err != nil { - panic(err) - } - fmt.Println(shortLink) - // Output: https://osm.org/go/0Ik3VNr_A-?m -} - -func ExampleEncode() { - shortLink, err := Encode(46.05141, 14.50604, 17) - if err != nil { - panic(err) - } - fmt.Println(shortLink) - // Output: 0Ik3VNr_A- -} - -func ExampleDecode() { - latitude, longitude, zoom, err := Decode("0Ik3VNr_A-") - if err != nil { - panic(err) - } - fmt.Println(latitude, longitude, zoom) - // Output: 46.05140447616577 14.506051540374756 17 -}