Skip to content

Commit

Permalink
Use scoping TestUnmarshalEmptyRegexp to avoid subtle bugs when reusin…
Browse files Browse the repository at this point in the history
…g variables.

Signed-off-by: Peter Štibraný <pstibrany@gmail.com>
  • Loading branch information
pstibrany committed Jun 3, 2021
1 parent b61b520 commit f43e831
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,17 +679,22 @@ func TestMarshalNilRegexp(t *testing.T) {

func TestUnmarshalEmptyRegexp(t *testing.T) {
b := []byte(`""`)
var re Regexp

err := json.Unmarshal(b, &re)
require.NoError(t, err)
require.Equal(t, regexp.MustCompile("^(?:)$"), re.Regexp)
require.Equal(t, "", re.original)
{
var re Regexp
err := json.Unmarshal(b, &re)
require.NoError(t, err)
require.Equal(t, regexp.MustCompile("^(?:)$"), re.Regexp)
require.Equal(t, "", re.original)
}

err = yaml.Unmarshal(b, &re)
require.NoError(t, err)
require.Equal(t, regexp.MustCompile("^(?:)$"), re.Regexp)
require.Equal(t, "", re.original)
{
var re Regexp
err := yaml.Unmarshal(b, &re)
require.NoError(t, err)
require.Equal(t, regexp.MustCompile("^(?:)$"), re.Regexp)
require.Equal(t, "", re.original)
}
}

func TestUnmarshalNullRegexp(t *testing.T) {
Expand Down

0 comments on commit f43e831

Please sign in to comment.