1
0
mirror of https://github.com/golang/go synced 2024-11-17 14:14:56 -07:00

net/url: add testable examples for Values funcs

Change-Id: Id71f3d8d7c1ef7910d5d9497167dc677f2f0a2ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/356535
Trust: Damien Neil <dneil@google.com>
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
Amelia Downs 2021-10-18 12:36:07 -04:00 committed by Damien Neil
parent 24999c3a8a
commit 392bb0677c

View File

@ -68,6 +68,84 @@ func ExampleValues() {
// [Jess Sarah Zoe]
}
func ExampleValues_Add() {
v := url.Values{}
v.Add("cat sounds", "meow")
v.Add("cat sounds", "mew")
v.Add("cat sounds", "mau")
fmt.Println(v["cat sounds"])
// Output:
// [meow mew mau]
}
func ExampleValues_Del() {
v := url.Values{}
v.Add("cat sounds", "meow")
v.Add("cat sounds", "mew")
v.Add("cat sounds", "mau")
fmt.Println(v["cat sounds"])
v.Del("cat sounds")
fmt.Println(v["cat sounds"])
// Output:
// [meow mew mau]
// []
}
func ExampleValues_Encode() {
v := url.Values{}
v.Add("cat sounds", "meow")
v.Add("cat sounds", "mew/")
v.Add("cat sounds", "mau$")
fmt.Println(v.Encode())
// Output:
// cat+sounds=meow&cat+sounds=mew%2F&cat+sounds=mau%24
}
func ExampleValues_Get() {
v := url.Values{}
v.Add("cat sounds", "meow")
v.Add("cat sounds", "mew")
v.Add("cat sounds", "mau")
fmt.Printf("%q\n", v.Get("cat sounds"))
fmt.Printf("%q\n", v.Get("dog sounds"))
// Output:
// "meow"
// ""
}
func ExampleValues_Has() {
v := url.Values{}
v.Add("cat sounds", "meow")
v.Add("cat sounds", "mew")
v.Add("cat sounds", "mau")
fmt.Println(v.Has("cat sounds"))
fmt.Println(v.Has("dog sounds"))
// Output:
// true
// false
}
func ExampleValues_Set() {
v := url.Values{}
v.Add("cat sounds", "meow")
v.Add("cat sounds", "mew")
v.Add("cat sounds", "mau")
fmt.Println(v["cat sounds"])
v.Set("cat sounds", "meow")
fmt.Println(v["cat sounds"])
// Output:
// [meow mew mau]
// [meow]
}
func ExampleURL() {
u, err := url.Parse("http://bing.com/search?q=dotnet")
if err != nil {