Skip to content

Instantly share code, notes, and snippets.

@Jabher
Created May 17, 2020 17:37
Show Gist options
  • Select an option

  • Save Jabher/89f7f8d82fb40e56d80b04901679565e to your computer and use it in GitHub Desktop.

Select an option

Save Jabher/89f7f8d82fb40e56d80b04901679565e to your computer and use it in GitHub Desktop.

Revisions

  1. Jabher created this gist May 17, 2020.
    42 changes: 42 additions & 0 deletions compileTrie.test.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    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"
    ]
    })
    })