Skip to content

Commit

Permalink
Isolated the go doc examples into a separate file (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanb authored Jun 10, 2024
1 parent 593cc1e commit dc11be8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
34 changes: 34 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -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
}
28 changes: 0 additions & 28 deletions osmshortlink_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package osmshortlink

import (
"fmt"
"math"
"testing"
)
Expand Down Expand Up @@ -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
}

0 comments on commit dc11be8

Please sign in to comment.