Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 9cafe98

Browse files
committed
Adds tests for decode and encode
Signed-off-by: ncordon <[email protected]>
1 parent 98f2ea3 commit 9cafe98

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/test/scala/org/bblfsh/client/v2/BblfshClientParseTest.scala

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.bblfsh.client.v2
22

33
import java.nio.ByteBuffer
4-
54
import scala.io.Source
65

76
class BblfshClientParseTest extends BblfshClientBaseTest {
@@ -72,5 +71,33 @@ class BblfshClientParseTest extends BblfshClientBaseTest {
7271
encodedBytes shouldEqual resp.uast.asReadOnlyByteBuffer
7372
}
7473

74+
"BblfshClient.decode" should "decode in binary format" in {
75+
val defaultDecoded = resp.uast.decode()
76+
val binaryDecoded = resp.uast.decode(UastBinary)
77+
val default = defaultDecoded.root().load()
78+
val binary = binaryDecoded.root().load()
79+
80+
default shouldEqual binary
81+
}
82+
83+
"BblfshClient.decode" should "be the inverse for ContextExt.encode" in {
84+
for (fmt <- Seq(UastBinary, UastYaml)) {
85+
val ctx: ContextExt = resp.uast.decode()
86+
val tree = ctx.root()
87+
val bytes = ctx.encode(tree, fmt)
88+
val decoded = BblfshClient.decode(bytes, fmt)
89+
90+
ctx.root().load() shouldEqual decoded.root().load()
91+
}
92+
}
93+
94+
"BblfshClient.decode with invalid number" should "use binary format" in {
95+
val invalidNumDec = resp.uast.decode(-1)
96+
val binaryDecoded = resp.uast.decode(UastBinary)
97+
val invalidNum = invalidNumDec.root().load()
98+
val binary = binaryDecoded.root().load()
99+
100+
invalidNum shouldEqual binary
101+
}
75102

76103
}

0 commit comments

Comments
 (0)