Skip to content

Commit

Permalink
Fix tests for Go1.16
Browse files Browse the repository at this point in the history
  • Loading branch information
yuin committed Mar 5, 2022
1 parent 920c381 commit a816d46
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions extra_test.go
Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand Down

0 comments on commit a816d46

Please sign in to comment.