1// +build go1.8,codegen
2
3package api
4
5import (
6	"testing"
7)
8
9func TestDocstring(t *testing.T) {
10	cases := map[string]struct {
11		In     string
12		Expect string
13	}{
14		"non HTML": {
15			In:     "Testing 1 2 3",
16			Expect: "// Testing 1 2 3",
17		},
18		"link": {
19			In:     `<a href="https://example.com">a link</a>`,
20			Expect: "// a link (https://example.com)",
21		},
22		"link with space": {
23			In:     `<a href=" https://example.com">a link</a>`,
24			Expect: "// a link (https://example.com)",
25		},
26		"list HTML 01": {
27			In:     "<ul><li>Testing 1 2 3</li> <li>FooBar</li></ul>",
28			Expect: "//    * Testing 1 2 3\n// \n//    * FooBar",
29		},
30		"list HTML 02": {
31			In:     "<ul> <li>Testing 1 2 3</li> <li>FooBar</li> </ul>",
32			Expect: "//    * Testing 1 2 3\n// \n//    * FooBar",
33		},
34		"list HTML leading spaces": {
35			In:     " <ul> <li>Testing 1 2 3</li> <li>FooBar</li> </ul>",
36			Expect: "//    * Testing 1 2 3\n// \n//    * FooBar",
37		},
38		"list HTML paragraph": {
39			In:     "<ul> <li> <p>Testing 1 2 3</p> </li><li> <p>FooBar</p></li></ul>",
40			Expect: "//    * Testing 1 2 3\n// \n//    * FooBar",
41		},
42		"inline code HTML": {
43			In:     "<ul> <li><code>Testing</code>: 1 2 3</li> <li>FooBar</li> </ul>",
44			Expect: "//    * Testing: 1 2 3\n// \n//    * FooBar",
45		},
46		"complex list paragraph": {
47			In:     "<ul> <li><p><code>FOO</code> Bar</p></li><li><p><code>Xyz</code> ABC</p></li></ul>",
48			Expect: "//    * FOO Bar\n// \n//    * Xyz ABC",
49		},
50		"inline code in paragraph": {
51			In:     "<p><code>Testing</code>: 1 2 3</p>",
52			Expect: "// Testing: 1 2 3",
53		},
54		"root pre": {
55			In:     "<pre><code>Testing</code></pre>",
56			Expect: "//    Testing",
57		},
58		"paragraph": {
59			In:     "<p>Testing 1 2 3</p>",
60			Expect: "// Testing 1 2 3",
61		},
62		"wrap lines": {
63			In:     "<span data-target-type=\"operation\" data-service=\"secretsmanager\" data-target=\"CreateSecret\">CreateSecret</span> <span data-target-type=\"structure\" data-service=\"secretsmanager\" data-target=\"SecretListEntry\">SecretListEntry</span> <span data-target-type=\"structure\" data-service=\"secretsmanager\" data-target=\"CreateSecret$SecretName\">SecretName</span> <span data-target-type=\"structure\" data-service=\"secretsmanager\" data-target=\"SecretListEntry$KmsKeyId\">KmsKeyId</span>",
64			Expect: "// CreateSecret SecretListEntry SecretName KmsKeyId",
65		},
66		"links with spaces": {
67			In:     "<p> Deletes the replication configuration from the bucket. For information about replication configuration, see <a href=\" https://docs.aws.amazon.com/AmazonS3/latest/dev/crr.html\">Cross-Region Replication (CRR)</a> in the <i>Amazon S3 Developer Guide</i>. </p>",
68			Expect: "// Deletes the replication configuration from the bucket. For information about\n// replication configuration, see Cross-Region Replication (CRR) (https://docs.aws.amazon.com/AmazonS3/latest/dev/crr.html)\n// in the Amazon S3 Developer Guide.",
69		},
70	}
71
72	for name, c := range cases {
73		t.Run(name, func(t *testing.T) {
74			t.Log("Input", c.In)
75			actual := docstring(c.In)
76			if e, a := c.Expect, actual; e != a {
77				t.Errorf("expect %q, got %q", e, a)
78			}
79		})
80	}
81}
82