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>
diff --git a/src/net/url/example_test.go b/src/net/url/example_test.go
index dfce2fc..87b6e74 100644
--- a/src/net/url/example_test.go
+++ b/src/net/url/example_test.go
@@ -68,6 +68,84 @@
// [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 {