]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/regexp/all_test.go
regexp: add Regexp.TextMarshaler/TextUnmarshaler
[gostls13.git] / src / regexp / all_test.go
index 52de3fef83da514f25f404072e7cb8ce8f0a13da..124313d1af970e5a16396253cd2f352a126c83c5 100644 (file)
@@ -947,3 +947,29 @@ func TestMinInputLen(t *testing.T) {
                }
        }
 }
+
+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")
+               }
+       })
+}