This repository has been archived by the owner on Dec 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples_test.go
67 lines (56 loc) · 2.24 KB
/
examples_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
package iri_test
import (
"fmt"
"github.com/contomap/iri"
)
func ExampleParse_https() {
value, _ := iri.Parse("https://[email protected]/µ/path?q=€#frag1")
fmt.Printf("%#v", value)
// Output: iri.IRI{Scheme:"https", ForceAuthority:false, Authority:"[email protected]", Path:"/µ/path", ForceQuery:false, Query:"q=€", ForceFragment:false, Fragment:"frag1"}
}
func ExampleParse_mailto() {
value, _ := iri.Parse("mailto:[email protected]")
fmt.Printf("%#v", value)
// Output: iri.IRI{Scheme:"mailto", ForceAuthority:false, Authority:"", Path:"[email protected]", ForceQuery:false, Query:"", ForceFragment:false, Fragment:""}
}
func ExampleParse_empty() {
value, _ := iri.Parse("")
fmt.Printf("%#v", value)
// Output: iri.IRI{Scheme:"", ForceAuthority:false, Authority:"", Path:"", ForceQuery:false, Query:"", ForceFragment:false, Fragment:""}
}
func ExampleParse_emptyComponents() {
value, _ := iri.Parse("//?#")
fmt.Printf("%#v", value)
// Output: iri.IRI{Scheme:"", ForceAuthority:true, Authority:"", Path:"", ForceQuery:true, Query:"", ForceFragment:true, Fragment:""}
}
func ExampleIRI_String_common() {
value := iri.IRI{Scheme: "https", ForceAuthority: false, Authority: "[email protected]", Path: "/sub/path", ForceQuery: false, Query: "q=1", ForceFragment: false, Fragment: "frag1"}
fmt.Printf("%s", value)
// Output: https://[email protected]/sub/path?q=1#frag1
}
func ExampleIRI_String_empty() {
var value iri.IRI
fmt.Printf("'%s'", value)
// Output: ''
}
func ExampleIRI_String_emptyComponents() {
value := iri.IRI{ForceAuthority: true, ForceQuery: true, ForceFragment: true}
fmt.Printf("%s", value)
// Output: //?#
}
func ExampleNormalizePercentEncoding() {
value, _ := iri.Parse("https://example.org/dog%20house/%c2%B5")
result, _ := iri.NormalizePercentEncoding(value)
fmt.Printf("%s", result.Path)
// Output: /dog%20house/µ
}
func ExampleIRI_ResolveReference() {
base, _ := iri.Parse("https://example.com/sub/path/µ?q=1#frag1")
fmt.Printf("%s\n", base.ResolveReference(iri.IRI{Fragment: "frag2"}))
fmt.Printf("%s\n", base.ResolveReference(iri.IRI{Path: ".."}))
fmt.Printf("%s\n", base.ResolveReference(iri.IRI{}))
// Output:
// https://example.com/sub/path/µ?q=1#frag2
// https://example.com/sub/
// https://example.com/sub/path/µ?q=1
}