Skip to content

Commit

Permalink
docs: added some examples to godoc
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed May 21, 2024
1 parent af01cc5 commit 885e2e2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
19 changes: 19 additions & 0 deletions list/list_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package list_test

import (
"fmt"
"strings"
"testing"

Expand All @@ -10,6 +11,24 @@ import (
"github.com/charmbracelet/lipgloss/tree"
)

// XXX: can't write multi-line examples if the underlying string uses
// lipgloss.JoinVertical.

func ExampleNew() {
list := list.New().
Item("First")
fmt.Print(list)
// Output:• First
}

func ExampleNew_customEnumerator() {
list := list.New().
Enumerator(list.Arabic).
Item("First")
fmt.Print(list)
// Output:1. First
}

func TestList(t *testing.T) {
l := list.New().
Item("Foo").
Expand Down
23 changes: 23 additions & 0 deletions tree/tree_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tree_test

import (
"fmt"
"testing"

"github.com/charmbracelet/lipgloss"
Expand All @@ -10,6 +11,28 @@ import (
"github.com/charmbracelet/lipgloss/tree"
)

func ExampleNew() {
tree := tree.New().
Item("First")
fmt.Print(tree)
// Output: └── First
}

func ExampleNew_root() {
tree := tree.New().
Root("Root")
fmt.Print(tree)
// Output: Root
}

func ExampleNew_round() {
tree := tree.New().
Enumerator(tree.RoundedEnumerator).
Item("First")
fmt.Print(tree)
// Output: ╰── First
}

func TestTree(t *testing.T) {
tree := tree.New().
Items(
Expand Down

0 comments on commit 885e2e2

Please sign in to comment.