diff options
Diffstat (limited to 'core/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala')
-rw-r--r-- | core/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala | 65 |
1 files changed, 21 insertions, 44 deletions
diff --git a/core/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala b/core/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala index e417233..69290b0 100644 --- a/core/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala +++ b/core/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala @@ -22,14 +22,11 @@ class UriInterpolatorTests extends FunSuite with Matchers { (uri"http://example.com?x=y", "http://example.com?x=y"), (uri"http://example.com/a/b/c", "http://example.com/a/b/c"), (uri"http://example.com/a/b/c/", "http://example.com/a/b/c/"), - (uri"http://example.com/a/b/c?x=y&h=j", - "http://example.com/a/b/c?x=y&h=j") + (uri"http://example.com/a/b/c?x=y&h=j", "http://example.com/a/b/c?x=y&h=j") ), "scheme" -> List( - (uri"http${if (secure) "s" else ""}://example.com", - s"https://example.com"), - (uri"${if (secure) "https" else "http"}://example.com", - s"https://example.com"), + (uri"http${if (secure) "s" else ""}://example.com", s"https://example.com"), + (uri"${if (secure) "https" else "http"}://example.com", s"https://example.com"), (uri"example.com?a=$v2", s"http://example.com?a=$v2queryEncoded") ), "user info" -> List( @@ -47,10 +44,8 @@ class UriInterpolatorTests extends FunSuite with Matchers { (uri"http://$None.example.com", s"http://example.com"), (uri"http://$None.$None.example.com", s"http://example.com"), (uri"http://${Some("sub")}.example.com", s"http://sub.example.com"), - (uri"http://${Some("sub1.sub2")}.example.com", - s"http://sub1.sub2.example.com"), - (uri"http://${List("sub1", "sub2")}.example.com", - s"http://sub1.sub2.example.com"), + (uri"http://${Some("sub1.sub2")}.example.com", s"http://sub1.sub2.example.com"), + (uri"http://${List("sub1", "sub2")}.example.com", s"http://sub1.sub2.example.com"), (uri"http://${List("sub", "example", "com")}", s"http://sub.example.com") ), "authority with parameters" -> List( @@ -78,18 +73,13 @@ class UriInterpolatorTests extends FunSuite with Matchers { (uri"http://example.com/$v1/", s"http://example.com/$v1/"), (uri"http://example.com/$v2", s"http://example.com/$v2encoded"), (uri"http://example.com/$v2/$v1", s"http://example.com/$v2encoded/$v1"), - (uri"http://example.com/$v1/p/$v4", - s"http://example.com/$v1/p/$v4encoded"), - (uri"http://example.com/a/${List(v2, "c", v4)}/b", - s"http://example.com/a/$v2encoded/c/$v4encoded/b"), - (uri"http://example.com/${"a/b/c".split('/')}", - s"http://example.com/a/b/c") + (uri"http://example.com/$v1/p/$v4", s"http://example.com/$v1/p/$v4encoded"), + (uri"http://example.com/a/${List(v2, "c", v4)}/b", s"http://example.com/a/$v2encoded/c/$v4encoded/b"), + (uri"http://example.com/${"a/b/c".split('/')}", s"http://example.com/a/b/c") ), "path with parameters" -> List( - (uri"http://example.com/$v1?x=$v2", - s"http://example.com/$v1?x=$v2queryEncoded"), - (uri"http://example.com/$v1/$v2?x=$v2", - s"http://example.com/$v1/$v2encoded?x=$v2queryEncoded") + (uri"http://example.com/$v1?x=$v2", s"http://example.com/$v1?x=$v2queryEncoded"), + (uri"http://example.com/$v1/$v2?x=$v2", s"http://example.com/$v1/$v2encoded?x=$v2queryEncoded") ), "query parameter values" -> List( (uri"http://example.com?x=$v1", s"http://example.com?x=$v1"), @@ -101,31 +91,24 @@ class UriInterpolatorTests extends FunSuite with Matchers { ), "query parameter without value" -> List( (uri"http://example.com?$v1", s"http://example.com?$v1"), - (uri"http://example.com?$v1&$v2", - s"http://example.com?$v1&$v2queryEncoded") + (uri"http://example.com?$v1&$v2", s"http://example.com?$v1&$v2queryEncoded") ), "optional query parameters" -> List( (uri"http://example.com?a=$None", s"http://example.com"), (uri"http://example.com?a=b&c=$None", s"http://example.com?a=b"), (uri"http://example.com?a=b&c=$None&e=f", s"http://example.com?a=b&e=f"), (uri"http://example.com?a=${Some(v1)}", s"http://example.com?a=$v1"), - (uri"http://example.com?a=${Some(v1)}&c=d", - s"http://example.com?a=$v1&c=d") + (uri"http://example.com?a=${Some(v1)}&c=d", s"http://example.com?a=$v1&c=d") ), "parameter collections" -> List( (uri"http://example.com?${Seq("a" -> "b", v2 -> v1, v1 -> v2)}", s"http://example.com?a=b&$v2queryEncoded=$v1&$v1=$v2queryEncoded"), - (uri"http://example.com?${Seq("a" -> "b", "a" -> "c")}", - s"http://example.com?a=b&a=c"), + (uri"http://example.com?${Seq("a" -> "b", "a" -> "c")}", s"http://example.com?a=b&a=c"), (uri"http://example.com?${Map("a" -> "b")}", s"http://example.com?a=b"), - (uri"http://example.com?x=y&${Map("a" -> "b")}", - s"http://example.com?x=y&a=b"), - (uri"http://example.com?x=y&${Map("a" -> None)}", - s"http://example.com?x=y"), - (uri"http://example.com?x=y&${Map("a" -> Some("b"))}", - s"http://example.com?x=y&a=b"), - (uri"http://example.com?x=y&${Seq("a" -> None)}", - s"http://example.com?x=y") + (uri"http://example.com?x=y&${Map("a" -> "b")}", s"http://example.com?x=y&a=b"), + (uri"http://example.com?x=y&${Map("a" -> None)}", s"http://example.com?x=y"), + (uri"http://example.com?x=y&${Map("a" -> Some("b"))}", s"http://example.com?x=y&a=b"), + (uri"http://example.com?x=y&${Seq("a" -> None)}", s"http://example.com?x=y") ), "fragments" -> List( (uri"http://example.com#$v1", s"http://example.com#$v1"), @@ -137,8 +120,7 @@ class UriInterpolatorTests extends FunSuite with Matchers { ), "embed whole url" -> List( (uri"${"http://example.com:123/a"}/b/c", "http://example.com:123/a/b/c"), - (uri"${uri"http://example.com/$v1?p=$v2"}", - s"http://example.com/$v1?p=$v2queryEncoded") + (uri"${uri"http://example.com/$v1?p=$v2"}", s"http://example.com/$v1?p=$v2queryEncoded") ) ) @@ -152,19 +134,14 @@ class UriInterpolatorTests extends FunSuite with Matchers { } val validationTestData = List( - ("uri with two ports", - () => uri"http://example.com:80:80", - "port specified multiple times"), - ("uri with embedded host+port and port", - () => uri"http://${"example.com:80"}:80", - "port specified multiple times") + ("uri with two ports", () => uri"http://example.com:80:80", "port specified multiple times"), + ("uri with embedded host+port and port", () => uri"http://${"example.com:80"}:80", "port specified multiple times") ) for { (name, createUri, expectedException) <- validationTestData } { - test( - s"""$name should validate and throw "$expectedException" if not valid""") { + test(s"""$name should validate and throw "$expectedException" if not valid""") { val caught = intercept[IllegalArgumentException] { createUri() } |