Skip to content

Commit

Permalink
docs: improve examples
Browse files Browse the repository at this point in the history
1. make calls to String() explicit
2. move the examples to the did package to address this bug
in gometalinter gojp/goreportcard#113
  • Loading branch information
mrinalwadhwa committed Nov 10, 2018
1 parent 3f44e3f commit cf45e46
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package did_test
package did

import (
"fmt"
"log"

"github.com/ockam-network/did"
)

func ExampleParse() {
d, err := did.Parse("did:example:q7ckgxeq1lxmra0r")
d, err := Parse("did:example:q7ckgxeq1lxmra0r")
if err != nil {
log.Fatal(err)
}
Expand All @@ -17,7 +15,7 @@ func ExampleParse() {
}

func ExampleParse_withPath() {
d, err := did.Parse("did:example:q7ckgxeq1lxmra0r/a/b")
d, err := Parse("did:example:q7ckgxeq1lxmra0r/a/b")
if err != nil {
log.Fatal(err)
}
Expand All @@ -26,7 +24,7 @@ func ExampleParse_withPath() {
}

func ExampleParse_withFragment() {
d, err := did.Parse("did:example:q7ckgxeq1lxmra0r#keys-1")
d, err := Parse("did:example:q7ckgxeq1lxmra0r#keys-1")
if err != nil {
log.Fatal(err)
}
Expand All @@ -35,43 +33,43 @@ func ExampleParse_withFragment() {
}

func ExampleDID_String() {
d := &did.DID{Method: "example", ID: "q7ckgxeq1lxmra0r"}
fmt.Println(d)
d := &DID{Method: "example", ID: "q7ckgxeq1lxmra0r"}
fmt.Println(d.String())
// Output: did:example:q7ckgxeq1lxmra0r
}

func ExampleDID_String_withPath() {
d := &did.DID{Method: "example", ID: "q7ckgxeq1lxmra0r", Path: "a/b"}
d := &DID{Method: "example", ID: "q7ckgxeq1lxmra0r", Path: "a/b"}
fmt.Println(d.String())
// Output: did:example:q7ckgxeq1lxmra0r/a/b
}

func ExampleDID_String_withPathSegments() {
d := &did.DID{Method: "example", ID: "q7ckgxeq1lxmra0r", PathSegments: []string{"a", "b"}}
d := &DID{Method: "example", ID: "q7ckgxeq1lxmra0r", PathSegments: []string{"a", "b"}}
fmt.Println(d.String())
// Output: did:example:q7ckgxeq1lxmra0r/a/b
}

func ExampleDID_String_withFragment() {
d := &did.DID{Method: "example", ID: "q7ckgxeq1lxmra0r", Fragment: "keys-1"}
fmt.Println(d)
d := &DID{Method: "example", ID: "q7ckgxeq1lxmra0r", Fragment: "keys-1"}
fmt.Println(d.String())
// Output: did:example:q7ckgxeq1lxmra0r#keys-1
}

func ExampleDID_IsReference_withPath() {
d := &did.DID{Method: "example", ID: "q7ckgxeq1lxmra0r", Path: "a/b"}
d := &DID{Method: "example", ID: "q7ckgxeq1lxmra0r", Path: "a/b"}
fmt.Println(d.IsReference())
// Output: true
}

func ExampleDID_IsReference_withFragment() {
d := &did.DID{Method: "example", ID: "q7ckgxeq1lxmra0r", Fragment: "keys-1"}
d := &DID{Method: "example", ID: "q7ckgxeq1lxmra0r", Fragment: "keys-1"}
fmt.Println(d.IsReference())
// Output: true
}

func ExampleDID_IsReference_noPathOrFragment() {
d := &did.DID{Method: "example", ID: "q7ckgxeq1lxmra0r"}
d := &DID{Method: "example", ID: "q7ckgxeq1lxmra0r"}
fmt.Println(d.IsReference())
// Output: false
}

0 comments on commit cf45e46

Please sign in to comment.