require('bare-process/global') const test = require('brittle') const { HyperP2PTriePrefix, PROTOCOL } = require('../index.js') test('exports', (t) => { t.ok(HyperP2PTriePrefix) t.is(PROTOCOL, 'trie-prefix/v1') }) test('insert prefixSearch', async (t) => { const m = new HyperP2PTriePrefix() m.insert('pear') m.insert('peer') t.alike(m.prefixSearch('pe'), ['pear', 'peer']) await m.close() }) test('validation', async (t) => { const m = new HyperP2PTriePrefix() try { m.insert('') } catch (e) { t.ok(e) } await m.close() }) test('remove', async (t) => { const m = new HyperP2PTriePrefix() m.insert('cat') t.ok(m.remove('cat')) t.is(m.prefixSearch('ca').length, 0) await m.close() }) test('getStats', async (t) => { const m = new HyperP2PTriePrefix() m.insert('z') t.is(m.getStats().protocol, 'trie-prefix/v1') t.is(m.getStats().inserted, 1) await m.close() }) test('autocomplete countPrefix', async (t) => { const m = new HyperP2PTriePrefix() m.insert('cat') m.insert('car') m.insert('dog') t.is(m.countPrefix('ca'), 2) t.is(m.autocomplete('ca', 1).length, 1) await m.close() })