Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Jan 5, 2024
1 parent 6764cd6 commit e368868
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 69 deletions.
120 changes: 55 additions & 65 deletions cask/test/src/test/cask/DispatchTrieTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import utest._
object DispatchTrieTests extends TestSuite {
val tests = Tests{

"hello" - {
test("hello") {
val x = DispatchTrie.construct(0,
Seq((Vector("hello"), "GET", false))
)(Seq(_))
Expand All @@ -15,7 +15,7 @@ object DispatchTrieTests extends TestSuite {
x.lookup(List("hello", "world"), Map()) ==> None
x.lookup(List("world"), Map()) ==> None
}
"nested" - {
test("nested") {
val x = DispatchTrie.construct(0,
Seq(
(Vector("hello", "world"), "GET", false),
Expand All @@ -31,7 +31,7 @@ object DispatchTrieTests extends TestSuite {
x.lookup(List("hello", "world", "moo"), Map()) ==> None

}
"bindings" - {
test("bindings") {
val x = DispatchTrie.construct(0,
Seq((Vector(":hello", ":world"), "GET", false))
)(Seq(_))
Expand All @@ -44,7 +44,7 @@ object DispatchTrieTests extends TestSuite {

}

"path" - {
test("path") {
val x = DispatchTrie.construct(0,
Seq((Vector("hello"), "GET", true))
)(Seq(_))
Expand All @@ -56,82 +56,72 @@ object DispatchTrieTests extends TestSuite {
x.lookup(List(), Map()) == None
}

"partialOverlap" - {
val x = DispatchTrie.construct(0,
Seq(
(Vector(":hello"), "GET", false),
(Vector("hello", ":world"), "GET", false)
)
)(Seq(_))

x.lookup(List("hello", "world"), Map()) ==> Some(("GET", Map("hello" -> "hello", "world" -> "world"), Nil))
x.lookup(List("world", "hello"), Map()) ==> Some(("GET", Map("hello" -> "world", "world" -> "hello"), Nil))
test("partialOverlap") {
test("wildcardAndFixedWildcard"){
val x = DispatchTrie.construct(0,
Seq(
(Vector(":hello"), "GET", false),
(Vector("hello", ":world"), "GET", false)
)
)(Seq(_))

x.lookup(List("hello", "world", "cow"), Map()) ==> None
x.lookup(List("hello"), Map()) ==> None
}
x.lookup(List("hello", "world"), Map()) ==> Some(("GET", Map("hello" -> "hello", "world" -> "world"), Nil))
x.lookup(List("world", "hello"), Map()) ==> Some(("GET", Map("hello" -> "world", "world" -> "hello"), Nil))

"partialOverlap2" - {
val x = DispatchTrie.construct(0,
Seq(
(Vector(":var", "foo"), ("GET", "fooImpl"), false),
(Vector(":var", "bar"), ("GET", "barImpl"), false)
)
)(t => Seq(t._1))
x.lookup(List("hello", "world", "cow"), Map()) ==> None
x.lookup(List("hello"), Map()) ==> None
}

x.lookup(List("hello", "foo"), Map()) ==> Some((("GET", "fooImpl"), Map("var" -> "hello"), Nil))
x.lookup(List("world", "bar"), Map()) ==> Some((("GET", "barImpl"), Map("var" -> "world"), Nil))

x.lookup(List("hello", "world", "cow"), Map()) ==> None
x.lookup(List("hello"), Map()) ==> None
}
test("wildcardAndWildcardFixed") {
val x = DispatchTrie.construct(0,
Seq(
(Vector(":hello"), "GET", false),
(Vector(":hello", "world"), "GET", false)
)
)(Seq(_))

"partialOverlap3" - {
val x = DispatchTrie.construct(0,
Seq(
(Vector(":hello", "foo"), "GET", false),
(Vector(":world", "bar"), "GET", false)
)
)(Seq(_))
x.lookup(List("hello", "world"), Map()) ==> Some(("GET", Map("hello" -> "hello"), Nil))
x.lookup(List("hello"), Map()) ==> Some(("GET", Map("hello" -> "hello"), Nil))

x.lookup(List("hello", "world"), Map()) ==> Some(("GET", Map("hello" -> "hello", "world" -> "world"), Nil))
x.lookup(List("world", "hello"), Map()) ==> Some(("GET", Map("hello" -> "world", "world" -> "hello"), Nil))
x.lookup(List("world", "hello"), Map()) ==> None
x.lookup(List("hello", "world", "cow"), Map()) ==> None
}

x.lookup(List("hello", "world", "cow"), Map()) ==> None
x.lookup(List("hello"), Map()) ==> None
}
test("sameWildcardDifferingFixed"){
val x = DispatchTrie.construct(0,
Seq(
(Vector(":var", "foo"), ("GET", "fooImpl"), false),
(Vector(":var", "bar"), ("GET", "barImpl"), false)
)
)(t => Seq(t._1))

"partialOverlap4" - {
val x = DispatchTrie.construct(0,
Seq(
(Vector(":hello"), "GET", false),
(Vector(":hello", "world"), "GET", false)
)
)(Seq(_))
x.lookup(List("hello", "foo"), Map()) ==> Some((("GET", "fooImpl"), Map("var" -> "hello"), Nil))
x.lookup(List("world", "bar"), Map()) ==> Some((("GET", "barImpl"), Map("var" -> "world"), Nil))

x.lookup(List("hello", "world"), Map()) ==> Some(("GET", Map("hello" -> "hello"), Nil))
x.lookup(List("hello"), Map()) ==> Some(("GET", Map("hello" -> "hello"), Nil))
x.lookup(List("hello", "world", "cow"), Map()) ==> None
x.lookup(List("hello"), Map()) ==> None
}

x.lookup(List("world", "hello"), Map()) ==> None
x.lookup(List("hello", "world", "cow"), Map()) ==> None
}
test("differingWildcardDifferingFixed") {
val x = DispatchTrie.construct(0,
Seq(
(Vector(":hello", "foo"), "GET", false),
(Vector(":world", "bar"), "GET", false)
)
)(Seq(_))

"partialOverlap5" - {
val x = DispatchTrie.construct(0,
Seq(
(Vector(":hello"), "GET", false),
(Vector(":world", "world"), "GET", false)
)
)(Seq(_))
x.lookup(List("hello", "world"), Map()) ==> Some(("GET", Map("hello" -> "hello", "world" -> "world"), Nil))
x.lookup(List("world", "hello"), Map()) ==> Some(("GET", Map("hello" -> "world", "world" -> "hello"), Nil))

x.lookup(List("hello", "world"), Map()) ==> Some(("GET", Map("world" -> "hello"), Nil))
x.lookup(List("hello"), Map()) ==> Some(("GET", Map("world" -> "hello"), Nil))
x.lookup(List("hello", "world", "cow"), Map()) ==> None
x.lookup(List("hello"), Map()) ==> None
}

x.lookup(List("world", "hello"), Map()) ==> None
x.lookup(List("hello", "world", "cow"), Map()) ==> None
}

"errors" - {

test("errors") {
test("wildcardAndFixed") {
DispatchTrie.construct(0,
Seq(
Expand Down
6 changes: 3 additions & 3 deletions cask/test/src/test/cask/FailureTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object FailureTests extends TestSuite {
}

val tests = Tests{
"mismatchedDecorators" - {
test("mismatchedDecorators") {
val m = utest.compileError("""
object Decorated extends cask.MainRoutes{
@myDecorator
Expand All @@ -23,7 +23,7 @@ object FailureTests extends TestSuite {
assert(m.contains("required: cask.router.Decorator[_, cask.endpoints.WebsocketResult, _]"))
}

"noEndpoint" - {
test("noEndpoint") {
utest.compileError("""
object Decorated extends cask.MainRoutes{
@cask.get("/hello/:world")
Expand All @@ -35,7 +35,7 @@ object FailureTests extends TestSuite {
"Last annotation applied to a function must be an instance of Endpoint, not test.cask.FailureTests.myDecorator"
}

"tooManyEndpoint" - {
test("tooManyEndpoint") {
utest.compileError("""
object Decorated extends cask.MainRoutes{
@cask.get("/hello/:world")
Expand Down
2 changes: 1 addition & 1 deletion cask/test/src/test/cask/UtilTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import utest._

object UtilTests extends TestSuite {
val tests = Tests{
"splitPath" - {
test("splitPath") {
cask.internal.Util.splitPath("") ==> Seq()
cask.internal.Util.splitPath("/") ==> Seq()
cask.internal.Util.splitPath("////") ==> Seq()
Expand Down

0 comments on commit e368868

Please sign in to comment.