Skip to content

Commit bd2ee89

Browse files
jberkellihaoyi
andauthored
Add documentation and tests for Either (#533)
How do I regenerate the documentation? --------- Co-authored-by: Li Haoyi <[email protected]>
1 parent 38ac056 commit bd2ee89

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

upickle/test/src/upickle/example/ExampleTests.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ object ExampleTests extends TestSuite {
208208
write(Some(1)) ==> "1"
209209
write(None) ==> "null"
210210
}
211+
212+
test("either") {
213+
write(Left(42): Either[Int, String]) ==> "[0,42]"
214+
write(Right("foo"): Either[Int, String]) ==> """[1,"foo"]"""
215+
}
216+
211217
test("tuples"){
212218
write((1, "omg")) ==> """[1,"omg"]"""
213219
write((1, "omg", true)) ==> """[1,"omg",true]"""

upickleReadme/Readme.scalatex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@
152152

153153
@hl.ref(exampleTests, Seq("\"more\"", "\"options\"", ""))
154154

155+
@p
156+
@code{Either}s are serialized as JSON lists with 2 elements, with the first
157+
element a number indicating @code{Left} (0) or @code{Right} (1), and the second
158+
containing the value.
159+
160+
@hl.ref(exampleTests, Seq("\"more\"", "\"either\"", ""))
155161

156162
@p
157163
Tuples of all sizes (1-22) are serialized as heterogenous JSON lists

0 commit comments

Comments
 (0)