-
Notifications
You must be signed in to change notification settings - Fork 21
/
example_test.go
92 lines (78 loc) · 2.44 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package did_test
import (
"fmt"
"log"
"github.com/ockam-network/did"
)
func ExampleParse() {
d, err := did.Parse("did:example:q7ckgxeq1lxmra0r")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Method - %s, ID - %s", d.Method, d.ID)
// Output: Method - example, ID - q7ckgxeq1lxmra0r
}
func ExampleParse_withPath() {
d, err := did.Parse("did:example:q7ckgxeq1lxmra0r/a/b")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Method - %s, ID - %s, Path - %s", d.Method, d.ID, d.Path)
// Output: Method - example, ID - q7ckgxeq1lxmra0r, Path - a/b
}
func ExampleParse_withQuery() {
d, err := did.Parse("did:example:q7ckgxeq1lxmra0r?dskjsdjj")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Method - %s, ID - %s, Query - %s", d.Method, d.ID, d.Query)
// Output: Method - example, ID - q7ckgxeq1lxmra0r, Query - dskjsdjj
}
func ExampleParse_withFragment() {
d, err := did.Parse("did:example:q7ckgxeq1lxmra0r#keys-1")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Method - %s, ID - %s, Fragment - %s", d.Method, d.ID, d.Fragment)
// Output: Method - example, ID - q7ckgxeq1lxmra0r, Fragment - keys-1
}
func ExampleDID_String() {
d := &did.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"}
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"}}
fmt.Println(d.String())
// Output: did:example:q7ckgxeq1lxmra0r/a/b
}
func ExampleDID_String_withQuery() {
d := &did.DID{Method: "example", ID: "q7ckgxeq1lxmra0r", Query: "abc"}
fmt.Println(d.String())
// Output: did:example:q7ckgxeq1lxmra0r?abc
}
func ExampleDID_String_withFragment() {
d := &did.DID{Method: "example", ID: "q7ckgxeq1lxmra0r", Fragment: "keys-1"}
fmt.Println(d.String())
// Output: did:example:q7ckgxeq1lxmra0r#keys-1
}
func ExampleDID_IsURL_withPath() {
d := &did.DID{Method: "example", ID: "q7ckgxeq1lxmra0r", Path: "a/b"}
fmt.Println(d.IsURL())
// Output: true
}
func ExampleDID_IsURL_withFragment() {
d := &did.DID{Method: "example", ID: "q7ckgxeq1lxmra0r", Fragment: "keys-1"}
fmt.Println(d.IsURL())
// Output: true
}
func ExampleDID_IsURL_noPathOrFragment() {
d := &did.DID{Method: "example", ID: "q7ckgxeq1lxmra0r"}
fmt.Println(d.IsURL())
// Output: false
}