author | Alberto Bertogli
<albertito@blitiri.com.ar> 2023-09-24 10:39:30 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2023-09-24 10:40:14 UTC |
parent | eb501ede1fc20b4664f0678b1c176b0546f96b15 |
config/config.go | +4 | -4 |
config/config_test.go | +5 | -5 |
diff --git a/config/config.go b/config/config.go index bdda912..982a743 100644 --- a/config/config.go +++ b/config/config.go @@ -63,7 +63,7 @@ type Route struct { type DirOpts struct { Listing map[string]bool `yaml:",omitempty"` - Exclude []Regexp `yaml:",omitempty"` + Exclude []PathRegexp `yaml:",omitempty"` } type Raw struct { @@ -200,12 +200,12 @@ func LoadString(contents string) (*Config, error) { } // Wrapper to simplify regexp in configuration. -type Regexp struct { +type PathRegexp struct { orig string *regexp.Regexp } -func (re *Regexp) UnmarshalYAML(unmarshal func(interface{}) error) error { +func (re *PathRegexp) UnmarshalYAML(unmarshal func(interface{}) error) error { var s string if err := unmarshal(&s); err != nil { return err @@ -221,7 +221,7 @@ func (re *Regexp) UnmarshalYAML(unmarshal func(interface{}) error) error { return nil } -func (re Regexp) MarshalYAML() (interface{}, error) { +func (re PathRegexp) MarshalYAML() (interface{}, error) { return re.orig, nil } diff --git a/config/config_test.go b/config/config_test.go index c4f5cbc..d2d6d50 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -241,17 +241,17 @@ func expectErrs(t *testing.T, want string, got []error) { } } -func TestRegexp(t *testing.T) { - re := Regexp{} +func TestPathRegexp(t *testing.T) { + re := PathRegexp{} err := yaml.Unmarshal([]byte(`"ab.d"`), &re) if err != nil { t.Errorf("unexpected error: %v", err) } - expected := Regexp{ + expected := PathRegexp{ orig: "ab.d", Regexp: regexp.MustCompile("^(?:ab.d)$"), } - opts := cmp.Comparer(func(x, y Regexp) bool { + opts := cmp.Comparer(func(x, y PathRegexp) bool { return x.orig == y.orig && x.String() == y.String() }) if diff := cmp.Diff(expected, re, opts); diff != "" { @@ -271,7 +271,7 @@ func TestRegexp(t *testing.T) { } // Test marshalling. - s, err := Regexp{orig: "ab.d"}.MarshalYAML() + s, err := PathRegexp{orig: "ab.d"}.MarshalYAML() if !(s == "ab.d" && err == nil) { t.Errorf(`expected "ab.d" / nil, got %q / %v`, s, err) }