-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregexp_test.go
45 lines (38 loc) · 1008 Bytes
/
regexp_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package marshallable
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRegexpBasic(t *testing.T) {
data := `{"Regexp":".[123]+"}`
payload := new(struct{ Regexp Regexp })
err := json.Unmarshal([]byte(data), payload)
if err != nil {
t.Fatalf("Regexp failed to Unmarshal: %v", err)
}
o, err := json.Marshal(payload)
t.Logf("payload: %s", o)
assert.NoError(t, err)
assert.Equal(t, string(o), data)
}
func TestPOSIXRegexpBasic(t *testing.T) {
data := `{"POSIXRegexp":".[123]+"}`
payload := new(struct{ POSIXRegexp POSIXRegexp })
err := json.Unmarshal([]byte(data), payload)
if err != nil {
t.Fatalf("POSIXRegexp failed to Unmarshal: %v", err)
}
o, err := json.Marshal(payload)
t.Logf("payload: %s", o)
assert.NoError(t, err)
assert.Equal(t, string(o), data)
}
func TestRegexpNil(t *testing.T) {
var Regexp Regexp
V := Regexp.String()
t.Logf("Regexp: %s", V)
var POSIXRegexp POSIXRegexp
V = POSIXRegexp.String()
t.Logf("POSIXRegexp: %s", V)
}