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

Test case with sub encoder #135

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions test/sub.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const test = require('brittle')
const SubEncoder = require('sub-encoder')
const { create } = require('./helpers')

test('create many subs', async function (t) {
Expand All @@ -14,3 +15,11 @@ test('create many subs', async function (t) {

t.is(count, root.core.listenerCount('append'))
})

test('sub encoding', async function (t) {
const db = create()
const keyEncoding = new SubEncoder('files', 'utf-8')

await db.put('/a', '1', { keyEncoding })
t.alike(await db.get('/a', { keyEncoding }), { seq: 1, key: '/a', value: '1' })
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it correct that it's giving a buffer as key? Instead of the string '/a'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Upgraded sub-encoder v1 to v2, it seems to pass correctly the test above!

Now this test is not passing with the new encodeRange

const watcher = db.watch(sub.range(), { keyEncoding: sub, valueEncoding: 'json' })

Anyway at least sub-encoder was working as intended!

})