]> Cypherpunks repositories - gostls13.git/commitdiff
net/url: add testable examples for Values funcs
authorAmelia Downs <adowns@vmware.com>
Mon, 18 Oct 2021 16:36:07 +0000 (12:36 -0400)
committerDamien Neil <dneil@google.com>
Thu, 21 Oct 2021 17:31:42 +0000 (17:31 +0000)
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>
src/net/url/example_test.go

index dfce2fc11c80d1108b75658475a1e1d23374aefd..87b6e74a856449327022571b4dbf9901a7046238 100644 (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 {