Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more range tests #353

Merged
merged 1 commit into from
Oct 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions test/iterator-range-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var collectEntries = require('level-concat-iterator')
var xtend = require('xtend')

var db

Expand Down Expand Up @@ -44,6 +45,30 @@ exports.range = function (test, testCommon) {
t.end()
})
})

// Test the documented promise that in reverse mode,
// "the returned entries are the same, but in reverse".
if (!opts.reverse && !('limit' in opts)) {
var reverseOpts = xtend(opts, { reverse: true })

// Swap start & end options
if (('start' in opts) && ('end' in opts)) {
reverseOpts.end = opts.start
reverseOpts.start = opts.end
} else if ('start' in opts) {
reverseOpts.end = opts.start
delete reverseOpts.start
} else if ('end' in opts) {
reverseOpts.start = opts.end
delete reverseOpts.end
}

rangeTest(
name + ' (flipped)',
reverseOpts,
expected.slice().reverse()
)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This makes some tests (with reverse=true) redundant. We can remove those later, I figured that would be easier to review as a separate PR.

}

rangeTest('test full data collection', {}, data)
Expand Down Expand Up @@ -292,6 +317,38 @@ exports.range = function (test, testCommon) {
reverse: true
}, data.slice().reverse())

rangeTest('test iterator with lt after database end', {
lt: 'a'
}, data.slice())

rangeTest('test iterator with end after database end - legacy', {
end: 'a'
}, data.slice())

rangeTest('test iterator with lt at database end', {
lt: data[data.length - 1].key
}, data.slice(0, -1))

rangeTest('test iterator with lte at database end', {
lte: data[data.length - 1].key
}, data.slice())

rangeTest('test iterator with end at database end - legacy', {
end: data[data.length - 1].key
}, data.slice())

rangeTest('test iterator with lt before database end', {
lt: data[data.length - 2].key
}, data.slice(0, -2))

rangeTest('test iterator with lte before database end', {
lte: data[data.length - 2].key
}, data.slice(0, -1))

rangeTest('test iterator with end before database end - legacy', {
end: data[data.length - 2].key
}, data.slice(0, -1))

rangeTest('test iterator with lte and gte after database and reverse=true', {
lte: '9b',
gte: '9a',
Expand Down