Skip to content

Commit

Permalink
Add test for performance
Browse files Browse the repository at this point in the history
Related-to: syntax-tree/mdast-util-to-hast#62.

Co-authored-by: Nathaniel Hunter <42shadow42@gmail.com>
  • Loading branch information
wooorm and 42shadow42 committed Jun 25, 2022
1 parent 2832244 commit 321dc64
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,21 @@ test('trimLines(value)', function (t) {
)
t.end()
})

test('efficiency', (t) => {
const aTonOfWhitespace = 'a' + ' '.repeat(70_000) + 'b'
const timeoutId = setTimeout(() => {
t.fail('should process lots of whitespace efficiently')
}, 10)

t.deepEqual(
trimLines(aTonOfWhitespace),
aTonOfWhitespace,
'should be efficient on excessive whitespace'
)

setTimeout(() => {
clearTimeout(timeoutId)
t.end()
}, 0)
})

1 comment on commit 321dc64

@42shadow42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the implementation provided in the following commit, I think this test should include some line breaks, its possible the implementation efficiency breaks down in the presence of edge case matches. For example, you might do

const aTonOfWhitespace = '\na' + ' '.repeat(70_000) + 'b' + ' '.repeat(70_000) + 'c\n'

Please sign in to comment.