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 -}