diff --git a/helpers_test.go b/helpers_test.go index a814137..398e2bf 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -3,20 +3,20 @@ package main import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestSlugify(t *testing.T) { - assert.Equal(t, "abc", Slugify("abc")) - assert.Equal(t, "ab-c", Slugify("ab.c")) - assert.Equal(t, "ab-c", Slugify("ab-c")) - assert.Equal(t, "ab-c", Slugify("ab()[]c")) - assert.Equal(t, "ab123-cde-f-g", Slugify("ab123(cde)[]f.g")) + require.Equal(t, "abc", Slugify("abc")) + require.Equal(t, "ab-c", Slugify("ab.c")) + require.Equal(t, "ab-c", Slugify("ab-c")) + require.Equal(t, "ab-c", Slugify("ab()[]c")) + require.Equal(t, "ab123-cde-f-g", Slugify("ab123(cde)[]f.g")) } func TestLeftPad(t *testing.T) { - assert.Equal(t, "abc", LeftPad("abc", 0)) - assert.Equal(t, "abc", LeftPad("abc", 3)) - assert.Equal(t, " abc", LeftPad("abc", 6)) + require.Equal(t, "abc", LeftPad("abc", 0)) + require.Equal(t, "abc", LeftPad("abc", 3)) + require.Equal(t, " abc", LeftPad("abc", 6)) } func TestGetXXX(t *testing.T) { @@ -25,18 +25,18 @@ func TestGetXXX(t *testing.T) { "f": false, "s": "ss", } - assert.Equal(t, true, d.Bool("t", true)) - assert.Equal(t, true, d.Bool("t", false)) - assert.Equal(t, false, d.Bool("f", true)) - assert.Equal(t, false, d.Bool("f", true)) - assert.Equal(t, true, d.Bool("-", true)) - assert.Equal(t, false, d.Bool("-", false)) - assert.Equal(t, true, d.Bool("s", true)) - assert.Equal(t, false, d.Bool("s", false)) + require.Equal(t, true, d.Bool("t", true)) + require.Equal(t, true, d.Bool("t", false)) + require.Equal(t, false, d.Bool("f", true)) + require.Equal(t, false, d.Bool("f", true)) + require.Equal(t, true, d.Bool("-", true)) + require.Equal(t, false, d.Bool("-", false)) + require.Equal(t, true, d.Bool("s", true)) + require.Equal(t, false, d.Bool("s", false)) - assert.Equal(t, "ss", d.String("s", "-")) - assert.Equal(t, "--", d.String("-", "--")) - assert.Equal(t, "--", d.String("t", "--")) + require.Equal(t, "ss", d.String("s", "-")) + require.Equal(t, "--", d.String("-", "--")) + require.Equal(t, "--", d.String("t", "--")) } func TestMergeVariableMaps(t *testing.T) { @@ -44,12 +44,12 @@ func TestMergeVariableMaps(t *testing.T) { m2 := VariableMap{"b": 3, "c": 4} expected := VariableMap{"a": 1, "b": 3, "c": 4} actual := MergeVariableMaps(m1, m2) - assert.Equal(t, expected, actual) + require.Equal(t, expected, actual) } func TestStringArrayToMap(t *testing.T) { input := []string{"a", "b", "c"} expected := map[string]bool{"a": true, "b": true, "c": true} actual := stringArrayToMap(input) - assert.Equal(t, expected, actual) + require.Equal(t, expected, actual) } diff --git a/liquid_filters_test.go b/liquid_filters_test.go index 6c499f8..986c334 100644 --- a/liquid_filters_test.go +++ b/liquid_filters_test.go @@ -7,27 +7,22 @@ import ( "time" "github.com/acstech/liquid" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) -func assertTemplateRender(t *testing.T, tmpl string, data VariableMap, expected string) { +func requireTemplateRender(t *testing.T, tmpl string, data VariableMap, expected string) { template, err := liquid.ParseString(tmpl, nil) - if err != nil { - t.Fatalf(err.Error()) - return - } + require.NoError(t, err) writer := new(bytes.Buffer) template.Render(writer, data) - assert.Equal(t, expected, strings.TrimSpace(writer.String())) + require.Equal(t, expected, strings.TrimSpace(writer.String())) } func TestDateToRFC822Filter(t *testing.T) { t0, err := time.Parse(time.RFC3339, "2006-01-02T15:04:05Z") - if err != nil { - panic(err) - } + require.NoError(t, err) data := VariableMap{"time": t0} - assertTemplateRender(t, `{{time | date_to_rfc822 }}`, data, "02 Jan 06 15:04 UTC") + requireTemplateRender(t, `{{time | date_to_rfc822 }}`, data, "02 Jan 06 15:04 UTC") } func TestJsonifyFilter(t *testing.T) { @@ -36,7 +31,7 @@ func TestJsonifyFilter(t *testing.T) { "a": []int{1, 2, 3, 4}, }, } - assertTemplateRender(t, `{{obj | jsonify }}`, data, `{"a":[1,2,3,4]}`) + requireTemplateRender(t, `{{obj | jsonify }}`, data, `{"a":[1,2,3,4]}`) } // func TestXMLEscapeFilter(t *testing.T) { @@ -45,7 +40,7 @@ func TestJsonifyFilter(t *testing.T) { // "a": []int{1, 2, 3, 4}, // }, // } -// assertTemplateRender(t, `{{obj | xml_escape }}`, data, `{"ak":[1,2,3,4]}`) +// requireTemplateRender(t, `{{obj | xml_escape }}`, data, `{"ak":[1,2,3,4]}`) // } func TestWhereExpFilter(t *testing.T) { @@ -56,7 +51,7 @@ func TestWhereExpFilter(t *testing.T) { data := VariableMap{ "array": []int{1, 2, 3, 4}, } - assertTemplateRender(t, tmpl, data, "34") + requireTemplateRender(t, tmpl, data, "34") } func TestWhereExpFilterObjects(t *testing.T) { @@ -75,5 +70,5 @@ func TestWhereExpFilterObjects(t *testing.T) { "flag": false, }, }} - assertTemplateRender(t, tmpl, data, "A") + requireTemplateRender(t, tmpl, data, "A") } diff --git a/page_test.go b/page_test.go index 8636685..1a57734 100644 --- a/page_test.go +++ b/page_test.go @@ -3,11 +3,11 @@ package main import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestIsMarkdown(t *testing.T) { - assert.True(t, site.IsMarkdown("name.md")) - assert.True(t, site.IsMarkdown("name.markdown")) - assert.False(t, site.IsMarkdown("name.html")) + require.True(t, site.IsMarkdown("name.md")) + require.True(t, site.IsMarkdown("name.markdown")) + require.False(t, site.IsMarkdown("name.html")) } diff --git a/permalinks_test.go b/permalinks_test.go index 159c825..92a0e6f 100644 --- a/permalinks_test.go +++ b/permalinks_test.go @@ -3,7 +3,7 @@ package main import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestExpandPermalinkPattern(t *testing.T) { @@ -19,36 +19,43 @@ func TestExpandPermalinkPattern(t *testing.T) { } t.Run(":output_ext", func(t *testing.T) { - p, _ := testPermalinkPattern("/base:output_ext", path, d) - assert.Equal(t, "/base.html", p) + p, err := testPermalinkPattern("/base:output_ext", path, d) + require.NoError(t, err) + require.Equal(t, "/base.html", p) }) t.Run(":output_ext renames markdown to .html", func(t *testing.T) { - p, _ := testPermalinkPattern("/base:output_ext", "/a/b/base.md", d) - assert.Equal(t, "/base.html", p) - p, _ = testPermalinkPattern("/base:output_ext", "/a/b/base.markdown", d) - assert.Equal(t, "/base.html", p) + p, err := testPermalinkPattern("/base:output_ext", "/a/b/base.md", d) + require.NoError(t, err) + require.Equal(t, "/base.html", p) + p, err = testPermalinkPattern("/base:output_ext", "/a/b/base.markdown", d) + require.NoError(t, err) + require.Equal(t, "/base.html", p) }) t.Run(":name", func(t *testing.T) { - p, _ := testPermalinkPattern("/name/:name", path, d) - assert.Equal(t, "/name/base", p) + p, err := testPermalinkPattern("/name/:name", path, d) + require.NoError(t, err) + require.Equal(t, "/name/base", p) }) t.Run(":path", func(t *testing.T) { - p, _ := testPermalinkPattern("/prefix:path/post", path, d) - assert.Equal(t, "/prefix/a/b/base/post", p) + p, err := testPermalinkPattern("/prefix:path/post", path, d) + require.NoError(t, err) + require.Equal(t, "/prefix/a/b/base/post", p) }) t.Run(":title", func(t *testing.T) { - p, _ := testPermalinkPattern("/title/:title.html", path, d) - assert.Equal(t, "/title/base.html", p) + p, err := testPermalinkPattern("/title/:title.html", path, d) + require.NoError(t, err) + require.Equal(t, "/title/base.html", p) }) t.Run("invalid template variable", func(t *testing.T) { _, err := testPermalinkPattern("/:invalid", path, d) - assert.Error(t, err) + require.Error(t, err) }) d["collection"] = "c" path = "_c/a/b/c.d" t.Run(":path", func(t *testing.T) { - p, _ := testPermalinkPattern("/prefix:path/post", path, d) - assert.Equal(t, "/prefix/a/b/c/post", p) + p, err := testPermalinkPattern("/prefix:path/post", path, d) + require.NoError(t, err) + require.Equal(t, "/prefix/a/b/c/post", p) }) }