diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 7350634..3713879 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - go: ['1.23', '1.22'] + go: ['1.25', '1.24'] steps: - uses: actions/checkout@v4 diff --git a/README.md b/README.md index 92788ca..dcf1639 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,7 @@ func staticTest(_w io.Writer) { } -func translateTest(t Translater, buf *bytes.Buffer) { +func translateTest(t Translater, _w io.Writer) { {{t Translate me to some language }} @@ -562,7 +562,7 @@ import { } -func writeTemplate(ctx context.Context, buf *bytes.Buffer) { +func writeTemplate(ctx context.Context, _w io.Writer) { {{# Define the body that will be inserted into the template }} {{< body }} diff --git a/go.mod b/go.mod index 49347cd..8358cf5 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,8 @@ module github.com/goradd/got require ( - github.com/goradd/gofile v1.2.0 - github.com/stretchr/testify v1.8.4 + github.com/goradd/gofile v1.2.1 + github.com/stretchr/testify v1.11.1 ) require ( diff --git a/go.sum b/go.sum index d93f8af..7455421 100644 --- a/go.sum +++ b/go.sum @@ -2,10 +2,14 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/goradd/gofile v1.2.0 h1:sCHG3icAFGO8gwl5Yy8llvhlIl8k5uaYa6uE23Z56MA= github.com/goradd/gofile v1.2.0/go.mod h1:ZjSvnGak2csGsJgEu8AgQc06eaoonhg2MzbqXON9o1M= +github.com/goradd/gofile v1.2.1 h1:rbUJ6HIoYWJxDqqRftceb48COv4M0HxkU5d8PdRElD4= +github.com/goradd/gofile v1.2.1/go.mod h1:ZjSvnGak2csGsJgEu8AgQc06eaoonhg2MzbqXON9o1M= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/internal/got/lexer.go b/internal/got/lexer.go index 345f23f..7dcab4c 100644 --- a/internal/got/lexer.go +++ b/internal/got/lexer.go @@ -524,14 +524,16 @@ func splitParams(paramString string) (params []string, err error) { s.Init(strings.NewReader(paramString)) for tok := s.Scan(); tok != scanner.EOF; tok = s.Scan() { text := s.TokenText() - if len(text) > 0 && text[0] == '"' && (len(text) == 1 || text[len(text)-1] != '"') { + if len(text) > 0 && + (text[0] == '"' && (len(text) == 1 || text[len(text)-1] != '"') || + (text[0] == '`' && (len(text) == 1 || text[len(text)-1] != '`'))) { err = fmt.Errorf("parameter has a beginning quote with no ending quote: %s", text) return } if text == "," { currentItem = strings.TrimSpace(currentItem) if currentItem != "" { - if currentItem[0] == '"' { + if currentItem[0] == '"' || currentItem[0] == '`' { currentItem, err = strconv.Unquote(currentItem) if err != nil { return @@ -548,7 +550,7 @@ func splitParams(paramString string) (params []string, err error) { } } if currentItem != "" { - if currentItem[0] == '"' { + if currentItem[0] == '"' || currentItem[0] == '`' { currentItem, err = strconv.Unquote(currentItem) if err != nil { return diff --git a/internal/got/parser.go b/internal/got/parser.go index c4a246a..d9f679b 100644 --- a/internal/got/parser.go +++ b/internal/got/parser.go @@ -293,7 +293,7 @@ func (p *parser) parseIf(item tokenItem) (items []tokenItem) { default: item.typ = itemError - item.val = "unexpected end block item" + item.val = "unexpected end block item: " + endItem.val return []tokenItem{item} } } diff --git a/internal/testdata/expected/TestSub.out b/internal/testdata/expected/TestSub.out index 38984ab..e7290c9 100755 --- a/internal/testdata/expected/TestSub.out +++ b/internal/testdata/expected/TestSub.out @@ -6,3 +6,7 @@ MeSubstituted: You Not Substituted: +Substituted: +You,"Me" +Not Substituted: +, diff --git a/internal/testdata/src/testSub.tpl.got b/internal/testdata/src/testSub.tpl.got index 6b387fc..da42f96 100644 --- a/internal/testdata/src/testSub.tpl.got +++ b/internal/testdata/src/testSub.tpl.got @@ -25,6 +25,7 @@ func TestSub(_w io.Writer) (err error) { if err = myTest2(_w); err != nil {return} if err = myTest3(_w); err != nil {return} if err = myTest4(_w); err != nil {return} + if err = myTest5(_w); err != nil {return} return } @@ -59,6 +60,21 @@ Not Substituted: return } +{{define fourth 2}} +$1,$2 +{{end fourth}} + +func myTest5(_w io.Writer) (err error) { +{{ +Substituted: +{{fourth "You", `"Me"`}} +Not Substituted: +{{fourth}} +}} +return +} + + func init() { registry.RegisterTest(TestSub, "TestSub") } \ No newline at end of file