From 789935df426d6a32848a84b0555029d4adf5291e Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Tue, 25 Jul 2023 14:17:00 -0500 Subject: [PATCH 1/3] task: moving the tests to a _test package --- ast/ast_test.go | 19 +++---- comments_test.go | 7 +-- context_test.go | 15 +++--- error_test.go | 7 +-- escape_test.go | 9 ++-- example_test.go | 18 ++++--- for_test.go | 47 ++++++++--------- functions_test.go | 29 ++++++----- hashes_test.go | 21 ++++---- helpers.go | 2 +- helpers_test.go | 9 ++-- if_test.go | 41 +++++++-------- iterators.go | 2 +- iterators_test.go | 15 +++--- lexer/lexer_test.go | 20 ++++---- line_number_test.go | 19 +++---- markdown_helper_test.go | 9 ++-- math_test.go | 19 +++---- numbers_test.go | 15 +++--- parser/parser_test.go | 111 ++++++++++++++++++++-------------------- partial_helper.go | 4 +- partial_helper_test.go | 95 +++++++++++++++++----------------- plush.go | 7 +++ plush_test.go | 51 +++++++++--------- quotes_test.go | 7 +-- return_exit_test.go | 13 ++--- script_test.go | 7 +-- struct_test.go | 79 ++++++++++++++-------------- template_test.go | 7 +-- time_test.go | 11 ++-- variables_test.go | 33 ++++++------ variadic_test.go | 23 +++++---- 32 files changed, 403 insertions(+), 368 deletions(-) diff --git a/ast/ast_test.go b/ast/ast_test.go index 50527b7..9d43053 100644 --- a/ast/ast_test.go +++ b/ast/ast_test.go @@ -1,24 +1,25 @@ -package ast +package ast_test import ( "testing" + "github.com/gobuffalo/plush/v4/ast" "github.com/gobuffalo/plush/v4/token" "github.com/stretchr/testify/require" ) func Test_Program_String(t *testing.T) { r := require.New(t) - program := &Program{ - Statements: []Statement{ - &LetStatement{ - TokenAble: TokenAble{token.Token{Type: token.LET, Literal: "let"}}, - Name: &Identifier{ - TokenAble: TokenAble{token.Token{Type: token.IDENT, Literal: "myVar"}}, + program := &ast.Program{ + Statements: []ast.Statement{ + &ast.LetStatement{ + TokenAble: ast.TokenAble{token.Token{Type: token.LET, Literal: "let"}}, + Name: &ast.Identifier{ + TokenAble: ast.TokenAble{token.Token{Type: token.IDENT, Literal: "myVar"}}, Value: "myVar", }, - Value: &Identifier{ - TokenAble: TokenAble{token.Token{Type: token.IDENT, Literal: "anotherVar"}}, + Value: &ast.Identifier{ + TokenAble: ast.TokenAble{token.Token{Type: token.IDENT, Literal: "anotherVar"}}, Value: "anotherVar", }, }, diff --git a/comments_test.go b/comments_test.go index 6981a9d..07d9fff 100644 --- a/comments_test.go +++ b/comments_test.go @@ -1,8 +1,9 @@ -package plush +package plush_test import ( "testing" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) @@ -20,7 +21,7 @@ func Test_Comment(t *testing.T) { } for _, test := range input { - s, err := Render(test, NewContext()) + s, err := plush.Render(test, plush.NewContext()) r.NoError(err) r.Contains(s, "Hi") r.NotContains(s, "this is a comment") @@ -42,7 +43,7 @@ func Test_BlockComment(t *testing.T) { } for _, test := range input { - s, err := Render(test, NewContext()) + s, err := plush.Render(test, plush.NewContext()) r.NoError(err) r.Contains(s, "Hi") r.NotContains(s, []string{"this is", "a block comment"}) diff --git a/context_test.go b/context_test.go index fedb37f..3d4644e 100644 --- a/context_test.go +++ b/context_test.go @@ -1,4 +1,4 @@ -package plush +package plush_test import ( "html/template" @@ -6,12 +6,13 @@ import ( "golang.org/x/sync/errgroup" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) func Test_Context_Set(t *testing.T) { r := require.New(t) - c := NewContext() + c := plush.NewContext() r.Nil(c.Value("foo")) c.Set("foo", "bar") r.NotNil(c.Value("foo")) @@ -19,7 +20,7 @@ func Test_Context_Set(t *testing.T) { func Test_Context_Set_Concurrency(t *testing.T) { r := require.New(t) - c := NewContext() + c := plush.NewContext() wg := errgroup.Group{} f := func() error { @@ -35,7 +36,7 @@ func Test_Context_Set_Concurrency(t *testing.T) { func Test_Context_Get(t *testing.T) { r := require.New(t) - c := NewContext() + c := plush.NewContext() r.Nil(c.Value("foo")) c.Set("foo", "bar") r.Equal("bar", c.Value("foo")) @@ -44,7 +45,7 @@ func Test_Context_Get(t *testing.T) { func Test_NewSubContext_Set(t *testing.T) { r := require.New(t) - c := NewContext() + c := plush.NewContext() r.Nil(c.Value("foo")) sc := c.New() @@ -58,7 +59,7 @@ func Test_NewSubContext_Set(t *testing.T) { func Test_NewSubContext_Get(t *testing.T) { r := require.New(t) - c := NewContext() + c := plush.NewContext() c.Set("foo", "bar") sc := c.New() @@ -67,7 +68,7 @@ func Test_NewSubContext_Get(t *testing.T) { func Test_Context_Override_Helper(t *testing.T) { r := require.New(t) - c := NewContext() + c := plush.NewContext() c.Set("debug", func(i interface{}) template.HTML { return template.HTML("DEBUG") }) diff --git a/error_test.go b/error_test.go index 9736f7c..ce06ee8 100644 --- a/error_test.go +++ b/error_test.go @@ -1,4 +1,4 @@ -package plush +package plush_test import ( "database/sql" @@ -6,17 +6,18 @@ import ( "errors" "testing" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) func TestErrorType(t *testing.T) { r := require.New(t) - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("sqlError", func() error { return sql.ErrNoRows }) - _, err := Render(`<%= sqlError() %>`, ctx) + _, err := plush.Render(`<%= sqlError() %>`, ctx) r.True(errors.Is(err, sql.ErrNoRows)) } diff --git a/escape_test.go b/escape_test.go index d92d1dc..67926ef 100644 --- a/escape_test.go +++ b/escape_test.go @@ -1,9 +1,10 @@ -package plush +package plush_test import ( "html/template" "testing" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) @@ -11,7 +12,7 @@ func Test_Render_EscapedString(t *testing.T) { r := require.New(t) input := `

<%= "" %>

` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal("

<script>alert('pwned')</script>

", s) } @@ -20,7 +21,7 @@ func Test_Render_HTML_Escape(t *testing.T) { r := require.New(t) input := `<%= escapedHTML() %>|<%= unescapedHTML() %>|<%= raw("unsafe") %>` - s, err := Render(input, NewContextWith(map[string]interface{}{ + s, err := plush.Render(input, plush.NewContextWith(map[string]interface{}{ "escapedHTML": func() string { return "unsafe" }, @@ -36,7 +37,7 @@ func Test_Escaping_EscapeExpression(t *testing.T) { r := require.New(t) input := `C:\\<%= "temp" %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal(`C:\temp`, s) } diff --git a/example_test.go b/example_test.go index cf4714e..a6a9f87 100644 --- a/example_test.go +++ b/example_test.go @@ -1,9 +1,11 @@ -package plush +package plush_test import ( "fmt" "html/template" "log" + + "github.com/gobuffalo/plush/v4" ) // ExampleRender using `if`, `for`, `else`, functions, etc... @@ -20,10 +22,10 @@ func ExampleRender() { <% } %> ` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("names", []string{"john", "paul", "george", "ringo"}) - s, err := Render(html, ctx) + s, err := plush.Render(html, ctx) if err != nil { log.Fatal(err) } @@ -55,7 +57,7 @@ let greet = fn(n) { %>

<%= greet(h["name"]) %>

` - s, err := Render(html, NewContext()) + s, err := plush.Render(html, plush.NewContext()) if err != nil { log.Fatal(err) } @@ -74,14 +76,14 @@ func ExampleRender_customHelperFunctions() { <% } %> ` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("one", func() int { return 1 }) ctx.Set("greet", func(s string) string { return fmt.Sprintf("Hi %s", s) }) - ctx.Set("can", func(s string, help HelperContext) (template.HTML, error) { + ctx.Set("can", func(s string, help plush.HelperContext) (template.HTML, error) { if s == "update" { h, err := help.Block() return template.HTML(h), err @@ -89,7 +91,7 @@ func ExampleRender_customHelperFunctions() { return "", nil }) - s, err := Render(html, ctx) + s, err := plush.Render(html, ctx) if err != nil { log.Fatal(err) } @@ -103,7 +105,7 @@ func ExampleRender_customHelperFunctions() { func ExampleRender_forIterator() { html := `<%= for (v) in between(3,6) { %><%=v%><% } %>` - s, err := Render(html, NewContext()) + s, err := plush.Render(html, plush.NewContext()) if err != nil { log.Fatal(err) } diff --git a/for_test.go b/for_test.go index 6b87c6a..933b9f0 100644 --- a/for_test.go +++ b/for_test.go @@ -1,16 +1,17 @@ -package plush +package plush_test import ( "strings" "testing" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) func Test_Render_For_Array(t *testing.T) { r := require.New(t) input := `<% for (i,v) in ["a", "b", "c"] {return v} %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal("", s) } @@ -18,7 +19,7 @@ func Test_Render_For_Array(t *testing.T) { func Test_Render_For_Hash(t *testing.T) { r := require.New(t) input := `<%= for (k,v) in myMap { %><%= k + ":" + v%><% } %>` - s, err := Render(input, NewContextWith(map[string]interface{}{ + s, err := plush.Render(input, plush.NewContextWith(map[string]interface{}{ "myMap": map[string]string{ "a": "A", "b": "B", @@ -32,7 +33,7 @@ func Test_Render_For_Hash(t *testing.T) { func Test_Render_For_Array_Return(t *testing.T) { r := require.New(t) input := `<%= for (i,v) in ["a", "b", "c"] {return v} %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal("abc", s) } @@ -50,7 +51,7 @@ func Test_Render_For_Array_Continue(t *testing.T) { return v } %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal("StartOddStart2StartOddStart4StartOddStart6StartOddStart8StartOddStart10", s) @@ -67,7 +68,7 @@ func Test_Render_For_Array_WithNoOutput(t *testing.T) { return v } %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal("", s) @@ -80,7 +81,7 @@ func Test_Render_For_Array_WithoutContinue(t *testing.T) { } return v } %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal("12345678910", s) @@ -92,7 +93,7 @@ func Test_Render_For_Array_ContinueNoControl(t *testing.T) { continue return v } %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal("", s) @@ -111,7 +112,7 @@ func Test_Render_For_Array_Break_String(t *testing.T) { return v } %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal("Start1Start2Start3Start4StartOdd", s) @@ -125,7 +126,7 @@ func Test_Render_For_Array_WithBreakFirstValue(t *testing.T) { } return v } %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal("", s) @@ -140,7 +141,7 @@ func Test_Render_For_Array_WithBreakFirstValueWithReturn(t *testing.T) { } return v } %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal("1", s) @@ -151,7 +152,7 @@ func Test_Render_For_Array_Break(t *testing.T) { break return v } %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal("", s) @@ -160,7 +161,7 @@ func Test_Render_For_Array_Break(t *testing.T) { func Test_Render_For_Array_Key_Only(t *testing.T) { r := require.New(t) input := `<%= for (v) in ["a", "b", "c"] {%><%=v%><%} %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal("abc", s) } @@ -168,7 +169,7 @@ func Test_Render_For_Array_Key_Only(t *testing.T) { func Test_Render_For_Func_Range(t *testing.T) { r := require.New(t) input := `<%= for (v) in range(3,5) { %><%=v%><% } %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal("345", s) } @@ -176,7 +177,7 @@ func Test_Render_For_Func_Range(t *testing.T) { func Test_Render_For_Func_Between(t *testing.T) { r := require.New(t) input := `<%= for (v) in between(3,6) { %><%=v%><% } %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal("45", s) } @@ -184,7 +185,7 @@ func Test_Render_For_Func_Between(t *testing.T) { func Test_Render_For_Func_Until(t *testing.T) { r := require.New(t) input := `<%= for (v) in until(3) { %><%=v%><% } %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal("012", s) } @@ -192,7 +193,7 @@ func Test_Render_For_Func_Until(t *testing.T) { func Test_Render_For_Array_Key_Value(t *testing.T) { r := require.New(t) input := `<%= for (i,v) in ["a", "b", "c"] {%><%=i%><%=v%><%} %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal("0a1b2c", s) } @@ -200,9 +201,9 @@ func Test_Render_For_Array_Key_Value(t *testing.T) { func Test_Render_For_Nil(t *testing.T) { r := require.New(t) input := `<% for (i,v) in nilValue {return v} %>` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("nilValue", nil) - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.Error(err) r.Equal("", s) } @@ -215,9 +216,9 @@ func Test_Render_For_Map_Nil_Value(t *testing.T) { <%= k %>:<%= v %> <% } %> ` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("flash", map[string][]string{}) - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("", strings.TrimSpace(s)) } @@ -231,12 +232,12 @@ type Product struct { func Test_Render_For_Array_OutofBoundIndex(t *testing.T) { r := require.New(t) - ctx := NewContext() + ctx := plush.NewContext() product_listing := Category{} ctx.Set("product_listing", product_listing) input := `<%= for (i, names) in product_listing.Products[0].Name { %> <%= splt %> <% } %>` - _, err := Render(input, ctx) + _, err := plush.Render(input, ctx) r.Error(err) } diff --git a/functions_test.go b/functions_test.go index 2c19904..573dcb7 100644 --- a/functions_test.go +++ b/functions_test.go @@ -1,4 +1,4 @@ -package plush +package plush_test import ( "errors" @@ -6,6 +6,7 @@ import ( "html/template" "testing" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) @@ -13,7 +14,7 @@ func Test_Render_Function_Call(t *testing.T) { r := require.New(t) input := `

<%= f() %>

` - s, err := Render(input, NewContextWith(map[string]interface{}{ + s, err := plush.Render(input, plush.NewContextWith(map[string]interface{}{ "f": func() string { return "hi!" }, @@ -26,7 +27,7 @@ func Test_Render_Unknown_Function_Call(t *testing.T) { r := require.New(t) input := `

<%= f() %>

` - _, err := Render(input, NewContext()) + _, err := plush.Render(input, plush.NewContext()) r.Error(err) } @@ -34,7 +35,7 @@ func Test_Render_Function_Call_With_Arg(t *testing.T) { r := require.New(t) input := `

<%= f("mark") %>

` - s, err := Render(input, NewContextWith(map[string]interface{}{ + s, err := plush.Render(input, plush.NewContextWith(map[string]interface{}{ "f": func(s string) string { return fmt.Sprintf("hi %s!", s) }, @@ -47,7 +48,7 @@ func Test_Render_Function_Call_With_Variable_Arg(t *testing.T) { r := require.New(t) input := `

<%= f(name) %>

` - s, err := Render(input, NewContextWith(map[string]interface{}{ + s, err := plush.Render(input, plush.NewContextWith(map[string]interface{}{ "f": func(s string) string { return fmt.Sprintf("hi %s!", s) }, @@ -61,7 +62,7 @@ func Test_Render_Function_Call_With_Hash(t *testing.T) { r := require.New(t) input := `

<%= f({name: name}) %>

` - s, err := Render(input, NewContextWith(map[string]interface{}{ + s, err := plush.Render(input, plush.NewContextWith(map[string]interface{}{ "f": func(m map[string]interface{}) string { return fmt.Sprintf("hi %s!", m["name"]) }, @@ -75,7 +76,7 @@ func Test_Render_Function_Call_With_Syntax_Error_Hash(t *testing.T) { r := require.New(t) input := `

<%= f({name: name) %>

` - _, err := Render(input, NewContextWith(map[string]interface{}{ + _, err := plush.Render(input, plush.NewContextWith(map[string]interface{}{ "f": func(m map[string]interface{}) string { return fmt.Sprintf("hi %s!", m["name"]) }, @@ -89,7 +90,7 @@ func Test_Render_Function_Call_With_Error(t *testing.T) { r := require.New(t) input := `

<%= f() %>

` - _, err := Render(input, NewContextWith(map[string]interface{}{ + _, err := plush.Render(input, plush.NewContextWith(map[string]interface{}{ "f": func() (string, error) { return "hi!", errors.New("oops") }, @@ -101,8 +102,8 @@ func Test_Render_Function_Call_With_Block(t *testing.T) { r := require.New(t) input := `

<%= f() { %>hello<% } %>

` - s, err := Render(input, NewContextWith(map[string]interface{}{ - "f": func(h HelperContext) string { + s, err := plush.Render(input, plush.NewContextWith(map[string]interface{}{ + "f": func(h plush.HelperContext) string { s, _ := h.Block() return s }, @@ -121,7 +122,7 @@ func Test_Render_Function_Call_On_Callee(t *testing.T) { r := require.New(t) input := `

<%= g.Greet("mark") %>

` - s, err := Render(input, NewContextWith(map[string]interface{}{ + s, err := plush.Render(input, plush.NewContextWith(map[string]interface{}{ "g": greeter{}, })) r.NoError(err) @@ -131,8 +132,8 @@ func Test_Render_Function_Call_On_Callee(t *testing.T) { func Test_Render_Function_Optional_Map(t *testing.T) { r := require.New(t) input := `<%= foo() %>|<%= bar({a: "A"}) %>` - s, err := Render(input, NewContextWith(map[string]interface{}{ - "foo": func(opts map[string]interface{}, help HelperContext) string { + s, err := plush.Render(input, plush.NewContextWith(map[string]interface{}{ + "foo": func(opts map[string]interface{}, help plush.HelperContext) string { return "foo" }, "bar": func(opts map[string]interface{}) string { @@ -183,7 +184,7 @@ func Test_Render_Function_With_Backticks_And_Quotes(t *testing.T) { LEFT JOIN papers on a.id=papers.id WHERE (papers.doc_status = ANY (ARRAY[1, 3])) AND papers.status = 1 WITH DATA` - s, err := Render(input, NewContextWith(map[string]interface{}{ + s, err := plush.Render(input, plush.NewContextWith(map[string]interface{}{ "raw": func(arg string) template.HTML { return template.HTML(arg) }, diff --git a/hashes_test.go b/hashes_test.go index d71e09f..8d13cf6 100644 --- a/hashes_test.go +++ b/hashes_test.go @@ -1,8 +1,9 @@ -package plush +package plush_test import ( "testing" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) @@ -10,7 +11,7 @@ func Test_Render_Hash_Key_Interface(t *testing.T) { r := require.New(t) input := `<%= m["first"]%>` - s, err := Render(input, NewContextWith(map[string]interface{}{ + s, err := plush.Render(input, plush.NewContextWith(map[string]interface{}{ "m": map[interface{}]bool{"first": true}, })) @@ -22,7 +23,7 @@ func Test_Render_Hash_Key_Int_With_String_Index(t *testing.T) { r := require.New(t) input := `<%= m["first"]%>` - _, err := Render(input, NewContextWith(map[string]interface{}{ + _, err := plush.Render(input, plush.NewContextWith(map[string]interface{}{ "m": map[int]bool{0: true}, })) @@ -37,7 +38,7 @@ func Test_Render_Hash_Array_Index(t *testing.T) { r := require.New(t) input := `<%= m["first"] + " " + m["last"] %>|<%= a[0+1] %>` - s, err := Render(input, NewContextWith(map[string]interface{}{ + s, err := plush.Render(input, plush.NewContextWith(map[string]interface{}{ "m": map[string]string{"first": "Mark", "last": "Bates"}, "a": []string{"john", "paul"}, })) @@ -48,11 +49,11 @@ func Test_Render_Hash_Array_Index(t *testing.T) { func Test_Render_HashCall(t *testing.T) { r := require.New(t) input := `<%= m["a"] %>` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("m", map[string]string{ "a": "A", }) - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("A", s) } @@ -60,14 +61,14 @@ func Test_Render_HashCall(t *testing.T) { func Test_Render_HashCall_OnAttribute(t *testing.T) { r := require.New(t) input := `<%= m.MyMap[key] %>` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("m", struct { MyMap map[string]string }{ MyMap: map[string]string{"a": "A"}, }) ctx.Set("key", "a") - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("A", s) } @@ -75,14 +76,14 @@ func Test_Render_HashCall_OnAttribute(t *testing.T) { func Test_Render_HashCall_OnAttribute_IntoFunction(t *testing.T) { r := require.New(t) input := `<%= debug(m.MyMap[key]) %>` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("m", struct { MyMap map[string]string }{ MyMap: map[string]string{"a": "A"}, }) ctx.Set("key", "a") - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("
A
", s) } diff --git a/helpers.go b/helpers.go index 16d1743..c071b96 100644 --- a/helpers.go +++ b/helpers.go @@ -20,7 +20,7 @@ var Helpers = HelperMap{ } func init() { - Helpers.Add("partial", partialHelper) + Helpers.Add("partial", PartialHelper) Helpers.AddMany(helpers.ALL()) Helpers.Add(forms.FormKey, bootstrap.Form) Helpers.Add(forms.FormForKey, bootstrap.FormFor) diff --git a/helpers_test.go b/helpers_test.go index 80c87a4..28a2426 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -1,8 +1,9 @@ -package plush +package plush_test import ( "testing" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) @@ -19,17 +20,17 @@ func Test_Helpers_WithoutData(t *testing.T) { } for _, tt := range table { - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("name", "unknown") ctx.Set("bar", "BAR") - ctx.Set("foo", func(d data, help HelperContext) (string, error) { + ctx.Set("foo", func(d data, help plush.HelperContext) (string, error) { c := help.New() if n, ok := d["name"]; ok { c.Set("name", n) } return help.BlockWith(c) }) - s, err := Render(tt.I, ctx) + s, err := plush.Render(tt.I, ctx) r.NoError(err) r.Equal(tt.E, s) } diff --git a/if_test.go b/if_test.go index 7d67f38..5343663 100644 --- a/if_test.go +++ b/if_test.go @@ -1,8 +1,9 @@ -package plush +package plush_test import ( "testing" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) @@ -47,7 +48,7 @@ func Test_If_Condition(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { r := require.New(t) - s, err := Render(tc.input, NewContext()) + s, err := plush.Render(tc.input, plush.NewContext()) if tc.success { r.NoError(err) r.Equal(tc.expected, s) @@ -59,9 +60,9 @@ func Test_If_Condition(t *testing.T) { } func Test_Condition_Only(t *testing.T) { - ctx_empty := NewContext() + ctx_empty := plush.NewContext() - ctx_with_paths := NewContext() + ctx_with_paths := plush.NewContext() ctx_with_paths.Set("paths", "cart") tests := []struct { @@ -69,7 +70,7 @@ func Test_Condition_Only(t *testing.T) { expected string name string success bool - context *Context + context *plush.Context }{ {`<%= paths == nil %>`, "true", "unknown_equal_to_nil", true, ctx_empty}, {`<%= nil == paths %>`, "true", "nil_equal_to_unknown", true, ctx_empty}, @@ -99,7 +100,7 @@ func Test_Condition_Only(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { r := require.New(t) - s, err := Render(tc.input, tc.context) + s, err := plush.Render(tc.input, tc.context) if tc.success { r.NoError(err) r.Equal(tc.expected, s) @@ -112,26 +113,26 @@ func Test_Condition_Only(t *testing.T) { func Test_If_Else_If_Else_True(t *testing.T) { r := require.New(t) - ctx := NewContext() + ctx := plush.NewContext() input := `

<%= if (state == "foo") { %>hi foo<% } else if (state == "bar") { %>hi bar<% } else if (state == "fizz") { %>hi fizz<% } else { %>hi buzz<% } %>

` ctx.Set("state", "foo") - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("

hi foo

", s) ctx.Set("state", "bar") - s, err = Render(input, ctx) + s, err = plush.Render(input, ctx) r.NoError(err) r.Equal("

hi bar

", s) ctx.Set("state", "fizz") - s, err = Render(input, ctx) + s, err = plush.Render(input, ctx) r.NoError(err) r.Equal("

hi fizz

", s) ctx.Set("state", "buzz") - s, err = Render(input, ctx) + s, err = plush.Render(input, ctx) r.NoError(err) r.Equal("

hi buzz

", s) } @@ -139,48 +140,48 @@ func Test_If_Else_If_Else_True(t *testing.T) { func Test_If_String_Truthy(t *testing.T) { r := require.New(t) - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("username", "") input := `

<%= if (username && username != "") { return "hi" } else { return "bye" } %>

` - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("

bye

", s) ctx.Set("username", "foo") - s, err = Render(input, ctx) + s, err = plush.Render(input, ctx) r.NoError(err) r.Equal("

hi

", s) } func Test_If_Variable_Not_Set_But_Or_Condition_Is_True_Complex(t *testing.T) { r := require.New(t) - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("path", "cart") ctx.Set("paths", "cart") input := `<%= if ( paths == "cart" || (page && page.PageTitle != "cafe") || paths == "cart") { %>hi<%} %>` - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("hi", s) } func Test_If_Syntax_Error_On_Last_Node(t *testing.T) { r := require.New(t) - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("paths", "cart") input := `<%= if ( paths == "cart" || pages ^^^ ) { %>hi<%} %>` - _, err := Render(input, ctx) + _, err := plush.Render(input, ctx) r.Error(err) } func Test_If_Syntax_Error_On_First_Node(t *testing.T) { r := require.New(t) - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("paths", "cart") input := `<%= if ( paths @#@# "cart" || pages) { %>hi<%} %>` - _, err := Render(input, ctx) + _, err := plush.Render(input, ctx) r.Error(err) } diff --git a/iterators.go b/iterators.go index ad0c485..4d64bc4 100644 --- a/iterators.go +++ b/iterators.go @@ -35,7 +35,7 @@ func untilHelper(a int) Iterator { return &ranger{pos: -1, end: a - 1} } -func groupByHelper(size int, underlying interface{}) (*groupBy, error) { +func GroupByHelper(size int, underlying interface{}) (*groupBy, error) { if size <= 0 { return nil, fmt.Errorf("size must be greater than zero") } diff --git a/iterators_test.go b/iterators_test.go index 279779c..3c8a792 100644 --- a/iterators_test.go +++ b/iterators_test.go @@ -1,14 +1,15 @@ -package plush +package plush_test import ( "testing" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) func Test_groupByHelper(t *testing.T) { r := require.New(t) - g, err := groupByHelper(2, []string{"a", "b", "c", "d", "e"}) + g, err := plush.GroupByHelper(2, []string{"a", "b", "c", "d", "e"}) r.NoError(err) g1 := g.Next() r.Equal([]string{"a", "b", "c"}, g1) @@ -19,7 +20,7 @@ func Test_groupByHelper(t *testing.T) { func Test_groupByHelper_Exact(t *testing.T) { r := require.New(t) - g, err := groupByHelper(2, []string{"a", "b"}) + g, err := plush.GroupByHelper(2, []string{"a", "b"}) r.NoError(err) g1 := g.Next() r.Equal([]string{"a", "b"}, g1) @@ -28,7 +29,7 @@ func Test_groupByHelper_Exact(t *testing.T) { func Test_groupByHelper_Pointer(t *testing.T) { r := require.New(t) - g, err := groupByHelper(2, &[]string{"a", "b", "c", "d", "e"}) + g, err := plush.GroupByHelper(2, &[]string{"a", "b", "c", "d", "e"}) r.NoError(err) g1 := g.Next() r.Equal([]string{"a", "b", "c"}, g1) @@ -39,7 +40,7 @@ func Test_groupByHelper_Pointer(t *testing.T) { func Test_groupByHelper_SmallGroup(t *testing.T) { r := require.New(t) - g, err := groupByHelper(1, []string{"a", "b", "c", "d", "e"}) + g, err := plush.GroupByHelper(1, []string{"a", "b", "c", "d", "e"}) r.NoError(err) g1 := g.Next() r.Equal([]string{"a", "b", "c", "d", "e"}, g1) @@ -48,12 +49,12 @@ func Test_groupByHelper_SmallGroup(t *testing.T) { func Test_groupByHelper_NonGroupable(t *testing.T) { r := require.New(t) - _, err := groupByHelper(1, 1) + _, err := plush.GroupByHelper(1, 1) r.Error(err) } func Test_groupByHelper_ZeroSize(t *testing.T) { r := require.New(t) - _, err := groupByHelper(0, []string{"a"}) + _, err := plush.GroupByHelper(0, []string{"a"}) r.Error(err) } diff --git a/lexer/lexer_test.go b/lexer/lexer_test.go index 69263ef..90329a2 100644 --- a/lexer/lexer_test.go +++ b/lexer/lexer_test.go @@ -1,11 +1,11 @@ -package lexer +package lexer_test import ( "testing" - "github.com/stretchr/testify/require" - + "github.com/gobuffalo/plush/v4/lexer" "github.com/gobuffalo/plush/v4/token" + "github.com/stretchr/testify/require" ) func Test_NextToken_Simple(t *testing.T) { @@ -20,7 +20,7 @@ func Test_NextToken_Simple(t *testing.T) { {token.E_END, "%>"}, } - l := New(input) + l := lexer.New(input) for _, tt := range tests { tok := l.NextToken() r.Equal(tt.tokenType, tok.Type) @@ -44,7 +44,7 @@ func Test_NextToken_SkipLineComments(t *testing.T) { {token.E_END, "%>"}, } - l := New(input) + l := lexer.New(input) for _, tt := range tests { tok := l.NextToken() r.Equal(tt.tokenType, tok.Type) @@ -64,7 +64,7 @@ func Test_EscapeStringQuote(t *testing.T) { {token.E_END, "%>"}, } - l := New(input) + l := lexer.New(input) for _, tt := range tests { tok := l.NextToken() r.Equal(tt.tokenType, tok.Type) @@ -82,7 +82,7 @@ func Test_EscapeExpression(t *testing.T) { {token.HTML, `

<%= 1 %>

`}, } - l := New(input) + l := lexer.New(input) for _, tt := range tests { tok := l.NextToken() r.Equal(tt.tokenType, tok.Type) @@ -93,7 +93,7 @@ func Test_EscapeExpression(t *testing.T) { func Test_Escaping_EscapeExpression(t *testing.T) { r := require.New(t) input := `C:\\<%= "temp" %>` - l := New(input) + l := lexer.New(input) tests := []struct { tokenType token.Type @@ -126,7 +126,7 @@ func Test_NextToken_WithHTML(t *testing.T) { {token.HTML, `

`}, } - l := New(input) + l := lexer.New(input) for _, tt := range tests { tok := l.NextToken() r.Equal(tt.tokenType, tok.Type) @@ -332,7 +332,7 @@ my-helper() {token.EOF, ""}, } - l := New(input) + l := lexer.New(input) for _, tt := range tests { tok := l.NextToken() diff --git a/line_number_test.go b/line_number_test.go index fe92da4..3915f2b 100644 --- a/line_number_test.go +++ b/line_number_test.go @@ -1,8 +1,9 @@ -package plush +package plush_test import ( "testing" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) @@ -12,7 +13,7 @@ func Test_LineNumberErrors(t *testing.T) { <%= f.Foo %>

` - _, err := Render(input, NewContext()) + _, err := plush.Render(input, plush.NewContext()) r.Error(err) r.Contains(err.Error(), "line 2:") } @@ -25,7 +26,7 @@ func Test_LineNumberErrors_ForLoop(t *testing.T) { <% } %> ` - _, err := Render(input, NewContext()) + _, err := plush.Render(input, plush.NewContext()) r.Error(err) r.Contains(err.Error(), "line 2:") } @@ -40,7 +41,7 @@ func Test_LineNumberErrors_ForLoop2(t *testing.T) { <% } %> ` - _, err := Parse(input) + _, err := plush.Parse(input) r.Error(err) r.Contains(err.Error(), "line 2:") } @@ -52,9 +53,9 @@ func Test_LineNumberErrors_InsideForLoop(t *testing.T) { <%= n.Foo %> <% } %> ` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("numbers", []int{1, 2}) - _, err := Render(input, ctx) + _, err := plush.Render(input, ctx) r.Error(err) r.Contains(err.Error(), "line 3:") } @@ -70,9 +71,9 @@ func Test_LineNumberErrors_MissingKeyword(t *testing.T) { <%= n %> <% } %> ` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("numbers", []int{1, 2}) - _, err := Render(input, ctx) + _, err := plush.Render(input, ctx) r.Error(err) r.Contains(err.Error(), "line 6:") -} \ No newline at end of file +} diff --git a/markdown_helper_test.go b/markdown_helper_test.go index c20ef58..2e95b62 100644 --- a/markdown_helper_test.go +++ b/markdown_helper_test.go @@ -1,17 +1,18 @@ -package plush +package plush_test import ( "testing" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) func Test_MarkdownHelper(t *testing.T) { r := require.New(t) input := `<%= markdown(m) %>` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("m", "# H1") - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Contains(s, "H1") } @@ -19,7 +20,7 @@ func Test_MarkdownHelper(t *testing.T) { func Test_MarkdownHelper_WithBlock(t *testing.T) { r := require.New(t) input := `<%= markdown("") { return "# H2" } %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Contains(s, "H2") } diff --git a/math_test.go b/math_test.go index 1649cfb..a9071b3 100644 --- a/math_test.go +++ b/math_test.go @@ -1,9 +1,10 @@ -package plush +package plush_test import ( "fmt" "testing" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) @@ -31,7 +32,7 @@ func Test_Render_Int_Math(t *testing.T) { } for _, tt := range tests { input := fmt.Sprintf("<%%= %d %s %d %%>", tt.a, tt.op, tt.b) - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal(tt.res, s) } @@ -61,7 +62,7 @@ func Test_Render_Float_Math(t *testing.T) { } for _, tt := range tests { input := fmt.Sprintf("<%%= %f %s %f %%>", tt.a, tt.op, tt.b) - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal(tt.res, s) } @@ -87,7 +88,7 @@ func Test_Render_String_Math(t *testing.T) { for _, tt := range tests { input := fmt.Sprintf("<%%= %q %s %q %%>", tt.a, tt.op, tt.b) - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal(tt.res, s) } @@ -114,7 +115,7 @@ func Test_Render_Operator_UndefinedVar(t *testing.T) { t.Run(tc.operator, func(t *testing.T) { r := require.New(t) input := fmt.Sprintf("<%%= undefined %s 3 %%>", tc.operator) - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) if tc.errorExpected { r.Error(err, "undefined %s 3 --> '%v'", tc.operator, tc.result) } else { @@ -123,7 +124,7 @@ func Test_Render_Operator_UndefinedVar(t *testing.T) { r.Equal(tc.result, s, "undefined %s 3", tc.operator) input = fmt.Sprintf("<%%= 3 %s unknown %%>", tc.operator) - s, err = Render(input, NewContext()) + s, err = plush.Render(input, plush.NewContext()) if tc.errorExpected { r.Error(err, "3 %s undefined --> '%v'", tc.operator, tc.result) } else { @@ -138,7 +139,7 @@ func Test_Render_String_Concat_Multiple(t *testing.T) { r := require.New(t) input := `<%= "a" + "b" + "c" %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal("abc", s) } @@ -147,7 +148,7 @@ func Test_Render_String_Int_Concat(t *testing.T) { r := require.New(t) input := `<%= "a" + 1 %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal("a1", s) } @@ -156,7 +157,7 @@ func Test_Render_Bool_Concat(t *testing.T) { r := require.New(t) input := `<%= true + 1 %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.Equal("true", s) r.NoError(err) } diff --git a/numbers_test.go b/numbers_test.go index fb4d9f5..e37a228 100644 --- a/numbers_test.go +++ b/numbers_test.go @@ -1,8 +1,9 @@ -package plush +package plush_test import ( "testing" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) @@ -11,21 +12,21 @@ func Test_Identifiers_With_Digits(t *testing.T) { r := require.New(t) input := `<%= my123greet %> <%= name3 %>` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("my123greet", "hi") ctx.Set("name3", "mark") - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("hi mark", s) } func Test_Render_Var_ends_in_Number(t *testing.T) { r := require.New(t) - ctx := NewContextWith(map[string]interface{}{ + ctx := plush.NewContextWith(map[string]interface{}{ "myvar1": []string{"john", "paul"}, }) - s, err := Render(`<%= for (n) in myvar1 {return n}`, ctx) + s, err := plush.Render(`<%= for (n) in myvar1 {return n}`, ctx) r.NoError(err) r.Equal("johnpaul", s) } @@ -34,12 +35,12 @@ func Test_Render_AllowsManyNumericTypes(t *testing.T) { r := require.New(t) input := `<%= i32 %> <%= u32 %> <%= i8 %>` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("i32", int32(1)) ctx.Set("u32", uint32(2)) ctx.Set("i8", int8(3)) - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("1 2 3", s) } diff --git a/parser/parser_test.go b/parser/parser_test.go index 7fe220e..057fee7 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -1,10 +1,11 @@ -package parser +package parser_test import ( "fmt" "testing" "github.com/gobuffalo/plush/v4/ast" + "github.com/gobuffalo/plush/v4/parser" "github.com/stretchr/testify/require" ) @@ -21,7 +22,7 @@ func Test_LetStatements(t *testing.T) { } for _, tt := range tests { - program, err := Parse(tt.input) + program, err := parser.Parse(tt.input) r.NoError(err) r.Len(program.Statements, 1) @@ -51,7 +52,7 @@ func Test_ReturnStatements(t *testing.T) { } for _, tt := range tests { - program, err := Parse("<%" + tt.input + "%>") + program, err := parser.Parse("<%" + tt.input + "%>") r.NoError(err) r.Len(program.Statements, 1) @@ -67,7 +68,7 @@ func Test_IdentifierExpression(t *testing.T) { r := require.New(t) input := "<% foobar; %>" - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) r.Len(program.Statements, 1) @@ -81,7 +82,7 @@ func Test_IntegerLiteralExpression(t *testing.T) { r := require.New(t) input := "<% 5; %>" - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) r.Len(program.Statements, 1) @@ -95,7 +96,7 @@ func Test_FloatLiteralExpression(t *testing.T) { r := require.New(t) input := "<% 1.23 %>" - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) r.Len(program.Statements, 1) @@ -122,7 +123,7 @@ func Test_PrefixExpressions(t *testing.T) { } for _, tt := range prefixTests { - program, err := Parse("<%" + tt.input + "%>") + program, err := parser.Parse("<%" + tt.input + "%>") r.NoError(err) r.Len(program.Statements, 1) @@ -166,7 +167,7 @@ func Test_InfixExpressions(t *testing.T) { } for _, tt := range infixTests { - program, err := Parse("<%" + tt.input + "%>") + program, err := parser.Parse("<%" + tt.input + "%>") r.NoError(err) r.Len(program.Statements, 1) @@ -304,7 +305,7 @@ func Test_OperatorPrecedence(t *testing.T) { } for _, tt := range tests { - program, err := Parse("<%" + tt.input + "%>") + program, err := parser.Parse("<%" + tt.input + "%>") r.NoError(err) r.Equal(tt.expected, program.InnerText()) @@ -322,7 +323,7 @@ func Test_BooleanExpression(t *testing.T) { } for _, tt := range tests { - program, err := Parse("<%" + tt.input + "%>") + program, err := parser.Parse("<%" + tt.input + "%>") r.NoError(err) r.Len(program.Statements, 1) @@ -338,7 +339,7 @@ func Test_IfExpression(t *testing.T) { r := require.New(t) input := `<% if (x < y) { x } %>` - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) r.Len(program.Statements, 1) @@ -361,7 +362,7 @@ func Test_IfExpression_ComapreWithFunction(t *testing.T) { r := require.New(t) input := `<% if (f() != "yes") { x } %>` - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) r.Len(program.Statements, 1) @@ -393,7 +394,7 @@ func Test_IfExpression_PrefixExpressions_InvalidCompar(t *testing.T) { r := require.New(t) input := `<% if (!(x = 1)) { x } %>` - _, err := Parse(input) + _, err := parser.Parse(input) r.Error(err, "syntax error: invalid if condition, got x = 1") } @@ -401,7 +402,7 @@ func Test_IfExpression_With_Map_Array_Index(t *testing.T) { r := require.New(t) input := `<% if (flash["error"] ) { x } %>` - _, err := Parse(input) + _, err := parser.Parse(input) r.NoError(err) } @@ -410,7 +411,7 @@ func Test_IfExpression_InfixExpressions_InvalidCompare(t *testing.T) { r := require.New(t) input := `<% if ( y == 1 && x = 1) { x } %>` - _, err := Parse(input) + _, err := parser.Parse(input) r.Error(err, "syntax error: invalid if condition, got x = 1") } @@ -419,7 +420,7 @@ func Test_IfExpression_Boolean(t *testing.T) { r := require.New(t) input := `<% if (true) { x } %>` - _, err := Parse(input) + _, err := parser.Parse(input) r.NoError(err) @@ -429,7 +430,7 @@ func Test_IfExpression_Condition_CompareToString(t *testing.T) { r := require.New(t) input := `<% if (x == "yes") { x } %>` - _, err := Parse(input) + _, err := parser.Parse(input) r.NoError(err, "syntax error: invalid if condition, got x = y") @@ -438,7 +439,7 @@ func Test_IfExpression_Condition_Assign(t *testing.T) { r := require.New(t) input := `<% if (x = y) { x } %>` - _, err := Parse(input) + _, err := parser.Parse(input) r.Error(err, "syntax error: invalid if condition, got x = y") @@ -448,7 +449,7 @@ func Test_IfExpression_Condition_EmptyHash(t *testing.T) { r := require.New(t) input := `<% if ({}}) { x } %>` - _, err := Parse(input) + _, err := parser.Parse(input) r.Error(err, "syntax error: invalid if statment, got {}") } @@ -456,7 +457,7 @@ func Test_IfExpression_HTML(t *testing.T) { r := require.New(t) input := `

<% if (x < y) { %><%= x %><% } %>

` - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) r.Len(program.Statements, 3) @@ -483,7 +484,7 @@ func Test_IfExpression_HTML_NoClosingTag(t *testing.T) { r := require.New(t) // the template should have a missing '%>' after the if condition input := `

<% if (x < y) { Hello Buffalo <% } %>` - program, err := Parse(input) + program, err := parser.Parse(input) r.Error(err, "Error parsing invalid if statement expected") // but there should still be two parsed statements @@ -506,7 +507,7 @@ func Test_IfExpression_Return_HTML_NoClosingTag(t *testing.T) { r := require.New(t) // the template should have a missing '%>' after the if condition input := `

<%= if (x < y) { Hello Buffalo <% } %>` - program, err := Parse(input) + program, err := parser.Parse(input) r.Error(err, "Error parsing invalid if statement expected") // but there should still be two parsed statements @@ -529,7 +530,7 @@ func Test_IfElseExpression(t *testing.T) { r := require.New(t) input := `<% if (x < y) { x } else { y } %>` - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) r.Len(program.Statements, 1) @@ -557,7 +558,7 @@ func Test_FunctionLiteralParsing(t *testing.T) { r := require.New(t) input := `<% fn(x, y) { x + y; } %>` - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) r.Len(program.Statements, 1) @@ -590,7 +591,7 @@ func Test_FunctionParameterParsing(t *testing.T) { } for _, tt := range tests { - program, err := Parse("<%" + tt.input + "%>") + program, err := parser.Parse("<%" + tt.input + "%>") r.NoError(err) stmt := program.Statements[0].(*ast.ExpressionStatement) @@ -607,7 +608,7 @@ func Test_CallExpression(t *testing.T) { r := require.New(t) input := "<% add(1, 2 * 3, 4 + 5); %>" - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) r.Len(program.Statements, 1) @@ -650,7 +651,7 @@ func Test_CallExpressionParameter(t *testing.T) { } for _, tt := range tests { - program, err := Parse("<%" + tt.input + "%>") + program, err := parser.Parse("<%" + tt.input + "%>") r.NoError(err) stmt := program.Statements[0].(*ast.ExpressionStatement) @@ -670,7 +671,7 @@ func Test_CallExpressionParsing_WithCallee(t *testing.T) { r := require.New(t) input := `<%= g.Greet("mark"); %>` - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) r.Len(program.Statements, 1) @@ -691,7 +692,7 @@ func Test_CallExpressionParsing_WithMultipleCallees(t *testing.T) { r := require.New(t) input := `<%= g.Foo.Greet("mark"); %>` - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) r.Len(program.Statements, 1) @@ -712,7 +713,7 @@ func Test_IndexExpression_Nested_Structs_Start_WithCallee(t *testing.T) { r := require.New(t) input := `<% myarray[0].Name.Final %>` - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) r.Len(program.Statements, 1) @@ -734,7 +735,7 @@ func Test_IndexExpression_Nested_Structs_Start_WithNested_Array(t *testing.T) { r := require.New(t) input := `<% myarray[0].Name[1].Final %>` - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) r.Len(program.Statements, 1) @@ -760,7 +761,7 @@ func Test_CallExpressionParsing_WithBlock(t *testing.T) { r := require.New(t) input := `

<%= foo() { %>hi<% } %>

` - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) r.Len(program.Statements, 3) @@ -785,7 +786,7 @@ func Test_StringLiteralExpression(t *testing.T) { r := require.New(t) input := `<% "hello world"; %>` - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) stmt := program.Statements[0].(*ast.ExpressionStatement) @@ -798,7 +799,7 @@ func Test_StringBlockExpression(t *testing.T) { r := require.New(t) input := "<% `hello world`; %>" - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) stmt := program.Statements[0].(*ast.ExpressionStatement) @@ -811,7 +812,7 @@ func Test_EmptyArrayLiterals(t *testing.T) { r := require.New(t) input := "<% [] %>" - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) stmt := program.Statements[0].(*ast.ExpressionStatement) @@ -824,7 +825,7 @@ func Test_ArrayLiterals(t *testing.T) { r := require.New(t) input := "<% [1, 2 * 2, 3 + 3] %>" - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) stmt := program.Statements[0].(*ast.ExpressionStatement) @@ -841,7 +842,7 @@ func Test_IndexExpressionsAssign(t *testing.T) { r := require.New(t) input := "<% myArray[2] = 1 %>" - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) stmt := program.Statements[0].(*ast.ExpressionStatement) @@ -857,7 +858,7 @@ func Test_IndexExpressions(t *testing.T) { r := require.New(t) input := "<% myArray[1 + 1] %>" - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) stmt := program.Statements[0].(*ast.ExpressionStatement) @@ -872,7 +873,7 @@ func Test_EmptyHashLiteral(t *testing.T) { r := require.New(t) input := "<% {} %>" - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) stmt := program.Statements[0].(*ast.ExpressionStatement) @@ -885,7 +886,7 @@ func Test_HashLiteralsStringKeys(t *testing.T) { r := require.New(t) input := `<% {"one": 1, "two": 2, "three": 3} %>` - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) stmt := program.Statements[0].(*ast.ExpressionStatement) @@ -911,7 +912,7 @@ func Test_HashLiteralsBooleanKeys(t *testing.T) { r := require.New(t) input := `<%{true: 1, false: 2}%>` - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) stmt := program.Statements[0].(*ast.ExpressionStatement) @@ -936,7 +937,7 @@ func Test_HashLiteralsIntegerKeys(t *testing.T) { r := require.New(t) input := `<% {1: 1, 2: 2, 3: 3} %>` - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) stmt := program.Statements[0].(*ast.ExpressionStatement) @@ -963,7 +964,7 @@ func Test_HashLiteralsWithExpressions(t *testing.T) { r := require.New(t) input := `<% {"one": 0 + 1, "two": 10 - 8, "three": 15 / 5} %>` - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) stmt := program.Statements[0].(*ast.ExpressionStatement) @@ -1052,7 +1053,7 @@ func Test_ForExpression_WithContinue(t *testing.T) { r := require.New(t) input := `<% for (k,v) in myArray { continue } %>` - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) r.Len(program.Statements, 1) @@ -1077,7 +1078,7 @@ func Test_ForExpression_WithBreak(t *testing.T) { r := require.New(t) input := `<% for (k,v) in myArray { break } %>` - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) r.Len(program.Statements, 1) @@ -1102,7 +1103,7 @@ func Test_Continue_IfCondtion(t *testing.T) { r := require.New(t) input := `<% if(x == 2) { continue } %>` - _, err := Parse(input) + _, err := parser.Parse(input) r.Error(err) } @@ -1110,7 +1111,7 @@ func Test_Break_IfCondtion(t *testing.T) { r := require.New(t) input := `<% if(x == 2) { break } %>` - _, err := Parse(input) + _, err := parser.Parse(input) r.Error(err) } @@ -1118,7 +1119,7 @@ func Test_Empty_IfCondtion(t *testing.T) { r := require.New(t) input := `<% if() { v } %>` - _, err := Parse(input) + _, err := parser.Parse(input) r.Error(err) } @@ -1126,7 +1127,7 @@ func Test_Continue_Function(t *testing.T) { r := require.New(t) input := `<% fn(x, y) { continue } %>` - _, err := Parse(input) + _, err := parser.Parse(input) r.Error(err) } @@ -1134,7 +1135,7 @@ func Test_Break_Function(t *testing.T) { r := require.New(t) input := `<% fn(x, y) { break } %>` - _, err := Parse(input) + _, err := parser.Parse(input) r.Error(err) } @@ -1142,7 +1143,7 @@ func Test_ForExpression(t *testing.T) { r := require.New(t) input := `<% for (k,v) in myArray { v } %>` - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) r.Len(program.Statements, 1) @@ -1168,7 +1169,7 @@ func Test_ForExpression_Split(t *testing.T) {

<%= v %>

<% } %>` - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) r.Len(program.Statements, 1) @@ -1189,7 +1190,7 @@ func Test_ForExpression_Func(t *testing.T) {

<%= v %>

<% } %>` - program, err := Parse(input) + program, err := parser.Parse(input) r.NoError(err) r.Len(program.Statements, 1) @@ -1219,7 +1220,7 @@ func Test_AndOrInfixExpressions(t *testing.T) { } for _, tt := range infixTests { - program, err := Parse("<% " + tt.input + "%>") + program, err := parser.Parse("<% " + tt.input + "%>") r.NoError(err) r.Len(program.Statements, 1) @@ -1253,7 +1254,7 @@ create_table("users_2", {"timestamps": false}) { } drop_column("table_name", "column1_name") drop_column("table_name", "column2_name")` - p, err := Parse("<%" + input + "%>") + p, err := parser.Parse("<%" + input + "%>") r.NoError(err) r.Equal(input, p.String()) } diff --git a/partial_helper.go b/partial_helper.go index 98ec0e7..fff2c0f 100644 --- a/partial_helper.go +++ b/partial_helper.go @@ -12,7 +12,7 @@ import ( // PartialFeeder is callback function should implemented on application side. type PartialFeeder func(string) (string, error) -func partialHelper(name string, data map[string]interface{}, help HelperContext) (template.HTML, error) { +func PartialHelper(name string, data map[string]interface{}, help HelperContext) (template.HTML, error) { if help.Context == nil { return "", fmt.Errorf("invalid context. abort") } @@ -50,7 +50,7 @@ func partialHelper(name string, data map[string]interface{}, help HelperContext) } if layout, ok := data["layout"].(string); ok { - return partialHelper( + return PartialHelper( layout, map[string]interface{}{"yield": template.HTML(part)}, help) diff --git a/partial_helper_test.go b/partial_helper_test.go index bd808b1..5a4a365 100644 --- a/partial_helper_test.go +++ b/partial_helper_test.go @@ -1,4 +1,4 @@ -package plush +package plush_test import ( "fmt" @@ -6,6 +6,7 @@ import ( "testing" "github.com/gobuffalo/helpers/hctx" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) @@ -14,9 +15,9 @@ func Test_PartialHelper_Nil_Context(t *testing.T) { name := "index" data := map[string]interface{}{} - help := HelperContext{} + help := plush.HelperContext{} - html, err := partialHelper(name, data, help) + html, err := plush.PartialHelper(name, data, help) r.Error(err) r.Contains(err.Error(), "invalid context") r.Equal("", string(html)) @@ -27,9 +28,9 @@ func Test_PartialHelper_Blank_Context(t *testing.T) { name := "index" data := map[string]interface{}{} - help := HelperContext{Context: NewContext()} + help := plush.HelperContext{Context: plush.NewContext()} - html, err := partialHelper(name, data, help) + html, err := plush.PartialHelper(name, data, help) r.Error(err) r.Contains(err.Error(), "could not found") r.Equal("", string(html)) @@ -40,10 +41,10 @@ func Test_PartialHelper_Invalid_Feeder(t *testing.T) { name := "index" data := map[string]interface{}{} - help := HelperContext{Context: NewContext()} + help := plush.HelperContext{Context: plush.NewContext()} help.Set("partialFeeder", "me-rong") - html, err := partialHelper(name, data, help) + html, err := plush.PartialHelper(name, data, help) r.Error(err) r.Contains(err.Error(), "could not found") r.Equal("", string(html)) @@ -54,12 +55,12 @@ func Test_PartialHelper_Invalid_FeederFunction(t *testing.T) { name := "index" data := map[string]interface{}{} - help := HelperContext{Context: NewContext()} + help := plush.HelperContext{Context: plush.NewContext()} help.Set("partialFeeder", func(string) string { return "me-rong" }) - html, err := partialHelper(name, data, help) + html, err := plush.PartialHelper(name, data, help) r.Error(err) r.Contains(err.Error(), "could not found") r.Equal("", string(html)) @@ -70,12 +71,12 @@ func Test_PartialHelper_Feeder_Error(t *testing.T) { name := "index" data := map[string]interface{}{} - help := HelperContext{Context: NewContext()} + help := plush.HelperContext{Context: plush.NewContext()} help.Set("partialFeeder", func(string) (string, error) { return "", fmt.Errorf("me-rong") }) - _, err := partialHelper(name, data, help) + _, err := plush.PartialHelper(name, data, help) r.Error(err) r.Contains(err.Error(), "me-rong") } @@ -85,12 +86,12 @@ func Test_PartialHelper_Good(t *testing.T) { name := "index" data := map[string]interface{}{} - help := HelperContext{Context: NewContext()} + help := plush.HelperContext{Context: plush.NewContext()} help.Set("partialFeeder", func(string) (string, error) { return `
Plush!
`, nil }) - html, err := partialHelper(name, data, help) + html, err := plush.PartialHelper(name, data, help) r.NoError(err) r.Equal(`
Plush!
`, string(html)) } @@ -100,12 +101,12 @@ func Test_PartialHelper_With_Data(t *testing.T) { name := "index" data := map[string]interface{}{"name": "Yonghwan"} - help := HelperContext{Context: NewContext()} + help := plush.HelperContext{Context: plush.NewContext()} help.Set("partialFeeder", func(string) (string, error) { return `
Hello <%= name %>
`, nil }) - html, err := partialHelper(name, data, help) + html, err := plush.PartialHelper(name, data, help) r.NoError(err) r.Equal(`
Hello Yonghwan
`, string(html)) } @@ -115,7 +116,7 @@ func Test_PartialHelper_With_InternalChange(t *testing.T) { name := "index" data := map[string]interface{}{} - help := HelperContext{Context: NewContextWith(map[string]interface{}{ + help := plush.HelperContext{Context: plush.NewContextWith(map[string]interface{}{ "number": 3, })} help.Set("partialFeeder", func(string) (string, error) { @@ -123,7 +124,7 @@ func Test_PartialHelper_With_InternalChange(t *testing.T) { %>
Hello <%= number %>
`, nil }) - html, err := partialHelper(name, data, help) + html, err := plush.PartialHelper(name, data, help) r.NoError(err) r.Equal(`
Hello 2
`, string(html)) r.Equal(3, help.Value("number")) @@ -134,7 +135,7 @@ func Test_PartialHelper_With_Recursion(t *testing.T) { name := "index" data := map[string]interface{}{} - help := HelperContext{Context: NewContextWith(map[string]interface{}{ + help := plush.HelperContext{Context: plush.NewContextWith(map[string]interface{}{ "number": 3, })} help.Set("partialFeeder", func(string) (string, error) { @@ -145,7 +146,7 @@ func Test_PartialHelper_With_Recursion(t *testing.T) { } %>`, nil }) - html, err := partialHelper(name, data, help) + html, err := plush.PartialHelper(name, data, help) r.NoError(err) r.Equal(`0, 1, 2, `, string(html)) r.Equal(3, help.Value("number")) @@ -156,12 +157,12 @@ func Test_PartialHelper_Render_Error(t *testing.T) { name := "index" data := map[string]interface{}{} - help := HelperContext{Context: NewContext()} + help := plush.HelperContext{Context: plush.NewContext()} help.Set("partialFeeder", func(string) (string, error) { return `
Hello <%= name
`, nil }) - _, err := partialHelper(name, data, help) + _, err := plush.PartialHelper(name, data, help) r.Error(err) } @@ -173,7 +174,7 @@ func Test_PartialHelper_With_Layout(t *testing.T) { "name": "Yonghwan", "layout": "container", } - help := HelperContext{Context: NewContext()} + help := plush.HelperContext{Context: plush.NewContext()} help.Set("partialFeeder", func(name string) (string, error) { if name == "container" { return `<%= yield %>`, nil @@ -181,7 +182,7 @@ func Test_PartialHelper_With_Layout(t *testing.T) { return `
Hello <%= name %>
`, nil }) - html, err := partialHelper(name, data, help) + html, err := plush.PartialHelper(name, data, help) r.NoError(err) r.Equal(`
Hello Yonghwan
`, string(html)) } @@ -191,13 +192,13 @@ func Test_PartialHelper_JavaScript(t *testing.T) { name := "index.js" data := map[string]interface{}{} - help := HelperContext{Context: NewContext()} + help := plush.HelperContext{Context: plush.NewContext()} help.Set("contentType", "application/javascript") help.Set("partialFeeder", func(string) (string, error) { return `alert('\'Hello\'');`, nil }) - html, err := partialHelper(name, data, help) + html, err := plush.PartialHelper(name, data, help) r.NoError(err) r.Equal(`alert('\'Hello\'');`, string(html)) } @@ -207,13 +208,13 @@ func Test_PartialHelper_JavaScript_Without_Extension(t *testing.T) { name := "index" data := map[string]interface{}{} - help := HelperContext{Context: NewContext()} + help := plush.HelperContext{Context: plush.NewContext()} help.Set("contentType", "application/javascript") help.Set("partialFeeder", func(string) (string, error) { return `alert('\'Hello\'');`, nil }) - html, err := partialHelper(name, data, help) + html, err := plush.PartialHelper(name, data, help) r.NoError(err) r.Equal(`alert('\'Hello\'');`, string(html)) } @@ -223,13 +224,13 @@ func Test_PartialHelper_Javascript_With_HTML(t *testing.T) { name := "index.html" data := map[string]interface{}{} - help := HelperContext{Context: NewContext()} + help := plush.HelperContext{Context: plush.NewContext()} help.Set("contentType", "application/javascript") help.Set("partialFeeder", func(string) (string, error) { return `alert('\'Hello\'');`, nil }) - html, err := partialHelper(name, data, help) + html, err := plush.PartialHelper(name, data, help) r.NoError(err) r.Equal(`alert(\'\\\'Hello\\\'\');`, string(html)) } @@ -239,7 +240,7 @@ func Test_PartialHelper_Javascript_With_HTML_Partial(t *testing.T) { r := require.New(t) data := map[string]interface{}{} - help := HelperContext{Context: NewContext()} + help := plush.HelperContext{Context: plush.NewContext()} help.Set("partialFeeder", func(name string) (string, error) { switch name { case "js_having_html_partial.js": @@ -258,7 +259,7 @@ func Test_PartialHelper_Javascript_With_HTML_Partial(t *testing.T) { }) // without content-type, js escaping is not applied - html, err := partialHelper("js_having_html_partial.js", data, help) + html, err := plush.PartialHelper("js_having_html_partial.js", data, help) r.NoError(err) r.Equal(`alert('
FORM
');`, string(html)) @@ -266,12 +267,12 @@ func Test_PartialHelper_Javascript_With_HTML_Partial(t *testing.T) { help.Set("contentType", "application/javascript") // and including partials with js extension - html, err = partialHelper("js_having_js_partial.js", data, help) + html, err = plush.PartialHelper("js_having_js_partial.js", data, help) r.NoError(err) r.Equal(`alert('
FORM
');`, string(html)) // has content-type but including html extension - html, err = partialHelper("js_having_html_partial.js", data, help) + html, err = plush.PartialHelper("js_having_html_partial.js", data, help) r.NoError(err) r.Equal(`alert('\u003Cdiv\u003E\\u003Cspan\\u003EFORM\\u003C/span\\u003E\u003C/div\u003E');`, string(html)) } @@ -281,13 +282,13 @@ func Test_PartialHelper_Markdown(t *testing.T) { name := "index.md" data := map[string]interface{}{} - help := HelperContext{Context: NewContext()} + help := plush.HelperContext{Context: plush.NewContext()} help.Set("contentType", "text/markdown") help.Set("partialFeeder", func(string) (string, error) { return "`test`", nil }) - md, err := partialHelper(name, data, help) + md, err := plush.PartialHelper(name, data, help) r.NoError(err) r.Equal(`

test

`, strings.TrimSpace(string(md))) } @@ -299,7 +300,7 @@ func Test_PartialHelper_Markdown_With_Layout(t *testing.T) { data := map[string]interface{}{ "layout": "container.html", } - help := HelperContext{Context: NewContext()} + help := plush.HelperContext{Context: plush.NewContext()} help.Set("partialFeeder", func(name string) (string, error) { if name == data["layout"] { return `This is a <%= yield %>`, nil @@ -307,7 +308,7 @@ func Test_PartialHelper_Markdown_With_Layout(t *testing.T) { return `**test**`, nil }) - html, err := partialHelper(name, data, help) + html, err := plush.PartialHelper(name, data, help) r.NoError(err) r.Equal("This is a

test

", string(html)) } @@ -319,7 +320,7 @@ func Test_PartialHelper_Markdown_With_Layout_Reversed(t *testing.T) { data := map[string]interface{}{ "layout": "container.md", } - help := HelperContext{Context: NewContext()} + help := plush.HelperContext{Context: plush.NewContext()} help.Set("partialFeeder", func(name string) (string, error) { if name == data["layout"] { return `This *is* a <%= yield %>`, nil @@ -327,7 +328,7 @@ func Test_PartialHelper_Markdown_With_Layout_Reversed(t *testing.T) { return `test`, nil }) - html, err := partialHelper(name, data, help) + html, err := plush.PartialHelper(name, data, help) r.NoError(err) r.Equal(`

This is a test

`, strings.TrimSpace(string(html))) } @@ -345,7 +346,7 @@ func Test_PartialHelpers_Markdown_With_Nested_CodeBlock(t *testing.T) { fmt.Println() }` + "\n```" - help := HelperContext{Context: NewContext()} + help := plush.HelperContext{Context: plush.NewContext()} help.Set("contentType", "text/markdown") help.Set("partialFeeder", func(name string) (string, error) { if name == "outer.md" { @@ -354,7 +355,7 @@ func Test_PartialHelpers_Markdown_With_Nested_CodeBlock(t *testing.T) { return inner, nil }) - html, err := Render(main, help) + html, err := plush.Render(main, help) r.NoError(err) r.Equal(`

Some text

@@ -378,12 +379,12 @@ func Test_PartialHelpers_With_Indentation(t *testing.T) { "}\n" + "```" - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("partialFeeder", func(string) (string, error) { return partial, nil }) - html, err := Render(main, ctx) + html, err := plush.Render(main, ctx) r.NoError(err) r.Equal(`
@@ -400,7 +401,7 @@ func Test_PartialHelper_NoDefaultHelperOverride(t *testing.T) { r := require.New(t) t.Run("Existing key", func(t *testing.T) { - help := HelperContext{Context: NewContextWith(map[string]interface{}{ + help := plush.HelperContext{Context: plush.NewContextWith(map[string]interface{}{ "truncate": func(s string, opts hctx.Map) string { return s }, @@ -410,19 +411,19 @@ func Test_PartialHelper_NoDefaultHelperOverride(t *testing.T) { return `<%= truncate("xxxxxxxxxxxaaaaaaaaaa", {size: 10}) %>`, nil }) - html, err := partialHelper("index", map[string]interface{}{}, help) + html, err := plush.PartialHelper("index", map[string]interface{}{}, help) r.NoError(err) r.Equal(`xxxxxxxxxxxaaaaaaaaaa`, string(html)) }) t.Run("Unexisting", func(t *testing.T) { - help := HelperContext{Context: NewContextWith(map[string]interface{}{})} + help := plush.HelperContext{Context: plush.NewContextWith(map[string]interface{}{})} help.Set("partialFeeder", func(string) (string, error) { return `<%= truncate("xxxxxxxxxxxaaaaaaaaaa", {size: 10}) %>`, nil }) - html, err := partialHelper("index", map[string]interface{}{}, help) + html, err := plush.PartialHelper("index", map[string]interface{}{}, help) r.NoError(err) r.Equal(`xxxxxxx...`, string(html)) }) diff --git a/plush.go b/plush.go index 6ae1047..0b1f164 100644 --- a/plush.go +++ b/plush.go @@ -26,6 +26,13 @@ var CacheEnabled bool var cache = map[string]*Template{} var moot = &sync.Mutex{} +func CacheSet(key string, t *Template) { + moot.Lock() + defer moot.Unlock() + + cache[key] = t +} + // BuffaloRenderer implements the render.TemplateEngine interface allowing velvet to be used as a template engine // for Buffalo func BuffaloRenderer(input string, data map[string]interface{}, helpers map[string]interface{}) (string, error) { diff --git a/plush_test.go b/plush_test.go index 5149d6f..363a930 100644 --- a/plush_test.go +++ b/plush_test.go @@ -1,8 +1,9 @@ -package plush +package plush_test import ( "testing" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) @@ -10,7 +11,7 @@ func Test_Render_Simple_HTML(t *testing.T) { r := require.New(t) input := `

Hi

` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal(input, s) } @@ -19,11 +20,11 @@ func Test_Render_Keeps_Spacing(t *testing.T) { r := require.New(t) input := `<%= greet %> <%= name %>` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("greet", "hi") ctx.Set("name", "mark") - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("hi mark", s) } @@ -32,7 +33,7 @@ func Test_Render_HTML_InjectedString(t *testing.T) { r := require.New(t) input := `

<%= "mark" %>

` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal("

mark

", s) } @@ -41,7 +42,7 @@ func Test_Render_Injected_Variable(t *testing.T) { r := require.New(t) input := `

<%= name %>

` - s, err := Render(input, NewContextWith(map[string]interface{}{ + s, err := plush.Render(input, plush.NewContextWith(map[string]interface{}{ "name": "Mark", })) r.NoError(err) @@ -52,14 +53,14 @@ func Test_Render_Missing_Variable(t *testing.T) { r := require.New(t) input := `

<%= name %>

` - _, err := Render(input, NewContext()) + _, err := plush.Render(input, plush.NewContext()) r.Error(err) } func Test_Render_ShowNoShow(t *testing.T) { r := require.New(t) input := `<%= "shown" %><% "notshown" %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal("shown", s) } @@ -69,15 +70,15 @@ func Test_Render_ScriptFunction(t *testing.T) { input := `<% let add = fn(x) { return x + 2; }; %><%= add(2) %>` - s, err := Render(input, NewContext()) + s, err := plush.Render(input, plush.NewContext()) r.NoError(err) r.Equal("4", s) } func Test_Render_HasBlock(t *testing.T) { r := require.New(t) - ctx := NewContext() - ctx.Set("blockCheck", func(help HelperContext) string { + ctx := plush.NewContext() + ctx.Set("blockCheck", func(help plush.HelperContext) string { if help.HasBlock() { s, _ := help.Block() return s @@ -85,19 +86,19 @@ func Test_Render_HasBlock(t *testing.T) { return "no block" }) input := `<%= blockCheck() {return "block"} %>|<%= blockCheck() %>` - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("block|no block", s) } func Test_Render_Dash_in_Helper(t *testing.T) { r := require.New(t) - ctx := NewContextWith(map[string]interface{}{ + ctx := plush.NewContextWith(map[string]interface{}{ "my-helper": func() string { return "hello" }, }) - s, err := Render(`<%= my-helper() %>`, ctx) + s, err := plush.Render(`<%= my-helper() %>`, ctx) r.NoError(err) r.Equal("hello", s) } @@ -113,7 +114,7 @@ func Test_BuffaloRenderer(t *testing.T) { return "George" }, } - s, err := BuffaloRenderer(input, data, helpers) + s, err := plush.BuffaloRenderer(input, data, helpers) r.NoError(err) r.Equal("GeorgeRingo", s) } @@ -121,7 +122,7 @@ func Test_BuffaloRenderer(t *testing.T) { func Test_Helper_Nil_Arg(t *testing.T) { r := require.New(t) input := `<%= foo(nil, "k") %><%= foo(one, "k") %>` - ctx := NewContextWith(map[string]interface{}{ + ctx := plush.NewContextWith(map[string]interface{}{ "one": map[string]string{ "k": "test", }, @@ -132,7 +133,7 @@ func Test_Helper_Nil_Arg(t *testing.T) { return "" }, }) - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("test", s) } @@ -140,10 +141,10 @@ func Test_Helper_Nil_Arg(t *testing.T) { func Test_UndefinedArg(t *testing.T) { r := require.New(t) input := `<%= foo(bar) %>` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("foo", func(string) {}) - _, err := Render(input, ctx) + _, err := plush.Render(input, ctx) r.Error(err) r.Equal(`line 1: "bar": unknown identifier`, err.Error()) } @@ -151,18 +152,18 @@ func Test_UndefinedArg(t *testing.T) { func Test_Caching(t *testing.T) { r := require.New(t) - template, err := NewTemplate("<%= \"AA\" %>") + template, err := plush.NewTemplate("<%= \"AA\" %>") r.NoError(err) - cache["<%= a %>"] = template - CacheEnabled = true + plush.CacheSet("<%= a %>", template) + plush.CacheEnabled = true - tc, err := Parse("<%= a %>") + tc, err := plush.Parse("<%= a %>") r.NoError(err) r.Equal(tc, template) - CacheEnabled = false - tc, err = Parse("<%= a %>") + plush.CacheEnabled = false + tc, err = plush.Parse("<%= a %>") r.NoError(err) r.NotEqual(tc, template) } diff --git a/quotes_test.go b/quotes_test.go index c0b6679..80a9440 100644 --- a/quotes_test.go +++ b/quotes_test.go @@ -1,8 +1,9 @@ -package plush +package plush_test import ( "testing" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) @@ -19,9 +20,9 @@ func Test_Quote_Missing(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { r := require.New(t) - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("foo", func(string) {}) - _, err := Render(tc.input, ctx) + _, err := plush.Render(tc.input, ctx) r.Error(err) }) } diff --git a/return_exit_test.go b/return_exit_test.go index 6306b5b..7f48a23 100644 --- a/return_exit_test.go +++ b/return_exit_test.go @@ -1,9 +1,10 @@ -package plush +package plush_test import ( "strings" "testing" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) @@ -61,7 +62,7 @@ func Test_Return_Exit_With__InfixExpression(t *testing.T) { t.Run(tc.name, func(t *testing.T) { r := require.New(t) - s, err := Render(tc.input, NewContext()) + s, err := plush.Render(tc.input, plush.NewContext()) if tc.success { r.NoError(err) } else { @@ -74,7 +75,7 @@ func Test_Return_Exit_With__InfixExpression(t *testing.T) { func Test_User_Function_Return(t *testing.T) { r := require.New(t) - ctx := NewContext() + ctx := plush.NewContext() in := `<% let print = fn(obj) { if (obj.Secret) { @@ -94,17 +95,17 @@ func Test_User_Function_Return(t *testing.T) { } ctx.Set("data", obj{Secret: true, String: "your royal highness"}) - out, err := Render(in, ctx) + out, err := plush.Render(in, ctx) r.NoError(err, "Render") r.Equal(`You are: **********.`, out) ctx.Set("data", obj{Secret: true, GiveHint: true, String: "your royal highness"}) - out, err = Render(in, ctx) + out, err = plush.Render(in, ctx) r.NoError(err, "Render") r.Equal(`You are: your roy****.`, out) ctx.Set("data", obj{Secret: false, String: "your royal highness"}) - out, err = Render(in, ctx) + out, err = plush.Render(in, ctx) r.NoError(err, "Render") r.Equal(`You are: your royal highness.`, out) } diff --git a/script_test.go b/script_test.go index 9db8661..96cbdad 100644 --- a/script_test.go +++ b/script_test.go @@ -1,22 +1,23 @@ -package plush +package plush_test import ( "bytes" "fmt" "testing" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) func Test_RunScript(t *testing.T) { r := require.New(t) bb := &bytes.Buffer{} - ctx := NewContextWith(map[string]interface{}{ + ctx := plush.NewContextWith(map[string]interface{}{ "out": func(i interface{}) { bb.WriteString(fmt.Sprint(i)) }, }) - err := RunScript(script, ctx) + err := plush.RunScript(script, ctx) r.NoError(err) r.Equal("3hiasdfasdf", bb.String()) } diff --git a/struct_test.go b/struct_test.go index e6dd7ee..b29e207 100644 --- a/struct_test.go +++ b/struct_test.go @@ -1,31 +1,32 @@ -package plush +package plush_test import ( "strings" "testing" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) func Test_Render_Struct_Attribute(t *testing.T) { r := require.New(t) input := `<%= f.Name %>` - ctx := NewContext() + ctx := plush.NewContext() f := struct { Name string }{"Mark"} ctx.Set("f", f) - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("Mark", s) } func Test_Render_UnknownAttribute_on_Callee(t *testing.T) { r := require.New(t) - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("m", struct{}{}) input := `<%= m.Foo %>` - _, err := Render(input, ctx) + _, err := plush.Render(input, ctx) r.Error(err) r.Contains(err.Error(), "'m' does not have a field or method named 'Foo' (m.Foo)") } @@ -47,33 +48,33 @@ func (r *Robot) Name() string { func Test_Render_Function_on_sub_Struct(t *testing.T) { r := require.New(t) - ctx := NewContext() + ctx := plush.NewContext() bender := Robot{ Avatar: Avatar("bender.jpg"), } ctx.Set("robot", bender) input := `<%= robot.Avatar.URL() %>` - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("BENDER.JPG", s) } func Test_Render_Struct_PointerMethod(t *testing.T) { r := require.New(t) - ctx := NewContext() + ctx := plush.NewContext() robot := Robot{name: "robot"} t.Run("ByValue", func(t *testing.T) { ctx.Set("robot", robot) input := `<%= robot.Name() %>` - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("robot", s) }) t.Run("ByPointer", func(t *testing.T) { ctx.Set("robot", &robot) input := `<%= robot.Name() %>` - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("robot", s) }) @@ -106,8 +107,8 @@ func Test_Render_Struct_PointerMethod_IsNil(t *testing.T) { } for p := first; p != nil; p = p.Next { - ctx := NewContextWith(map[string]interface{}{"p": p}) - res, err := Render(input, ctx) + ctx := plush.NewContextWith(map[string]interface{}{"p": p}) + res, err := plush.Render(input, ctx) r.NoError(err) r.Equal(resE[p.N], res) @@ -126,11 +127,11 @@ func Test_Render_Struct_PointerValue_Nil(t *testing.T) { Name: "Garn Clapstick", Image: nil, } - ctx := NewContextWith(map[string]interface{}{ + ctx := plush.NewContextWith(map[string]interface{}{ "user": u, }) input := `<%= user.Name %>: <%= user.Image %>` - res, err := Render(input, ctx) + res, err := plush.Render(input, ctx) r.NoError(err) r.Equal(`Garn Clapstick: `, res) @@ -149,11 +150,11 @@ func Test_Render_Struct_PointerValue_NonNil(t *testing.T) { Name: "Scrinch Archipeligo", Image: &image, } - ctx := NewContextWith(map[string]interface{}{ + ctx := plush.NewContextWith(map[string]interface{}{ "user": u, }) input := `<%= user.Name %>: <%= user.Image %>` - res, err := Render(input, ctx) + res, err := plush.Render(input, ctx) r.NoError(err) r.Equal(`Scrinch Archipeligo: bicep.png`, res) @@ -171,9 +172,9 @@ func Test_Render_Struct_Multiple_Access(t *testing.T) { gg := make([]mylist, 3) gg[0].Name = "John" gg[1].Name = "Doe" - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("myarray", gg) - res, err := Render(input, ctx) + res, err := plush.Render(input, ctx) r.NoError(err) r.Equal("John Doe", res) @@ -193,9 +194,9 @@ func Test_Render_Nested_Structs_Start_With_Slice(t *testing.T) { gg := make([]mylist, 3) gg[0].Name.Final = "Hello World" - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("myarray", gg) - res, err := Render(input, ctx) + res, err := plush.Render(input, ctx) r.NoError(err) r.Equal("Hello World", res) @@ -214,16 +215,16 @@ func Test_Render_Nested_Structs_Start_With_Slice_End_With_Slice(t *testing.T) { gg := make([]mylist, 3) gg[0].Name = b{[]string{"Hello World"}} - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("myarray", gg) - res, err := Render(input, ctx) + res, err := plush.Render(input, ctx) r.NoError(err) r.Equal("Hello World", res) } func Test_Render_Nested_Structs_Ends_With_Slice(t *testing.T) { r := require.New(t) - ctx := NewContext() + ctx := plush.NewContext() type c struct { Final []string @@ -245,14 +246,14 @@ func Test_Render_Nested_Structs_Ends_With_Slice(t *testing.T) { } ctx.Set("robot", bender) input := `<%= robot.Name.B.Final[0] %>` - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("bendser.jpg", s) } func Test_Render_Nested_Structs(t *testing.T) { r := require.New(t) - ctx := NewContext() + ctx := plush.NewContext() type c struct { Final string @@ -274,13 +275,13 @@ func Test_Render_Nested_Structs(t *testing.T) { } ctx.Set("robot", bender) input := `<%= robot.Name.B.Final %>` - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("bendser.jpg", s) } func Test_Render_Struct_Access_Slice_Field(t *testing.T) { r := require.New(t) - ctx := NewContext() + ctx := plush.NewContext() type D struct { Final string } @@ -306,7 +307,7 @@ func Test_Render_Struct_Access_Slice_Field(t *testing.T) { } ctx.Set("robot", bender) input := `<%= robot.Name.B.Final[0].Final %>` - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("String", s) } @@ -338,9 +339,9 @@ func Test_Render_Struct_Nested_Slice_Access(t *testing.T) { bc.A[1] = ca gg[0].Name = []b{bc} - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("myarray", gg) - res, err := Render(input, ctx) + res, err := plush.Render(input, ctx) r.NoError(err) r.Equal("Hello World", res) @@ -373,9 +374,9 @@ func Test_Render_Struct_Nested_Map_Slice_Access(t *testing.T) { bc.A[1] = ca gg[0].Name = []b{bc} - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("myarray", gg) - res, err := Render(input, ctx) + res, err := plush.Render(input, ctx) r.NoError(err) r.Equal("Hello World", res) @@ -406,9 +407,9 @@ func Test_Render_Struct_Nested_With_Unexported_Fields(t *testing.T) { departments["HR"] = employees input := `<%= departments["HR"].employee[0].FirstName %>` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("departments", departments) - _, err := Render(input, ctx) + _, err := plush.Render(input, ctx) r.Error(err) //r.Equal("John", res) @@ -439,24 +440,24 @@ func Test_Render_Struct_Nested_Map_Access(t *testing.T) { departments["HR"] = employees input := `<%= departments["HR"].Employee[0].FirstName %> <%= departments["HR"].Employee[0].LastName %>` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("departments", departments) - res, err := Render(input, ctx) + res, err := plush.Render(input, ctx) r.NoError(err) r.Equal("John Doe", res) input = `<%= departments["HR"].Employee[1].FirstName %> <%= departments["HR"].Employee[1].LastName %>` - res, err = Render(input, ctx) + res, err = plush.Render(input, ctx) r.NoError(err) r.Equal("Jane Dolittle", res) input = `<%= departments["HR"].Employee[1].FirstName %> <%= departments["HR"].Employee[0].LastName %>` - res, err = Render(input, ctx) + res, err = plush.Render(input, ctx) r.NoError(err) r.Equal("Jane Doe", res) input = `<%= departments["HR"].Employee[0].FirstName %> <%= departments["HR"].Employee[1].LastName %>` - res, err = Render(input, ctx) + res, err = plush.Render(input, ctx) r.NoError(err) r.Equal("John Dolittle", res) } diff --git a/template_test.go b/template_test.go index f4a6970..647d61a 100644 --- a/template_test.go +++ b/template_test.go @@ -1,19 +1,20 @@ -package plush +package plush_test import ( "testing" "golang.org/x/sync/errgroup" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) func Test_Template_Exec_Concurrency(t *testing.T) { r := require.New(t) - tmpl, err := NewTemplate(``) + tmpl, err := plush.NewTemplate(``) r.NoError(err) exec := func() error { - _, e := tmpl.Exec(NewContext()) + _, e := tmpl.Exec(plush.NewContext()) return e } wg := errgroup.Group{} diff --git a/time_test.go b/time_test.go index 0c9d56d..1ab0b63 100644 --- a/time_test.go +++ b/time_test.go @@ -1,9 +1,10 @@ -package plush +package plush_test import ( "testing" "time" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) @@ -13,22 +14,22 @@ func Test_Default_Time_Format(t *testing.T) { shortForm := "2006-Jan-02" tm, err := time.Parse(shortForm, "2013-Feb-03") r.NoError(err) - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("tm", tm) input := `<%= tm %>` - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("February 03, 2013 00:00:00 +0000", s) ctx.Set("TIME_FORMAT", "2006-02-Jan") - s, err = Render(input, ctx) + s, err = plush.Render(input, ctx) r.NoError(err) r.Equal("2013-03-Feb", s) ctx.Set("tm", &tm) - s, err = Render(input, ctx) + s, err = plush.Render(input, ctx) r.NoError(err) r.Equal("2013-03-Feb", s) } diff --git a/variables_test.go b/variables_test.go index 8eff281..7aed31d 100644 --- a/variables_test.go +++ b/variables_test.go @@ -1,10 +1,11 @@ -package plush +package plush_test import ( "html/template" "strings" "testing" + "github.com/gobuffalo/plush/v4" "github.com/gobuffalo/tags/v3" "github.com/stretchr/testify/require" ) @@ -20,10 +21,10 @@ func Test_Let_Reassignment(t *testing.T) { <% } %> <% } %>` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("myArray", []string{"a", "b"}) - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("bar\n \n \nbaz", strings.TrimSpace(s)) } @@ -32,9 +33,9 @@ func Test_Let_SyntaxError_NoEqualSign(t *testing.T) { r := require.New(t) input := `<% let foo %>` - ctx := NewContext() + ctx := plush.NewContext() - _, err := Render(input, ctx) + _, err := plush.Render(input, ctx) r.ErrorContains(err, "expected next token to be =") } @@ -42,9 +43,9 @@ func Test_Let_SyntaxError_NoIdentifier(t *testing.T) { r := require.New(t) input := `<% let = %>` - ctx := NewContext() + ctx := plush.NewContext() - _, err := Render(input, ctx) + _, err := plush.Render(input, ctx) r.ErrorContains(err, "expected next token to be IDENT") } @@ -52,17 +53,17 @@ func Test_Let_Reassignment_UnknownIdent(t *testing.T) { r := require.New(t) input := `<% foo = "baz" %>` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("myArray", []string{"a", "b"}) - _, err := Render(input, ctx) + _, err := plush.Render(input, ctx) r.ErrorContains(err, "\"foo\": unknown identifier") } func Test_Let_Inside_Helper(t *testing.T) { r := require.New(t) - ctx := NewContextWith(map[string]interface{}{ - "divwrapper": func(opts map[string]interface{}, helper HelperContext) (template.HTML, error) { + ctx := plush.NewContextWith(map[string]interface{}{ + "divwrapper": func(opts map[string]interface{}, helper plush.HelperContext) (template.HTML, error) { body, err := helper.Block() if err != nil { return template.HTML(""), err @@ -82,7 +83,7 @@ func Test_Let_Inside_Helper(t *testing.T) { <% } %>` - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Contains(s, "
  • 0 - 1
  • ") r.Contains(s, "
  • 1 - 2
  • ") @@ -106,7 +107,7 @@ func Test_Render_Let_Hash(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { r := require.New(t) - s, err := Render(tc.input, NewContext()) + s, err := plush.Render(tc.input, plush.NewContext()) if tc.success { r.NoError(err) } else { @@ -133,7 +134,7 @@ func Test_Render_Let_Array(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { r := require.New(t) - s, err := Render(tc.input, NewContext()) + s, err := plush.Render(tc.input, plush.NewContext()) if tc.success { r.NoError(err) } else { @@ -171,10 +172,10 @@ func Test_Render_Access_CalleeArray(t *testing.T) { r := require.New(t) input := `<% let a = product_listing.Products[0].Name[0] %><%= a %>` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("product_listing", tc.data) - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) if tc.success { r.NoError(err) } else { diff --git a/variadic_test.go b/variadic_test.go index a3b1794..2bc8ff5 100644 --- a/variadic_test.go +++ b/variadic_test.go @@ -1,20 +1,21 @@ -package plush +package plush_test import ( "testing" + "github.com/gobuffalo/plush/v4" "github.com/stretchr/testify/require" ) func Test_VariadicHelper(t *testing.T) { r := require.New(t) input := `<%= foo(1, 2, 3) %>` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("foo", func(args ...int) int { return len(args) }) - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("3", s) } @@ -22,12 +23,12 @@ func Test_VariadicHelper(t *testing.T) { func Test_VariadicHelper_SecondArg(t *testing.T) { r := require.New(t) input := `<%= foo("hello") %>` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("foo", func(s string, args ...interface{}) string { return s }) - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("hello", s) } @@ -35,12 +36,12 @@ func Test_VariadicHelper_SecondArg(t *testing.T) { func Test_VariadicHelperNoParam(t *testing.T) { r := require.New(t) input := `<%= foo() %>` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("foo", func(args ...int) int { return len(args) }) - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("0", s) } @@ -48,12 +49,12 @@ func Test_VariadicHelperNoParam(t *testing.T) { func Test_VariadicHelperNoVariadicParam(t *testing.T) { r := require.New(t) input := `<%= foo(1) %>` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("foo", func(a int, args ...int) int { return a + len(args) }) - s, err := Render(input, ctx) + s, err := plush.Render(input, ctx) r.NoError(err) r.Equal("1", s) } @@ -61,12 +62,12 @@ func Test_VariadicHelperNoVariadicParam(t *testing.T) { func Test_VariadicHelperWithWrongParam(t *testing.T) { r := require.New(t) input := `<%= foo(1, 2, "test") %>` - ctx := NewContext() + ctx := plush.NewContext() ctx.Set("foo", func(args ...int) int { return len(args) }) - _, err := Render(input, ctx) + _, err := plush.Render(input, ctx) r.Error(err) r.Contains(err.Error(), "test (string) is an invalid argument for foo at pos 2: expected (int)") } From 5f41b53dc3aa4553587c2e7f6a141f10ebe5c8bc Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Tue, 25 Jul 2023 14:39:40 -0500 Subject: [PATCH 2/3] task: updating some dependencies --- go.sum | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/go.sum b/go.sum index d9ab157..5fc30fa 100644 --- a/go.sum +++ b/go.sum @@ -9,6 +9,8 @@ github.com/gobuffalo/flect v0.3.0 h1:erfPWM+K1rFNIQeRPdeEXxo8yFr/PO17lhRnS8FUrtk github.com/gobuffalo/flect v0.3.0/go.mod h1:5pf3aGnsvqvCj50AVni7mJJF8ICxGZ8HomberC3pXLE= github.com/gobuffalo/github_flavored_markdown v1.1.3 h1:rSMPtx9ePkFB22vJ+dH+m/EUBS8doQ3S8LeEXcdwZHk= github.com/gobuffalo/github_flavored_markdown v1.1.3/go.mod h1:IzgO5xS6hqkDmUh91BW/+Qxo/qYnvfzoz3A7uLkg77I= +github.com/gobuffalo/github_flavored_markdown v1.1.4 h1:WacrEGPXUDX+BpU1GM/Y0ADgMzESKNWls9hOTG1MHVs= +github.com/gobuffalo/github_flavored_markdown v1.1.4/go.mod h1:Vl9686qrVVQou4GrHRK/KOG3jCZOKLUqV8MMOAYtlso= github.com/gobuffalo/helpers v0.6.7 h1:C9CedoRSfgWg2ZoIkVXgjI5kgmSpL34Z3qdnzpfNVd8= github.com/gobuffalo/helpers v0.6.7/go.mod h1:j0u1iC1VqlCaJEEVkZN8Ia3TEzfj/zoXANqyJExTMTA= github.com/gobuffalo/tags/v3 v3.1.4 h1:X/ydLLPhgXV4h04Hp2xlbI2oc5MDaa7eub6zw8oHjsM= @@ -26,32 +28,65 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/microcosm-cc/bluemonday v1.0.20 h1:flpzsq4KU3QIYAYGV/szUat7H+GPOXR0B2JU5A1Wp8Y= github.com/microcosm-cc/bluemonday v1.0.20/go.mod h1:yfBmMi8mxvaZut3Yytv+jTXRY8mxyjJ0/kQBTElld50= +github.com/microcosm-cc/bluemonday v1.0.22 h1:p2tT7RNzRdCi0qmwxG+HbqD6ILkmwter1ZwVZn1oTxA= +github.com/microcosm-cc/bluemonday v1.0.22/go.mod h1:ytNkv4RrDrLJ2pqlsSI46O6IVXmZOBBD4SaJyDwwTkM= 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/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= +github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= +github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d h1:yKm7XZV6j9Ev6lojP2XaIshpT4ymkqhMeSghO5Ps00E= github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE= github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e h1:qpG93cPwA5f7s/ZPBJnGOYQNK/vKsaDaseuKT5Asee8= github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +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/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.0.0-20221002022538-bcab6841153b h1:6e93nYa3hNqAvLr0pD4PN1fFS+gKzp2zAXqrnTCstqU= golang.org/x/net v0.0.0-20221002022538-bcab6841153b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= +golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 7381a86d056f9012ef46e2632f8fffc643e64cbe Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Tue, 25 Jul 2023 14:40:08 -0500 Subject: [PATCH 3/3] task: updating dependencies --- go.mod | 6 +++--- go.sum | 9 --------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 3c206de..d6bf27b 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module github.com/gobuffalo/plush/v4 go 1.16 require ( - github.com/gobuffalo/github_flavored_markdown v1.1.3 + github.com/gobuffalo/github_flavored_markdown v1.1.4 github.com/gobuffalo/helpers v0.6.7 github.com/gobuffalo/tags/v3 v3.1.4 - github.com/stretchr/testify v1.8.1 - golang.org/x/sync v0.1.0 + github.com/stretchr/testify v1.8.4 + golang.org/x/sync v0.3.0 ) diff --git a/go.sum b/go.sum index 5fc30fa..a04042b 100644 --- a/go.sum +++ b/go.sum @@ -7,7 +7,6 @@ github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/gobuffalo/flect v0.3.0 h1:erfPWM+K1rFNIQeRPdeEXxo8yFr/PO17lhRnS8FUrtk= github.com/gobuffalo/flect v0.3.0/go.mod h1:5pf3aGnsvqvCj50AVni7mJJF8ICxGZ8HomberC3pXLE= -github.com/gobuffalo/github_flavored_markdown v1.1.3 h1:rSMPtx9ePkFB22vJ+dH+m/EUBS8doQ3S8LeEXcdwZHk= github.com/gobuffalo/github_flavored_markdown v1.1.3/go.mod h1:IzgO5xS6hqkDmUh91BW/+Qxo/qYnvfzoz3A7uLkg77I= github.com/gobuffalo/github_flavored_markdown v1.1.4 h1:WacrEGPXUDX+BpU1GM/Y0ADgMzESKNWls9hOTG1MHVs= github.com/gobuffalo/github_flavored_markdown v1.1.4/go.mod h1:Vl9686qrVVQou4GrHRK/KOG3jCZOKLUqV8MMOAYtlso= @@ -26,13 +25,11 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/microcosm-cc/bluemonday v1.0.20 h1:flpzsq4KU3QIYAYGV/szUat7H+GPOXR0B2JU5A1Wp8Y= github.com/microcosm-cc/bluemonday v1.0.20/go.mod h1:yfBmMi8mxvaZut3Yytv+jTXRY8mxyjJ0/kQBTElld50= github.com/microcosm-cc/bluemonday v1.0.22 h1:p2tT7RNzRdCi0qmwxG+HbqD6ILkmwter1ZwVZn1oTxA= github.com/microcosm-cc/bluemonday v1.0.22/go.mod h1:ytNkv4RrDrLJ2pqlsSI46O6IVXmZOBBD4SaJyDwwTkM= 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/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= @@ -42,13 +39,10 @@ github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e h1:qpG github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= 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/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= @@ -59,14 +53,11 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= -golang.org/x/net v0.0.0-20221002022538-bcab6841153b h1:6e93nYa3hNqAvLr0pD4PN1fFS+gKzp2zAXqrnTCstqU= golang.org/x/net v0.0.0-20221002022538-bcab6841153b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=