Skip to content

Commit fbba72b

Browse files
committed
[FEAT] Added in-code examples for document API
Public API can be documented with an external set of test-like functions that show a a given public package API function can be used.
1 parent b797018 commit fbba72b

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

example_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package xdg_test
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/mdm-code/xdg"
7+
)
8+
9+
func ExampleDataHomeDir() {
10+
dir := xdg.DataHomeDir()
11+
fmt.Println("Home data directory: ", dir)
12+
}
13+
14+
func ExampleConfigHomeDir() {
15+
dir := xdg.ConfigHomeDir()
16+
fmt.Println("Config home directory: ", dir)
17+
}
18+
19+
func ExampleStateHomeDir() {
20+
dir := xdg.StateHomeDir()
21+
fmt.Println("State home directory: ", dir)
22+
}
23+
24+
func ExampleDataDirs() {
25+
dir := xdg.DataDirs()
26+
fmt.Println("Data directories: ", dir)
27+
}
28+
29+
func ExampleConfigDirs() {
30+
dir := xdg.ConfigDirs()
31+
fmt.Println("Config directories: ", dir)
32+
}
33+
34+
func ExampleCacheHomeDir() {
35+
dir := xdg.CacheHomeDir()
36+
fmt.Println("Cache home directory: ", dir)
37+
}
38+
39+
func ExampleRuntimeDir() {
40+
dir := xdg.RuntimeDir()
41+
fmt.Println("Runtime home directory: ", dir)
42+
}
43+
44+
func ExampleFind() {
45+
fpath := "program/file.data"
46+
if f, ok := xdg.Find(xdg.Data, fpath); ok {
47+
fmt.Printf("Data file for %s was found at %s\n", fpath, f)
48+
} else {
49+
fmt.Printf("ERROR: couldn't find %s\n", fpath)
50+
}
51+
}

0 commit comments

Comments
 (0)