Fix tests for Go1.16

This commit is contained in:
yuin 2022-03-05 18:56:34 +09:00
parent 920c3818d4
commit a816d4652e

View file

@ -88,18 +88,23 @@ func TestAutogeneratedIDs(t *testing.T) {
}
}
func nowMillis() int64 {
// TODO: replace UnixNano to UnixMillis(drops Go1.16 support)
return time.Now().UnixNano() / 1000000
}
func TestDeepNestedLabelPerformance(t *testing.T) {
markdown := New(WithRendererOptions(
html.WithXHTML(),
html.WithUnsafe(),
))
started := time.Now().UnixMilli()
started := nowMillis()
n := 50000
source := []byte(strings.Repeat("[", n) + strings.Repeat("]", n))
var b bytes.Buffer
_ = markdown.Convert(source, &b)
finished := time.Now().UnixMilli()
finished := nowMillis()
if (finished - started) > 5000 {
t.Error("Parsing deep nested labels took more 5 secs")
}
@ -111,12 +116,12 @@ func TestManyProcessingInstructionPerformance(t *testing.T) {
html.WithUnsafe(),
))
started := time.Now().UnixMilli()
started := nowMillis()
n := 50000
source := []byte("a " + strings.Repeat("<?", n))
var b bytes.Buffer
_ = markdown.Convert(source, &b)
finished := time.Now().UnixMilli()
finished := nowMillis()
if (finished - started) > 5000 {
t.Error("Parsing processing instructions took more 5 secs")
}
@ -128,12 +133,12 @@ func TestManyCDATAPerformance(t *testing.T) {
html.WithUnsafe(),
))
started := time.Now().UnixMilli()
started := nowMillis()
n := 50000
source := []byte(strings.Repeat("a <![CDATA[", n))
var b bytes.Buffer
_ = markdown.Convert(source, &b)
finished := time.Now().UnixMilli()
finished := nowMillis()
if (finished - started) > 5000 {
t.Error("Parsing processing instructions took more 5 secs")
}
@ -145,12 +150,12 @@ func TestManyDeclPerformance(t *testing.T) {
html.WithUnsafe(),
))
started := time.Now().UnixMilli()
started := nowMillis()
n := 50000
source := []byte(strings.Repeat("a <!A ", n))
var b bytes.Buffer
_ = markdown.Convert(source, &b)
finished := time.Now().UnixMilli()
finished := nowMillis()
if (finished - started) > 5000 {
t.Error("Parsing processing instructions took more 5 secs")
}
@ -162,12 +167,12 @@ func TestManyCommentPerformance(t *testing.T) {
html.WithUnsafe(),
))
started := time.Now().UnixMilli()
started := nowMillis()
n := 50000
source := []byte(strings.Repeat("a <!-- ", n))
var b bytes.Buffer
_ = markdown.Convert(source, &b)
finished := time.Now().UnixMilli()
finished := nowMillis()
if (finished - started) > 5000 {
t.Error("Parsing processing instructions took more 5 secs")
}