(t *testing.T)
| 17 | ) |
| 18 | |
| 19 | func Test_ParseForms(t *testing.T) { |
| 20 | t.Parallel() |
| 21 | tests := []struct { |
| 22 | description string |
| 23 | html string |
| 24 | forms []*htmlForm |
| 25 | }{ |
| 26 | {"no forms", `<html></html>`, nil}, |
| 27 | {"empty form", `<html><form></form></html>`, []*htmlForm{{Values: url.Values{}}}}, |
| 28 | { |
| 29 | "single form with one value", |
| 30 | `<html><form action="a" method="m"><input name="n1" value="v1"></form></html>`, |
| 31 | []*htmlForm{{Action: "a", Method: "m", Values: url.Values{"n1": {"v1"}}}}, |
| 32 | }, |
| 33 | { |
| 34 | "two forms", |
| 35 | `<html> |
| 36 | <form action="a1" method="m1"><input name="n1" value="v1"></form> |
| 37 | <form action="a2" method="m2"><input name="n2" value="v2"></form> |
| 38 | </html>`, |
| 39 | []*htmlForm{ |
| 40 | {Action: "a1", Method: "m1", Values: url.Values{"n1": {"v1"}}}, |
| 41 | {Action: "a2", Method: "m2", Values: url.Values{"n2": {"v2"}}}, |
| 42 | }, |
| 43 | }, |
| 44 | { |
| 45 | "form with radio buttons (none checked)", |
| 46 | `<html><form> |
| 47 | <input type="radio" name="n1" value="v1"> |
| 48 | <input type="radio" name="n1" value="v2"> |
| 49 | <input type="radio" name="n1" value="v3"> |
| 50 | </form></html>`, |
| 51 | []*htmlForm{{Values: url.Values{}}}, |
| 52 | }, |
| 53 | { |
| 54 | "form with radio buttons", |
| 55 | `<html><form> |
| 56 | <input type="radio" name="n1" value="v1"> |
| 57 | <input type="radio" name="n1" value="v2"> |
| 58 | <input type="radio" name="n1" value="v3" checked> |
| 59 | </form></html>`, |
| 60 | []*htmlForm{{Values: url.Values{"n1": {"v3"}}}}, |
| 61 | }, |
| 62 | { |
| 63 | "form with checkboxes", |
| 64 | `<html><form> |
| 65 | <input type="checkbox" name="n1" value="v1" checked> |
| 66 | <input type="checkbox" name="n2" value="v2"> |
| 67 | <input type="checkbox" name="n3" value="v3" checked> |
| 68 | </form></html>`, |
| 69 | []*htmlForm{{Values: url.Values{"n1": {"v1"}, "n3": {"v3"}}}}, |
| 70 | }, |
| 71 | { |
| 72 | "single form with textarea", |
| 73 | `<html><form><textarea name="n1">v1</textarea></form></html>`, |
| 74 | []*htmlForm{{Values: url.Values{"n1": {"v1"}}}}, |
| 75 | }, |
| 76 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…