|
1 | 1 | package render
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "log" |
4 | 5 | "strings"
|
5 | 6 | "testing"
|
6 | 7 |
|
@@ -31,6 +32,36 @@ package <%= def.PackageName %>`
|
31 | 32 | }
|
32 | 33 | }
|
33 | 34 |
|
| 35 | +// TestRenderCommentsWithQuotes addresses https://github.com/pacedotdev/oto/issues/17. |
| 36 | +func TestRenderCommentsWithQuotes(t *testing.T) { |
| 37 | + is := is.New(t) |
| 38 | + def := parser.Definition{ |
| 39 | + PackageName: "services", |
| 40 | + Services: []parser.Service{ |
| 41 | + { |
| 42 | + Comment: `This comment contains "quotes"`, |
| 43 | + Name: "MyService", |
| 44 | + }, |
| 45 | + }, |
| 46 | + } |
| 47 | + template := ` |
| 48 | + <%= for (service) in def.Services { %> |
| 49 | + <%= format_comment_text(service.Comment) %>type <%= service.Name %> struct |
| 50 | + <% } %> |
| 51 | + ` |
| 52 | + s, err := Render(template, def, nil) |
| 53 | + is.NoErr(err) |
| 54 | + log.Println(s) |
| 55 | + for _, should := range []string{ |
| 56 | + `// This comment contains "quotes"`, |
| 57 | + } { |
| 58 | + if !strings.Contains(s, should) { |
| 59 | + t.Errorf("missing: %s", should) |
| 60 | + is.Fail() |
| 61 | + } |
| 62 | + } |
| 63 | +} |
| 64 | + |
34 | 65 | func TestCamelizeDown(t *testing.T) {
|
35 | 66 | for in, expected := range map[string]string{
|
36 | 67 | "CamelsAreGreat": "camelsAreGreat",
|
@@ -71,6 +102,10 @@ func TestFormatTags(t *testing.T) {
|
71 | 102 | func TestFormatCommentText(t *testing.T) {
|
72 | 103 | is := is.New(t)
|
73 | 104 |
|
74 |
| - actual := strings.TrimSpace(formatCommentText("card's")) |
| 105 | + actual := strings.TrimSpace(string(formatCommentText("card's"))) |
75 | 106 | is.Equal(actual, "// card's")
|
| 107 | + |
| 108 | + actual = strings.TrimSpace(string(formatCommentText(`What happens if I use "quotes"?`))) |
| 109 | + is.Equal(actual, `// What happens if I use "quotes"?`) |
| 110 | + |
76 | 111 | }
|
0 commit comments