Skip to content

Commit

Permalink
docs: move examples to did_test package
Browse files Browse the repository at this point in the history
  • Loading branch information
mrinalwadhwa committed Nov 10, 2018
1 parent cf45e46 commit 9cf6ecc
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package did
package did_test

import (
"fmt"
"log"

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

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

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

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

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

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

func ExampleDID_String_withPathSegments() {
d := &DID{Method: "example", ID: "q7ckgxeq1lxmra0r", PathSegments: []string{"a", "b"}}
d := &did.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{Method: "example", ID: "q7ckgxeq1lxmra0r", Fragment: "keys-1"}
d := &did.DID{Method: "example", ID: "q7ckgxeq1lxmra0r", Fragment: "keys-1"}
fmt.Println(d.String())
// Output: did:example:q7ckgxeq1lxmra0r#keys-1
}

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

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

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

0 comments on commit 9cf6ecc

Please sign in to comment.