diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-07-22 17:19:23 +0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-07-22 17:19:23 +0800 |
commit | 3fcab5dc0dc5df56976d87a7097549a55ec8e321 (patch) | |
tree | 490c23f94eb2b4680c74cb946d01dd15978cc6f6 /cask/test/src/test/cask/DispatchTrieTests.scala | |
parent | 0526bee89884f94c2b43b55ab3147cb093d74210 (diff) | |
download | cask-3fcab5dc0dc5df56976d87a7097549a55ec8e321.tar.gz cask-3fcab5dc0dc5df56976d87a7097549a55ec8e321.tar.bz2 cask-3fcab5dc0dc5df56976d87a7097549a55ec8e321.zip |
tweaks
Diffstat (limited to 'cask/test/src/test/cask/DispatchTrieTests.scala')
-rw-r--r-- | cask/test/src/test/cask/DispatchTrieTests.scala | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/cask/test/src/test/cask/DispatchTrieTests.scala b/cask/test/src/test/cask/DispatchTrieTests.scala new file mode 100644 index 0000000..fdd5f27 --- /dev/null +++ b/cask/test/src/test/cask/DispatchTrieTests.scala @@ -0,0 +1,103 @@ +package test.cask +import cask.DispatchTrie +import utest._ + +object DispatchTrieTests extends TestSuite { + val tests = Tests{ + + 'hello - { + val x = DispatchTrie.construct(0, + Seq((Vector("hello"), 1, false)) + ) + + assert( + x.lookup(List("hello"), Map()) == Some((1, Map(), Nil)), + x.lookup(List("hello", "world"), Map()) == None, + x.lookup(List("world"), Map()) == None + ) + } + 'nested - { + val x = DispatchTrie.construct(0, + Seq( + (Vector("hello", "world"), 1, false), + (Vector("hello", "cow"), 2, false) + ) + ) + assert( + x.lookup(List("hello", "world"), Map()) == Some((1, Map(), Nil)), + x.lookup(List("hello", "cow"), Map()) == Some((2, Map(), Nil)), + x.lookup(List("hello"), Map()) == None, + x.lookup(List("hello", "moo"), Map()) == None, + x.lookup(List("hello", "world", "moo"), Map()) == None + ) + } + 'bindings - { + val x = DispatchTrie.construct(0, + Seq((Vector(":hello", ":world"), 1, false)) + ) + assert( + x.lookup(List("hello", "world"), Map()) == Some((1, Map("hello" -> "hello", "world" -> "world"), Nil)), + x.lookup(List("world", "hello"), Map()) == Some((1, Map("hello" -> "world", "world" -> "hello"), Nil)), + + x.lookup(List("hello", "world", "cow"), Map()) == None, + x.lookup(List("hello"), Map()) == None + ) + } + + 'path - { + val x = DispatchTrie.construct(0, + Seq((Vector("hello"), 1, true)) + ) + + assert( + x.lookup(List("hello", "world"), Map()) == Some((1,Map(), Seq("world"))), + x.lookup(List("hello", "world", "cow"), Map()) == Some((1,Map(), Seq("world", "cow"))), + x.lookup(List("hello"), Map()) == Some((1,Map(), Seq())), + x.lookup(List(), Map()) == None + ) + } + + 'errors - { + intercept[Exception]{ + DispatchTrie.construct(0, + Seq( + (Vector("hello", ":world"), 1, false), + (Vector("hello", "world"), 2, false) + ) + ) + } + intercept[Exception]{ + DispatchTrie.construct(0, + Seq( + (Vector("hello", ":world"), 1, false), + (Vector("hello", "world", "omg"), 2, false) + ) + ) + } + intercept[Exception]{ + DispatchTrie.construct(0, + Seq( + (Vector("hello"), 1, true), + (Vector("hello", "cow", "omg"), 2, false) + ) + ) + } + intercept[Exception]{ + DispatchTrie.construct(0, + Seq( + (Vector("hello", ":world"), 1, false), + (Vector("hello", ":cow"), 2, false) + ) + ) + } + intercept[Exception]{ + DispatchTrie.construct(0, + Seq( + (Vector("hello", "world"), 1, false), + (Vector("hello", "world"), 2, false) + ) + ) + } + } + } +}
\ No newline at end of file |