}
}
}
+
+func TestUnmarshalText(t *testing.T) {
+ unmarshaled := new(Regexp)
+ for i := range goodRe {
+ re := compileTest(t, goodRe[i], "")
+ marshaled, err := re.MarshalText()
+ if err != nil {
+ t.Errorf("regexp %#q failed to marshal: %s", re, err)
+ continue
+ }
+ if err := unmarshaled.UnmarshalText(marshaled); err != nil {
+ t.Errorf("regexp %#q failed to unmarshal: %s", re, err)
+ continue
+ }
+ if unmarshaled.String() != goodRe[i] {
+ t.Errorf("UnmarshalText returned unexpected value: %s", unmarshaled.String())
+ }
+ }
+ t.Run("invalid pattern", func(t *testing.T) {
+ re := new(Regexp)
+ err := re.UnmarshalText([]byte(`\`))
+ if err == nil {
+ t.Error("unexpected success")
+ }
+ })
+}