diff --git a/src/net/url/example_test.go b/src/net/url/example_test.go index dfce2fc11c..87b6e74a85 100644 --- a/src/net/url/example_test.go +++ b/src/net/url/example_test.go @@ -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 {