Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pacedotdev/oto
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.10.4
Choose a base ref
...
head repository: pacedotdev/oto
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.10.5
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Sep 23, 2020

  1. don't escape comments - fixes #17

    matryer committed Sep 23, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    811c4bb View commit details
Showing with 38 additions and 3 deletions.
  1. +2 −2 render/render.go
  2. +36 −1 render/render_test.go
4 changes: 2 additions & 2 deletions render/render.go
Original file line number Diff line number Diff line change
@@ -40,10 +40,10 @@ func toJSONHelper(v interface{}) (template.HTML, error) {
return template.HTML(b), nil
}

func formatCommentText(s string) string {
func formatCommentText(s string) template.HTML {
var buf bytes.Buffer
doc.ToText(&buf, s, "// ", "", 80)
return buf.String()
return template.HTML(buf.String())
}

func formatCommentHTML(s string) template.HTML {
37 changes: 36 additions & 1 deletion render/render_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package render

import (
"log"
"strings"
"testing"

@@ -31,6 +32,36 @@ package <%= def.PackageName %>`
}
}

// TestRenderCommentsWithQuotes addresses https://github.com/pacedotdev/oto/issues/17.
func TestRenderCommentsWithQuotes(t *testing.T) {
is := is.New(t)
def := parser.Definition{
PackageName: "services",
Services: []parser.Service{
{
Comment: `This comment contains "quotes"`,
Name: "MyService",
},
},
}
template := `
<%= for (service) in def.Services { %>
<%= format_comment_text(service.Comment) %>type <%= service.Name %> struct
<% } %>
`
s, err := Render(template, def, nil)
is.NoErr(err)
log.Println(s)
for _, should := range []string{
`// This comment contains "quotes"`,
} {
if !strings.Contains(s, should) {
t.Errorf("missing: %s", should)
is.Fail()
}
}
}

func TestCamelizeDown(t *testing.T) {
for in, expected := range map[string]string{
"CamelsAreGreat": "camelsAreGreat",
@@ -71,6 +102,10 @@ func TestFormatTags(t *testing.T) {
func TestFormatCommentText(t *testing.T) {
is := is.New(t)

actual := strings.TrimSpace(formatCommentText("card's"))
actual := strings.TrimSpace(string(formatCommentText("card's")))
is.Equal(actual, "// card's")

actual = strings.TrimSpace(string(formatCommentText(`What happens if I use "quotes"?`)))
is.Equal(actual, `// What happens if I use "quotes"?`)

}