Skip to content

Commit

Permalink
Modernize
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Oct 17, 2024
1 parent 69a6f0e commit b50ab45
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 16 deletions.
3 changes: 1 addition & 2 deletions render/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package render
import (
"bytes"
"io"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -147,7 +146,7 @@ func (c rendererContext) RenderChildren(w io.Writer) Error {
}

func (c rendererContext) RenderFile(filename string, b map[string]interface{}) (string, error) {
source, err := ioutil.ReadFile(filename)
source, err := os.ReadFile(filename)
if err != nil && os.IsNotExist(err) {
// Is it cached?
if cval, ok := c.ctx.config.Cache[filename]; ok {
Expand Down
5 changes: 2 additions & 3 deletions render/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -123,7 +122,7 @@ func TestContext_errors(t *testing.T) {
t.Run(fmt.Sprintf("%02d", i+1), func(t *testing.T) {
root, err := cfg.Compile(test.in, parser.SourceLoc{})
require.NoErrorf(t, err, test.in)
err = Render(root, ioutil.Discard, contextTestBindings, cfg)
err = Render(root, io.Discard, contextTestBindings, cfg)
require.Errorf(t, err, test.in)
require.Containsf(t, err.Error(), test.expect, test.in)
})
Expand All @@ -140,7 +139,7 @@ func TestContext_file_not_found_error(t *testing.T) {
addContextTestTags(cfg)
root, err := cfg.Compile(`{% test_render_file testdata/missing_file %}`, parser.SourceLoc{})
require.NoError(t, err)
err = Render(root, ioutil.Discard, contextTestBindings, cfg)
err = Render(root, io.Discard, contextTestBindings, cfg)
require.Error(t, err)
require.True(t, os.IsNotExist(err.Cause()))
}
3 changes: 1 addition & 2 deletions render/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"testing"
"time"

Expand Down Expand Up @@ -121,7 +120,7 @@ func TestRenderErrors(t *testing.T) {
t.Run(fmt.Sprintf("%02d", i+1), func(t *testing.T) {
root, err := cfg.Compile(test.in, parser.SourceLoc{})
require.NoErrorf(t, err, test.in)
err = Render(root, ioutil.Discard, renderTestBindings, cfg)
err = Render(root, io.Discard, renderTestBindings, cfg)
require.Errorf(t, err, test.in)
require.Containsf(t, err.Error(), test.out, test.in)
})
Expand Down
3 changes: 1 addition & 2 deletions tags/control_flow_tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"testing"

"github.com/osteele/liquid/parser"
Expand Down Expand Up @@ -94,7 +93,7 @@ func TestControlFlowTags_errors(t *testing.T) {
t.Run(fmt.Sprintf("%02d", i+1), func(t *testing.T) {
root, err := cfg.Compile(test.in, parser.SourceLoc{})
require.NoErrorf(t, err, test.in)
err = render.Render(root, ioutil.Discard, tagTestBindings, cfg)
err = render.Render(root, io.Discard, tagTestBindings, cfg)
require.Errorf(t, err, test.in)
require.Contains(t, err.Error(), test.expected, test.in)
})
Expand Down
6 changes: 3 additions & 3 deletions tags/include_tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package tags

import (
"bytes"
"io/ioutil"
"io"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -41,7 +41,7 @@ func TestIncludeTag(t *testing.T) {
// errors
root, err = config.Compile(`{% include 10 %}`, loc)
require.NoError(t, err)
err = render.Render(root, ioutil.Discard, includeTestBindings, config)
err = render.Render(root, io.Discard, includeTestBindings, config)
require.Error(t, err)
require.Contains(t, err.Error(), "requires a string")
}
Expand All @@ -54,7 +54,7 @@ func TestIncludeTag_file_not_found_error(t *testing.T) {
// See the comment in TestIncludeTag_file_not_found_error.
root, err := config.Compile(`{% include "missing_file.html" %}`, loc)
require.NoError(t, err)
err = render.Render(root, ioutil.Discard, includeTestBindings, config)
err = render.Render(root, io.Discard, includeTestBindings, config)
require.Error(t, err)
require.True(t, os.IsNotExist(err.Cause()))
}
Expand Down
4 changes: 2 additions & 2 deletions tags/iteration_tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tags
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"regexp"
"strings"
"testing"
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestIterationTags_errors(t *testing.T) {
t.Run(fmt.Sprintf("%02d", i+1+len(iterationSyntaxErrorTests)), func(t *testing.T) {
root, err := cfg.Compile(test.in, parser.SourceLoc{})
require.NoErrorf(t, err, test.in)
err = render.Render(root, ioutil.Discard, iterationTestBindings, cfg)
err = render.Render(root, io.Discard, iterationTestBindings, cfg)
require.Errorf(t, err, test.in)
require.Containsf(t, err.Error(), test.expected, test.in)
})
Expand Down
4 changes: 2 additions & 2 deletions tags/standard_tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tags
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"testing"

"github.com/osteele/liquid/parser"
Expand Down Expand Up @@ -101,7 +101,7 @@ func TestStandardTags_render_errors(t *testing.T) {
t.Run(fmt.Sprintf("%02d", i+1), func(t *testing.T) {
root, err := config.Compile(test.in, parser.SourceLoc{})
require.NoErrorf(t, err, test.in)
err = render.Render(root, ioutil.Discard, tagTestBindings, config)
err = render.Render(root, io.Discard, tagTestBindings, config)
require.Errorf(t, err, test.in)
require.Containsf(t, err.Error(), test.expected, test.in)
})
Expand Down

0 comments on commit b50ab45

Please sign in to comment.