From 392bb0677cfe6e6058d4f11953de80cdc20c52a8 Mon Sep 17 00:00:00 2001 From: Amelia Downs Date: Mon, 18 Oct 2021 12:36:07 -0400 Subject: [PATCH] net/url: add testable examples for Values funcs Change-Id: Id71f3d8d7c1ef7910d5d9497167dc677f2f0a2ef Reviewed-on: https://go-review.googlesource.com/c/go/+/356535 Trust: Damien Neil Trust: Cherry Mui Run-TryBot: Damien Neil TryBot-Result: Go Bot Reviewed-by: Damien Neil --- src/net/url/example_test.go | 78 +++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) 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 { -- 2.50.0