Skip to content

Instantly share code, notes, and snippets.

@Jabher
Created May 17, 2020 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jabher/89f7f8d82fb40e56d80b04901679565e to your computer and use it in GitHub Desktop.
Save Jabher/89f7f8d82fb40e56d80b04901679565e to your computer and use it in GitHub Desktop.
import { compileTrie } from './compileTrie'
import { Trie } from './Trie'
const makeTrie = (name: string, ...paths: string[]) => {
const trie = new Trie()
for (const key of paths) {
trie.mapValue(key.split('/'), () => `${name} ${key}`)
}
return trie
}
test('compileTrie', () => {
expect(compileTrie({
baseTrie: makeTrie('main',
':/bar',
':/:'
),
extraTries: [
makeTrie('extra1','foo/:'),
makeTrie('extra2', ':/*')
]
}).toJSON()).toEqual({
":>:": [
"extra2 :/*",
"main :/:"
],
":>bar": [
"extra2 :/*",
"main :/bar"
],
"foo>:": [
"extra2 :/*",
"extra1 foo/:",
"main :/:"
],
"foo>bar": [
"extra2 :/*",
"extra1 foo/:",
"main :/bar"
]
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment