-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #616 from finagle/vk/fix-encode-as
Fix priority of AnsyncStream encoders
- Loading branch information
Showing
7 changed files
with
64 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,38 @@ | ||
package io.finch | ||
|
||
import java.nio.charset.Charset | ||
import java.util.UUID | ||
|
||
import com.twitter.io.Buf | ||
import io.finch.internal.BufText | ||
|
||
class EncodeSpec extends FinchSpec { | ||
checkAll("Encode.TextPlain[String]", EncodeLaws.textPlain[String].all) | ||
checkAll("Encode.TextPlain[Int]", EncodeLaws.textPlain[Int].all) | ||
checkAll("Encode.TextPlain[Option[Boolean]]", EncodeLaws.textPlain[Option[Boolean]].all) | ||
checkAll("Encode.TextPlain[List[Long]]", EncodeLaws.textPlain[List[Long]].all) | ||
checkAll("Encode.TextPlain[Either[UUID, Float]]", EncodeLaws.textPlain[Either[UUID, Float]].all) | ||
checkAll("Encode.Text[String]", EncodeLaws.text[String].all) | ||
checkAll("Encode.Text[Int]", EncodeLaws.text[Int].all) | ||
checkAll("Encode.Text[Option[Boolean]]", EncodeLaws.text[Option[Boolean]].all) | ||
checkAll("Encode.Text[List[Long]]", EncodeLaws.text[List[Long]].all) | ||
checkAll("Encode.Text[Either[UUID, Float]]", EncodeLaws.text[Either[UUID, Float]].all) | ||
|
||
it should "round trip Unit" in { | ||
check { (ct: String, cs: Charset) => | ||
Encode[Unit](ct).apply((), cs) === Buf.Empty | ||
} | ||
} | ||
|
||
it should "round trip Buf" in { | ||
check { (ct: String, cs: Charset, buf: Buf) => | ||
Encode[Buf](ct).apply(buf, cs) === buf | ||
} | ||
} | ||
|
||
it should "encode exceptions" in { | ||
check { (s: String, cs: Charset) => | ||
val e = new Exception(s) | ||
|
||
val json = Encode[Exception]("application/json").apply(e, cs) | ||
val text = Encode[Exception]("text/plain").apply(e, cs) | ||
|
||
json === BufText(s"""{"message":"$s"}""", cs) && text === BufText(s, cs) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters