//go:build go1.8 && codegen // +build go1.8,codegen package api import ( "testing" ) func TestDocstring(t *testing.T) { cases := map[string]struct { In string Expect string }{ "non HTML": { In: "Testing 1 2 3", Expect: "// Testing 1 2 3", }, "link": { In: `a link`, Expect: "// a link (https://example.com)", }, "link with space": { In: `a link`, Expect: "// a link (https://example.com)", }, "list HTML 01": { In: "", Expect: "// * Testing 1 2 3\n// \n// * FooBar", }, "list HTML 02": { In: "", Expect: "// * Testing 1 2 3\n// \n// * FooBar", }, "list HTML leading spaces": { In: " ", Expect: "// * Testing 1 2 3\n// \n// * FooBar", }, "list HTML paragraph": { In: "", Expect: "// * Testing 1 2 3\n// \n// * FooBar", }, "inline code HTML": { In: "", Expect: "// * Testing: 1 2 3\n// \n// * FooBar", }, "complex list paragraph": { In: "", Expect: "// * FOO Bar\n// \n// * Xyz ABC", }, "inline code in paragraph": { In: "

Testing: 1 2 3

", Expect: "// Testing: 1 2 3", }, "root pre": { In: "
Testing
", Expect: "// Testing", }, "paragraph": { In: "

Testing 1 2 3

", Expect: "// Testing 1 2 3", }, "wrap lines": { In: "CreateSecret SecretListEntry SecretName KmsKeyId", Expect: "// CreateSecret SecretListEntry SecretName KmsKeyId", }, "links with spaces": { In: "

Deletes the replication configuration from the bucket. For information about replication configuration, see Cross-Region Replication (CRR) in the Amazon S3 Developer Guide.

", 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.", }, "unexpected closing tag": { In: "

Some cool text

", Expect: "// Some cool text", }, } for name, c := range cases { t.Run(name, func(t *testing.T) { actual := docstring(c.In) if e, a := c.Expect, actual; e != a { t.Errorf("expect %q, got %q", e, a) } }) } } func TestApiDocumentation_missingShapes(t *testing.T) { docs := apiDocumentation{ Service: "some service documentation", Operations: map[string]string{ "OperationOne": "some operation documentation", "OperationTwo": "some more operation documentation", }, Shapes: map[string]shapeDocumentation{ "ShapeOne": { Base: "some shape documentation", }, "ShapeTwo": { Base: "some more shape documentation", Refs: map[string]string{ "ShapeOne$shapeTwo": "shape ref document", }, }, }, } api := API{ Operations: map[string]*Operation{ "OperationOne": {}, }, Shapes: map[string]*Shape{ "ShapeOne": { Type: "structure", MemberRefs: map[string]*ShapeRef{}, }, }, } if err := docs.setup(&api); err != nil { t.Fatalf("expect no error, got %v", err) } if _, ok := api.Operations["OperationTwo"]; ok { t.Errorf("expect operation shape to not be added from document model") } if _, ok := api.Shapes["ShapeTwo"]; ok { t.Errorf("expect shape to not be added from document model") } if _, ok := api.Shapes["ShapeOne"].MemberRefs["shapeTwo"]; ok { t.Errorf("expect shape to not be added from document model") } }