Skip to content

Commit

Permalink
refactor: remove testify
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed Feb 5, 2025
1 parent 143f093 commit 6d865b3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ require (
github.com/remeh/sizedwaitgroup v1.0.0
github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.10.0
github.com/tomwright/dasel/v2 v2.8.1
github.com/yuin/goldmark v1.7.8
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8
Expand All @@ -38,18 +37,17 @@ require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.3.1 // indirect
github.com/atomicgo/cursor v0.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/huandu/xstrings v1.5.0 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/spf13/cast v1.7.1 // indirect
github.com/stretchr/testify v1.10.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/sync v0.10.0 // indirect
Expand Down
40 changes: 30 additions & 10 deletions internal/core/ini_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package core

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

func Test_processConfig_commentDelimiters(t *testing.T) {
Expand All @@ -18,7 +17,7 @@ func Test_processConfig_commentDelimiters(t *testing.T) {
CommentDelimiters = "{/*,*/}"
`,
expected: map[string][2]string{
"*.md": [2]string{"{/*", "*/}"},
"*.md": {"{/*", "*/}"},
},
},
{
Expand All @@ -33,13 +32,26 @@ TokenIgnores = (\$+[^\n$]+\$+)
for _, c := range cases {
t.Run(c.description, func(t *testing.T) {
uCfg, err := shadowLoad([]byte(c.body))
assert.NoError(t, err)
if err != nil {
t.Fatal(err)
}

conf, err := NewConfig(&CLIFlags{})
assert.NoError(t, err)
if err != nil {
t.Fatal(err)
}

_, err = processConfig(uCfg, conf, false)
assert.NoError(t, err)
if err != nil {
t.Fatal(err)
}

actual := conf.CommentDelimiters
assert.Equal(t, c.expected, actual)
for k, v := range c.expected {
if actual[k] != v {
t.Errorf("expected %v, but got %v", v, actual[k])
}
}
})
}
}
Expand Down Expand Up @@ -86,11 +98,19 @@ CommentDelimiters = "{/*"
for _, c := range cases {
t.Run(c.description, func(t *testing.T) {
uCfg, err := shadowLoad([]byte(c.body))
assert.NoError(t, err)
if err != nil {
t.Fatal(err)
}

conf, err := NewConfig(&CLIFlags{})
assert.NoError(t, err)
if err != nil {
t.Fatal(err)
}

_, err = processConfig(uCfg, conf, false)
assert.ErrorContains(t, err, c.expectedErr)
if !strings.Contains(err.Error(), c.expectedErr) {
t.Errorf("expected %v, but got %v", c.expectedErr, err.Error())
}
})
}
}
20 changes: 12 additions & 8 deletions internal/lint/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"

"github.com/errata-ai/vale/v3/internal/core"
"github.com/stretchr/testify/assert"
)

func Test_applyPatterns(t *testing.T) {
Expand All @@ -20,7 +19,7 @@ func Test_applyPatterns(t *testing.T) {
description: "MDX comment in markdown, custom comment delimiter",
conf: core.Config{
CommentDelimiters: map[string][2]string{
".md": [2]string{"{/*", "*/}"},
".md": {"{/*", "*/}"},
},
},
exts: extensionConfig{".md", ".md"},
Expand Down Expand Up @@ -74,7 +73,7 @@ This is the intro pagragraph.
description: "multiline MDX comment in markdown, custom comment delimiter",
conf: core.Config{
CommentDelimiters: map[string][2]string{
".md": [2]string{"{/*", "*/}"},
".md": {"{/*", "*/}"},
},
},
exts: extensionConfig{".md", ".md"},
Expand Down Expand Up @@ -108,7 +107,7 @@ This is a comment
content: "Call \\c func to start the process.",
conf: core.Config{
TokenIgnores: map[string][]string{
"*.cc": []string{`(\\c \w+)`},
"*.cc": {`(\\c \w+)`},
},
Formats: map[string]string{
"cc": "md",
Expand All @@ -122,8 +121,11 @@ This is a comment
for _, c := range cases {
t.Run(c.description, func(t *testing.T) {
s, err := applyPatterns(&c.conf, c.exts, c.content)
assert.NoError(t, err)
assert.Equal(t, c.expected, s)
if err != nil {
t.Fatalf("applyPatterns returned an error: %s", err)
} else if s != c.expected {
t.Fatalf("Expected '%s', but got '%s'", c.expected, s)
}
})
}
}
Expand All @@ -140,7 +142,7 @@ func Test_applyPatterns_errors(t *testing.T) {
description: "only one delimiter",
conf: core.Config{
CommentDelimiters: map[string][2]string{
".md": [2]string{"{/*", ""},
".md": {"{/*", ""},
},
},
exts: extensionConfig{".md", ".md"},
Expand All @@ -159,7 +161,9 @@ This is the intro pagragraph.
for _, c := range cases {
t.Run(c.description, func(t *testing.T) {
_, err := applyPatterns(&c.conf, c.exts, c.content)
assert.ErrorContains(t, err, c.expectedErr)
if !strings.Contains(err.Error(), c.expectedErr) {
t.Fatalf("Expected '%s', but got '%s'", c.expectedErr, err.Error())
}
})
}
}
Expand Down

0 comments on commit 6d865b3

Please # to comment.