diff options
author | adamw <adam@warski.org> | 2017-07-28 09:34:35 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-07-28 09:34:35 +0200 |
commit | 2b38d9b18620f9d4796f8b56f73e9b093051a1fa (patch) | |
tree | 0863d93df58d26a9e68fe16feec6602b7b1f8023 /core/src/test/scala/com | |
parent | b645204f43c18db8e3ffc80c6f83bf44badb3e88 (diff) | |
download | sttp-2b38d9b18620f9d4796f8b56f73e9b093051a1fa.tar.gz sttp-2b38d9b18620f9d4796f8b56f73e9b093051a1fa.tar.bz2 sttp-2b38d9b18620f9d4796f8b56f73e9b093051a1fa.zip |
Updating scalafmt plugin
Diffstat (limited to 'core/src/test/scala/com')
-rw-r--r-- | core/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala | 13 | ||||
-rw-r--r-- | core/src/test/scala/com/softwaremill/sttp/UriTests.scala | 57 |
2 files changed, 64 insertions, 6 deletions
diff --git a/core/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala b/core/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala index 85348e6..b0dbf53 100644 --- a/core/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala +++ b/core/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala @@ -1,7 +1,5 @@ package com.softwaremill.sttp -import java.net.URI - import org.scalatest.{FunSuite, Matchers} class UriInterpolatorTests extends FunSuite with Matchers { @@ -15,7 +13,7 @@ class UriInterpolatorTests extends FunSuite with Matchers { val v4encoded = "f%2Fg" val secure = true - val testData: List[(String, List[(URI, String)])] = List( + val testData: List[(String, List[(Uri, String)])] = List( "basic" -> List( (uri"http://example.com", "http://example.com"), (uri"http://example.com/", "http://example.com/"), @@ -23,14 +21,17 @@ class UriInterpolatorTests extends FunSuite with Matchers { (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") + "http://example.com/a/b/c?x=y&h=j"), + (uri"http://example.com/a%20b?v%26v=v+v", + "http://example.com/a%20b?v%26v=v+v"), + (uri"http://example.com?x=y;p", "http://example.com?x=y;p") ), "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"example.com?a=$v2", s"example.com?a=$v2queryEncoded") + (uri"example.com?a=$v2", s"http://example.com?a=$v2queryEncoded") ), "authority" -> List( (uri"http://$v1.com", s"http://$v1.com"), @@ -115,7 +116,7 @@ class UriInterpolatorTests extends FunSuite with Matchers { ((interpolated, expected), i) <- testCases.zipWithIndex } { test(s"[$groupName] interpolate to $expected (${i + 1})") { - interpolated should be(new URI(expected)) + interpolated.toString should be(expected) } } } diff --git a/core/src/test/scala/com/softwaremill/sttp/UriTests.scala b/core/src/test/scala/com/softwaremill/sttp/UriTests.scala new file mode 100644 index 0000000..e82cc9c --- /dev/null +++ b/core/src/test/scala/com/softwaremill/sttp/UriTests.scala @@ -0,0 +1,57 @@ +package com.softwaremill.sttp + +import org.scalatest.{FunSuite, Matchers} + +class UriTests extends FunSuite with Matchers { + + val QF = QueryFragment + + val wholeUriTestData = List( + Uri("http", "example.com", None, Nil, Nil, None) -> "http://example.com", + Uri("https", + "sub.example.com", + Some(8080), + List("a", "b", "xyz"), + List(QF.KeyValue("p1", "v1"), QF.KeyValue("p2", "v2")), + Some("f")) -> + "https://sub.example.com:8080/a/b/xyz?p1=v1&p2=v2#f", + Uri("http", + "example.com", + None, + List(""), + List(QF.KeyValue("p", "v"), QF.KeyValue("p", "v")), + None) -> "http://example.com/?p=v&p=v", + Uri("http", + "exa mple.com", + None, + List("a b", "z", "ą:ę"), + List(QF.KeyValue("p:1", "v&v"), QF.KeyValue("p2", "v v")), + None) -> + "http://exa%20mple.com/a%20b/z/%C4%85%3A%C4%99?p%3A1=v%26v&p2=v+v" + ) + + for { + (uri, expected) <- wholeUriTestData + } { + test(s"$uri should serialize to $expected") { + uri.toString should be(expected) + } + } + + val testUri = Uri("http", "example.com", None, Nil, Nil, None) + + val pathTestData = List( + "a/b/c" -> List("a", "b", "c"), + "/a/b/c" -> List("a", "b", "c"), + "/" -> List(""), + "" -> List("") + ) + + for { + (path, expected) <- pathTestData + } { + test(s"$path should parse as $expected") { + testUri.path(path).path.toList should be(expected) + } + } +} |