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

Commit 4c3ccfc

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

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

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

+31-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,36 @@ 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)) {
85+
val fileName = "src/test/resources/Tiny.java"
86+
val fileContent = Source.fromFile(fileName).getLines.mkString("\n")
87+
val resp = client.parse(fileName, fileContent)
88+
val ctx: ContextExt = resp.uast.decode()
89+
val tree = ctx.root()
90+
val bytes = ctx.encode(tree, fmt)
91+
val decoded = BblfshClient.decode(bytes, fmt)
92+
93+
ctx.root().load() shouldEqual decoded.root().load()
94+
}
95+
}
96+
97+
"BblfshClient.decode with invalid number" should "use binary format" in {
98+
val invalidNumDec = resp.uast.decode(-1)
99+
val binaryDecoded = resp.uast.decode(UastBinary)
100+
val invalidNum = invalidNumDec.root().load()
101+
val binary = binaryDecoded.root().load()
102+
103+
invalidNum shouldEqual binary
104+
}
75105

76106
}

0 commit comments

Comments
 (0)